Class: Redmine::Client
- Inherits:
-
Object
- Object
- Redmine::Client
- Defined in:
- lib/redmine/client.rb
Overview
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.
Instance Method Summary collapse
-
#initialize(rest_client:) ⇒ Client
constructor
A new instance of Client.
- #issue(issue_id) ⇒ Object
- #issue_statuses ⇒ Object
-
#issues(options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #project(id) ⇒ Object
- #projects ⇒ Object
Constructor Details
#initialize(rest_client:) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/redmine/client.rb', line 9 def initialize(rest_client:) @rest_client = rest_client end |
Instance Method Details
#issue(issue_id) ⇒ Object
13 14 15 16 |
# 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 ⇒ Object
32 33 34 35 36 37 |
# File 'lib/redmine/client.rb', line 32 def issue_statuses @rest_client .get('/issue_statuses.json') .first .fetch('issue_statuses') end |
#issues(options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/redmine/client.rb', line 39 def issues( = {}) # rubocop:disable Metrics/AbcSize = { limit: 10, offset: 0, sort: :asc }.merge(.to_h) Enumerator.new do |yielder| loop do result, _response = @rest_client.get( '/issues.json?' + URI.encode_www_form() ) 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 .merge!(offset: .fetch(:limit) + .fetch(:offset)) end end end |
#project(id) ⇒ Object
26 27 28 29 30 |
# File 'lib/redmine/client.rb', line 26 def project(id) @rest_client .get("/projects/#{id}.json?include=trackers") .fetch('project') end |