Class: TrackerApi::Client
- Inherits:
-
Object
- Object
- TrackerApi::Client
- Defined in:
- lib/tracker_api/client.rb
Constant Summary collapse
- USER_AGENT =
"Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}) TrackerApi/#{TrackerApi::VERSION} Faraday/#{Faraday::VERSION}".freeze
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#token ⇒ Object
Returns the value of attribute token.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Create Pivotal Tracker API client.
- #project(id, params = {}) ⇒ Object
- #projects(params = {}) ⇒ Object
- #request(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Create Pivotal Tracker API client.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tracker_api/client.rb', line 19 def initialize(={}) url = [:url] || 'https://www.pivotaltracker.com' @url = URI.parse(url).to_s @api_version = [:api_version] || '/services/v5' @logger = [:logger] || Logger.new(nil) adapter = [:adapter] || :net_http = [:connection_options] || { ssl: { verify: true } } @token = [:token] raise 'Missing required options: :token' unless @token @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 builder.adapter adapter end end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
5 6 7 |
# File 'lib/tracker_api/client.rb', line 5 def api_version @api_version end |
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/tracker_api/client.rb', line 5 def connection @connection end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/tracker_api/client.rb', line 5 def logger @logger end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/tracker_api/client.rb', line 5 def token @token end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/tracker_api/client.rb', line 5 def url @url end |
Instance Method Details
#project(id, params = {}) ⇒ Object
67 68 69 |
# File 'lib/tracker_api/client.rb', line 67 def project(id, params={}) Endpoints::Project.new(self).get(id, params) end |
#projects(params = {}) ⇒ Object
63 64 65 |
# File 'lib/tracker_api/client.rb', line 63 def projects(params={}) Endpoints::Projects.new(self).get(params) end |
#request(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tracker_api/client.rb', line 45 def request(={}) method = [:method] || :get url = [:url] || File.join(@url, @api_version, [:path]) token = [:token] || @token params = [:params] || {} body = [:body] headers = { 'User-Agent' => USER_AGENT, 'X-TrackerToken' => token }.merge([:headers] || {}) connection.send(method) do |req| req.url url req.headers.merge!(headers) req.params.merge!(params) req.body = body end rescue Faraday::Error::ClientError => e raise TrackerApi::Error.new(e) end |