Class: Lotrb::Client
- Inherits:
-
Object
- Object
- Lotrb::Client
- Defined in:
- lib/lotrb/client.rb
Constant Summary collapse
- BASE_URL =
"https://the-one-api.dev/v2/"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/lotrb/client.rb', line 10 def initialize(adapter: Faraday.default_adapter) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/lotrb/client.rb', line 8 def adapter @adapter end |
Class Method Details
.instance(adapter: Faraday.default_adapter) ⇒ Object
14 15 16 |
# File 'lib/lotrb/client.rb', line 14 def self.instance(adapter: Faraday.default_adapter) @instance ||= new(adapter: adapter) end |
Instance Method Details
#connection ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/lotrb/client.rb', line 18 def connection @connection ||= Faraday.new do |conn| conn.url_prefix = BASE_URL conn.request :json conn.response :json, content_type: "application/json" conn.adapter adapter end end |
#get(path, params = {}) ⇒ Object
27 28 29 |
# File 'lib/lotrb/client.rb', line 27 def get(path, params = {}) connection.get(path, params , auth_header) end |