Class: TrackerApi::Client
Defined Under Namespace
Classes: Pagination
Constant Summary collapse
- USER_AGENT =
"Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}) TrackerApi/#{TrackerApi::VERSION} Faraday/#{Faraday::VERSION}".freeze
- CONVENIENCE_HEADERS =
Set.new([:accept, :content_type])
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#auto_paginate ⇒ Object
readonly
Returns the value of attribute auto_paginate.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#activity(params = {}) ⇒ Array[TrackerApi::Resources::Activity]
Provides a list of all the activity performed the authenticated person.
-
#create_workspace(params) ⇒ TrackerApi::Resources::Workspace
Create a new workspace.
-
#delete(path, options = {}) ⇒ Faraday::Response
Make a HTTP DELETE request.
-
#epic(epic_id, params = {}) ⇒ TrackerApi::Resources::Epic
Get information about an epic without knowing what project the epic belongs to.
-
#get(path, options = {}) ⇒ Faraday::Response
Make a HTTP GET request.
-
#initialize(options = {}, &block) ⇒ Client
constructor
Create Pivotal Tracker API client.
-
#me ⇒ TrackerApi::Resources::Me
Get information about the authenticated user.
-
#notifications(params = {}) ⇒ Array[TrackerApi::Resources::Notification]
Get notifications for the authenticated person.
-
#paginate(path, options = {}, &block) ⇒ Array
Make one or more HTTP GET requests, optionally fetching the next page of results from information passed back in headers based on value in #auto_paginate.
-
#post(path, options = {}) ⇒ Faraday::Response
Make a HTTP POST request.
-
#project(id, params = {}) ⇒ TrackerApi::Resources::Project
Get project.
-
#projects(params = {}) ⇒ Array[TrackerApi::Resources::Project]
Get projects.
-
#put(path, options = {}) ⇒ Faraday::Response
Make a HTTP PUT request.
-
#story(story_id, params = {}) ⇒ TrackerApi::Resources::Story
Get information about a client story without knowing what project the story belongs to.
-
#workspace(id, params = {}) ⇒ TrackerApi::Resources::Workspace
Get workspace.
-
#workspaces(params = {}) ⇒ Array[TrackerApi::Resources::Workspace]
Get workspaces.
Constructor Details
#initialize(options = {}, &block) ⇒ Client
Create Pivotal Tracker API client.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tracker_api/client.rb', line 23 def initialize(={}, &block) url = .fetch(:url, 'https://www.pivotaltracker.com') @url = Addressable::URI.parse(url).to_s @api_version = .fetch(:api_version, '/services/v5') @logger = .fetch(:logger, ::Logger.new(nil)) adapter = .fetch(:adapter, :excon) = .fetch(:connection_options, { ssl: { verify: true } }) @auto_paginate = .fetch(:auto_paginate, true) @token = [:token] raise 'Missing required options: :token' unless @token @faraday_block = block if block_given? @connection = Faraday.new({ url: @url }.merge()) do |builder| # response builder.use Faraday::Response::RaiseError builder.response :json # request builder.request :multipart builder.request :json builder.use TrackerApi::Logger, @logger @faraday_block.call(builder) if @faraday_block builder.adapter adapter end end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def api_version @api_version end |
#auto_paginate ⇒ Object (readonly)
Returns the value of attribute auto_paginate.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def auto_paginate @auto_paginate end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def connection @connection end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def last_response @last_response end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def logger @logger end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def token @token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/tracker_api/client.rb', line 8 def url @url end |
Instance Method Details
#activity(params = {}) ⇒ Array[TrackerApi::Resources::Activity]
Provides a list of all the activity performed the authenticated person.
202 203 204 |
# File 'lib/tracker_api/client.rb', line 202 def activity(params={}) Endpoints::Activity.new(self).get(params) end |
#create_workspace(params) ⇒ TrackerApi::Resources::Workspace
Create a new workspace.
144 145 146 |
# File 'lib/tracker_api/client.rb', line 144 def create_workspace(params) Endpoints::Workspace.new(self).create(params) end |
#delete(path, options = {}) ⇒ Faraday::Response
Make a HTTP DELETE request
83 84 85 |
# File 'lib/tracker_api/client.rb', line 83 def delete(path, = {}) request(:delete, parse_query_and_convenience_headers(path, )) end |
#epic(epic_id, params = {}) ⇒ TrackerApi::Resources::Epic
Get information about an epic without knowing what project the epic belongs to
186 187 188 |
# File 'lib/tracker_api/client.rb', line 186 def epic(epic_id, params={}) Endpoints::Epic.new(self).get_epic(epic_id, params) end |
#get(path, options = {}) ⇒ Faraday::Response
Make a HTTP GET request
56 57 58 |
# File 'lib/tracker_api/client.rb', line 56 def get(path, = {}) request(:get, parse_query_and_convenience_headers(path, )) end |
#me ⇒ TrackerApi::Resources::Me
Get information about the authenticated user
168 169 170 |
# File 'lib/tracker_api/client.rb', line 168 def me Endpoints::Me.new(self).get end |
#notifications(params = {}) ⇒ Array[TrackerApi::Resources::Notification]
Get notifications for the authenticated person
194 195 196 |
# File 'lib/tracker_api/client.rb', line 194 def notifications(params={}) Endpoints::Notifications.new(self).get(params) end |
#paginate(path, options = {}, &block) ⇒ Array
Make one or more HTTP GET requests, optionally fetching the next page of results from information passed back in headers based on value in #auto_paginate.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tracker_api/client.rb', line 98 def paginate(path, = {}, &block) opts = parse_query_and_convenience_headers path, .dup auto_paginate = opts[:params].delete(:auto_paginate) { |k| @auto_paginate } @last_response = request :get, opts data = @last_response.body raise TrackerApi::Errors::UnexpectedData, 'Array expected' unless data.is_a? Array if auto_paginate pager = Pagination.new @last_response.headers while pager.more? opts[:params].update(pager.next_page_params) @last_response = request :get, opts pager = Pagination.new @last_response.headers if block_given? yield(data, @last_response) else data.concat(@last_response.body) if @last_response.body.is_a?(Array) end end end data end |
#post(path, options = {}) ⇒ Faraday::Response
Make a HTTP POST request
65 66 67 |
# File 'lib/tracker_api/client.rb', line 65 def post(path, = {}) request(:post, parse_query_and_convenience_headers(path, )) end |
#project(id, params = {}) ⇒ TrackerApi::Resources::Project
Get project
136 137 138 |
# File 'lib/tracker_api/client.rb', line 136 def project(id, params={}) Endpoints::Project.new(self).get(id, params) end |
#projects(params = {}) ⇒ Array[TrackerApi::Resources::Project]
Get projects
128 129 130 |
# File 'lib/tracker_api/client.rb', line 128 def projects(params={}) Endpoints::Projects.new(self).get(params) end |
#put(path, options = {}) ⇒ Faraday::Response
Make a HTTP PUT request
74 75 76 |
# File 'lib/tracker_api/client.rb', line 74 def put(path, = {}) request(:put, parse_query_and_convenience_headers(path, )) end |
#story(story_id, params = {}) ⇒ TrackerApi::Resources::Story
Get information about a client story without knowing what project the story belongs to
177 178 179 |
# File 'lib/tracker_api/client.rb', line 177 def story(story_id, params={}) Endpoints::Story.new(self).get_story(story_id, params) end |
#workspace(id, params = {}) ⇒ TrackerApi::Resources::Workspace
Get workspace
152 153 154 |
# File 'lib/tracker_api/client.rb', line 152 def workspace(id, params={}) Endpoints::Workspace.new(self).get(id, params) end |
#workspaces(params = {}) ⇒ Array[TrackerApi::Resources::Workspace]
Get workspaces
160 161 162 |
# File 'lib/tracker_api/client.rb', line 160 def workspaces(params={}) Endpoints::Workspaces.new(self).get(params) end |