Class: Replicate::Endpoint
- Inherits:
-
Object
- Object
- Replicate::Endpoint
- Defined in:
- lib/replicate/endpoint.rb
Overview
Network layer for API clients.
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#endpoint_url ⇒ Object
readonly
Returns the value of attribute endpoint_url.
Instance Method Summary collapse
-
#agent ⇒ Sawyer::Agent
Hypermedia agent for the datatrans API.
-
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request.
-
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request.
-
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request.
-
#initialize(endpoint_url:, api_token:, content_type: 'application/json') ⇒ Endpoint
constructor
A new instance of Endpoint.
-
#last_response ⇒ Sawyer::Response
Response for last HTTP request.
-
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request.
-
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request.
-
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request.
Constructor Details
#initialize(endpoint_url:, api_token:, content_type: 'application/json') ⇒ Endpoint
Returns a new instance of Endpoint.
14 15 16 17 18 |
# File 'lib/replicate/endpoint.rb', line 14 def initialize(endpoint_url:, api_token:, content_type: 'application/json') @endpoint_url = endpoint_url @api_token = api_token @content_type = content_type end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
12 13 14 |
# File 'lib/replicate/endpoint.rb', line 12 def api_token @api_token end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
12 13 14 |
# File 'lib/replicate/endpoint.rb', line 12 def content_type @content_type end |
#endpoint_url ⇒ Object (readonly)
Returns the value of attribute endpoint_url.
12 13 14 |
# File 'lib/replicate/endpoint.rb', line 12 def endpoint_url @endpoint_url end |
Instance Method Details
#agent ⇒ Sawyer::Agent
Hypermedia agent for the datatrans API
77 78 79 80 81 82 83 84 85 |
# File 'lib/replicate/endpoint.rb', line 77 def agent @agent ||= Faraday.new(url: endpoint_url) do |conn| conn.request :retry conn.request :authorization, 'Token', api_token if api_token conn.headers["Content-Type"] = content_type conn.adapter :net_http end end |
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request
61 62 63 |
# File 'lib/replicate/endpoint.rb', line 61 def delete(url, = {}) request :delete, url, end |
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request
25 26 27 |
# File 'lib/replicate/endpoint.rb', line 25 def get(url, = {}) request :get, url, end |
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request
70 71 72 |
# File 'lib/replicate/endpoint.rb', line 70 def head(url, = {}) request :head, url, end |
#last_response ⇒ Sawyer::Response
Response for last HTTP request
90 91 92 |
# File 'lib/replicate/endpoint.rb', line 90 def last_response @last_response if defined? @last_response end |
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request
52 53 54 |
# File 'lib/replicate/endpoint.rb', line 52 def patch(url, = {}) request :patch, url, .to_json end |
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request
34 35 36 |
# File 'lib/replicate/endpoint.rb', line 34 def post(url, = {}) request :post, url, .to_json end |
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request
43 44 45 |
# File 'lib/replicate/endpoint.rb', line 43 def put(url, = {}) request :put, url, .to_json end |