class Redmine::Client
The client is a Redmine-aware REST API client that maps remote resources into local methods and data. It uses the RestClient
under the hood and outputs our own domain objects.
Public Class Methods
new(rest_client:)
click to toggle source
# File lib/redmine/client.rb, line 9 def initialize(rest_client:) @rest_client = rest_client end
Public Instance Methods
issue(issue_id)
click to toggle source
# File lib/redmine/client.rb, line 13 def issue(issue_id) data = @rest_client.get("/issues/#{issue_id}.json?include=journals").first Issue.new(data.fetch('issue')) end
issue_statuses()
click to toggle source
# File lib/redmine/client.rb, line 32 def issue_statuses @rest_client .get('/issue_statuses.json') .first .fetch('issue_statuses') end
issues(options = {})
click to toggle source
# File lib/redmine/client.rb, line 39 def issues(options = {}) # rubocop:disable Metrics/AbcSize options = { limit: 10, offset: 0, sort: :asc }.merge(options.to_h) Enumerator.new do |yielder| loop do result, _response = @rest_client.get( '/issues.json?' + URI.encode_www_form(options) ) result.fetch('issues').each { |issue| yielder << Issue.new(issue) } position = result.fetch('limit') + result.fetch('offset') raise StopIteration unless result.fetch('total_count').to_i > position options.merge!(offset: options.fetch(:limit) + options.fetch(:offset)) end end end
project(id)
click to toggle source
# File lib/redmine/client.rb, line 26 def project(id) @rest_client .get("/projects/#{id}.json?include=trackers") .fetch('project') end
projects()
click to toggle source
# File lib/redmine/client.rb, line 18 def projects @rest_client .get('/projects.json') .first .fetch('projects') .map { |p| Project.new(p) } end