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'
Instance Method Summary collapse
-
#delete(resource_uri, params: {}, options: {}) ⇒ 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, log_asana_change_warnings: true, default_headers: nil, &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, log_asana_change_warnings: true, default_headers: nil, &config) ⇒ HttpClient
Initializes an HttpClient to make requests to the Asana API.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asana/http_client.rb', line 26 def initialize(authentication: required('authentication'), adapter: nil, user_agent: nil, debug_mode: false, log_asana_change_warnings: true, default_headers: nil, &config) @authentication = authentication @adapter = adapter || Faraday.default_adapter @environment_info = EnvironmentInfo.new(user_agent) @debug_mode = debug_mode @log_asana_change_warnings = log_asana_change_warnings @default_headers = default_headers @config = config end |
Instance Method Details
#delete(resource_uri, params: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a DELETE request against the API.
116 117 118 119 120 121 122 123 |
# File 'lib/asana/http_client.rb', line 116 def delete(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(:delete, resource_uri, params.merge(opts), [:headers]) end |
#get(resource_uri, params: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a GET request against the API.
51 52 53 54 55 56 57 58 |
# File 'lib/asana/http_client.rb', line 51 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), [:headers]) end |
#post(resource_uri, body: {}, upload: nil, options: {}) ⇒ Asana::HttpClient::Response
Performs a POST request against the API.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/asana/http_client.rb', line 91 def post(resource_uri, body: {}, upload: nil, options: {}) opts = .reduce({}) do |acc, (k, v)| acc.tap do |hash| hash[:"opt_#{k}"] = v.is_a?(Array) ? v.join(',') : v end end .merge(opts) params = { data: body }.merge(.empty? ? {} : { options: }) if upload perform_request(:post, resource_uri, params.merge(file: upload), [:headers]) do |c| c.request :multipart end else perform_request(:post, resource_uri, params, [:headers]) end end |
#put(resource_uri, body: {}, options: {}) ⇒ Asana::HttpClient::Response
Performs a PUT request against the API.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/asana/http_client.rb', line 69 def put(resource_uri, body: {}, options: {}) opts = .reduce({}) do |acc, (k, v)| acc.tap do |hash| hash[:"opt_#{k}"] = v.is_a?(Array) ? v.join(',') : v end end .merge(opts) params = { data: body }.merge(.empty? ? {} : { options: }) perform_request(:put, resource_uri, params, [:headers]) end |