Class: Asana::HttpClient Private
- Inherits:
-
Object
- Object
- Asana::HttpClient
- Defined in:
- lib/asana/http_client.rb,
lib/asana/http_client/response.rb,
lib/asana/http_client/error_handling.rb,
lib/asana/http_client/environment_info.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wrapper over Faraday that abstracts authentication, request parsing and common options.
Defined Under Namespace
Modules: ErrorHandling Classes: EnvironmentInfo, Response
Constant Summary collapse
- BASE_URI =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The API base URI.
'https://app.asana.com/api/1.0'.freeze
Instance Method Summary collapse
-
#delete(resource_uri) ⇒ Asana::HttpClient::Response
Performs a DELETE request against the API.
-
#get(resource_uri, params: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a GET request against the API.
-
#initialize(authentication: required('authentication'), adapter: nil, user_agent: nil, debug_mode: false, &config) ⇒ HttpClient
constructor
Initializes an HttpClient to make requests to the Asana API.
-
#post(resource_uri, body: {}, upload: nil, options: {}) ⇒ Asana::HttpClient::Response
Performs a POST request against the API.
-
#put(resource_uri, body: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a PUT request against the API.
Constructor Details
#initialize(authentication: required('authentication'), adapter: nil, user_agent: nil, debug_mode: false, &config) ⇒ HttpClient
Initializes an HttpClient to make requests to the Asana API.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/asana/http_client.rb', line 25 def initialize(authentication: required('authentication'), adapter: nil, user_agent: nil, debug_mode: false, &config) @authentication = authentication @adapter = adapter || Faraday.default_adapter @environment_info = EnvironmentInfo.new(user_agent) @debug_mode = debug_mode @config = config end |
Instance Method Details
#delete(resource_uri) ⇒ Asana::HttpClient::Response
Performs a DELETE request against the API.
98 99 100 |
# File 'lib/asana/http_client.rb', line 98 def delete(resource_uri) perform_request(:delete, resource_uri) end |
#get(resource_uri, params: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a GET request against the API.
46 47 48 49 50 51 52 53 |
# File 'lib/asana/http_client.rb', line 46 def get(resource_uri, params: {}, options: {}) opts = .reduce({}) do |acc, (k, v)| acc.tap do |hash| hash[:"opt_#{k}"] = v.is_a?(Array) ? v.join(',') : v end end perform_request(:get, resource_uri, params.merge(opts)) end |
#post(resource_uri, body: {}, upload: nil, options: {}) ⇒ Asana::HttpClient::Response
Performs a POST request against the API.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/asana/http_client.rb', line 80 def post(resource_uri, body: {}, upload: nil, options: {}) params = { data: body }.merge(.empty? ? {} : { options: }) if upload perform_request(:post, resource_uri, params.merge(file: upload)) do |c| c.request :multipart end else perform_request(:post, resource_uri, params) end end |
#put(resource_uri, body: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a PUT request against the API.
64 65 66 67 |
# File 'lib/asana/http_client.rb', line 64 def put(resource_uri, body: {}, options: {}) params = { data: body }.merge(.empty? ? {} : { options: }) perform_request(:put, resource_uri, params) end |