Class: Hyperclient::EntryPoint
- Extended by:
- Forwardable
- Defined in:
- lib/hyperclient/entry_point.rb
Overview
The EntryPoint is the main public API for Hyperclient. It is used to initialize an API client and setup the configuration.
Instance Method Summary collapse
-
#connection ⇒ Object
A Faraday connection to use as a HTTP client.
-
#default_faraday_block ⇒ Object
private
private
Returns a block to initialize the Faraday connection.
-
#default_headers ⇒ Object
private
private
Returns the default headers to initialize the Faraday connection.
-
#initialize(url) ⇒ EntryPoint
constructor
Initializes an EntryPoint.
Methods inherited from Link
#_connection, #_delete, #_deprecation, #_expand, #_get, #_head, #_hreflang, #_name, #_options, #_patch, #_post, #_profile, #_put, #_resource, #_templated?, #_title, #_type, #_uri_template, #_url, #_variables, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_s
Constructor Details
#initialize(url) ⇒ EntryPoint
Initializes an EntryPoint.
21 22 23 24 |
# File 'lib/hyperclient/entry_point.rb', line 21 def initialize(url) @link = { 'href' => url } @entry_point = self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hyperclient::Link
Instance Method Details
#connection ⇒ Object
A Faraday connection to use as a HTTP client.
29 30 31 |
# File 'lib/hyperclient/entry_point.rb', line 29 def connection @connection ||= Faraday.new(_url, { headers: default_headers }, &default_faraday_block) end |
#default_faraday_block ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a block to initialize the Faraday connection. The default block includes a middleware to encode requests as JSON, a response middleware to parse JSON responses and sets the adapter as NetHttp.
These middleware can always be changed by accessing the Faraday connection.
44 45 46 47 48 49 50 51 |
# File 'lib/hyperclient/entry_point.rb', line 44 def default_faraday_block lambda do |faraday| faraday.use FaradayMiddleware::FollowRedirects faraday.request :json faraday.response :json, content_type: /\bjson$/ faraday.adapter :net_http end end |
#default_headers ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the default headers to initialize the Faraday connection. The default headers et the Content-Type and Accept to application/json.
57 58 59 |
# File 'lib/hyperclient/entry_point.rb', line 57 def default_headers { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } end |