Class: ActiveCampaignRb::HttpClient
- Inherits:
-
Object
- Object
- ActiveCampaignRb::HttpClient
- Defined in:
- lib/active_campaign_rb/http_client.rb
Overview
HTTP Client wrapper
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #delete(*args) ⇒ Object
- #get(*args) ⇒ Object
-
#initialize(opts = {}) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #patch(*args) ⇒ Object
- #post(*args) ⇒ Object
- #put(*args) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ HttpClient
Returns a new instance of HttpClient.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_campaign_rb/http_client.rb', line 10 def initialize(opts = {}) @connection = ::Faraday.new(url: opts.api_endpoint) do |f| ActiveCampaignRb::Faraday::Middleware.add_request_middleware(f, opts.request_middleware) ActiveCampaignRb::Faraday::Middleware.add_response_middleware(f, opts.response_middleware) f.adapter opts.adapter f.headers = { "Accept" => "application/json", "Content-Type" => "application/json", "Api-Token" => opts.api_key, "User-Agent" => "ActiveCampaignRb Client (v#{ActiveCampaignRb::VERSION})" } end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/active_campaign_rb/http_client.rb', line 8 def connection @connection end |
Instance Method Details
#delete(*args) ⇒ Object
43 44 45 46 47 |
# File 'lib/active_campaign_rb/http_client.rb', line 43 def delete(*args) safe_http_call do connection.delete(*args) end end |
#get(*args) ⇒ Object
49 50 51 52 53 |
# File 'lib/active_campaign_rb/http_client.rb', line 49 def get(*args) safe_http_call do connection.get(*args) end end |
#patch(*args) ⇒ Object
31 32 33 34 35 |
# File 'lib/active_campaign_rb/http_client.rb', line 31 def patch(*args) safe_http_call do connection.patch(*args) end end |
#post(*args) ⇒ Object
25 26 27 28 29 |
# File 'lib/active_campaign_rb/http_client.rb', line 25 def post(*args) safe_http_call do connection.post(*args) end end |
#put(*args) ⇒ Object
37 38 39 40 41 |
# File 'lib/active_campaign_rb/http_client.rb', line 37 def put(*args) safe_http_call do connection.put(*args) end end |