Class: Abt::Providers::Asana::Api
- Inherits:
-
Object
- Object
- Abt::Providers::Asana::Api
- Defined in:
- lib/abt/providers/asana/api.rb
Constant Summary collapse
- API_ENDPOINT =
"https://app.asana.com/api/1.0"
- VERBS =
[:get, :post, :put].freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
- #connection ⇒ Object
- #get_paged(path, query = {}) ⇒ Object
-
#initialize(access_token:) ⇒ Api
constructor
A new instance of Api.
- #request(*args) ⇒ Object
Constructor Details
#initialize(access_token:) ⇒ Api
Returns a new instance of Api.
12 13 14 |
# File 'lib/abt/providers/asana/api.rb', line 12 def initialize(access_token:) @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/abt/providers/asana/api.rb', line 10 def access_token @access_token end |
Instance Method Details
#connection ⇒ Object
48 49 50 51 52 53 |
# File 'lib/abt/providers/asana/api.rb', line 48 def connection @connection ||= Faraday.new(API_ENDPOINT) do |connection| connection.headers["Authorization"] = "Bearer #{access_token}" connection.headers["Content-Type"] = "application/json" end end |
#get_paged(path, query = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/abt/providers/asana/api.rb', line 22 def get_paged(path, query = {}) records = [] loop do result = request(:get, path, query.merge(limit: 100)) records += result["data"] break if result["next_page"].nil? path = result["next_page"]["path"][1..-1] end records end |
#request(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/abt/providers/asana/api.rb', line 36 def request(*args) response = connection.public_send(*args) if response.success? Oj.load(response.body) else error_class = Abt::HttpError.error_class_for_status(response.status) encoded_response_body = response.body.force_encoding("utf-8") raise error_class, "Code: #{response.status}, body: #{encoded_response_body}" end end |