Class: Deta::Client
- Inherits:
-
Object
- Object
- Deta::Client
- Defined in:
- lib/deta/client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#project_key ⇒ Object
readonly
Returns the value of attribute project_key.
Instance Method Summary collapse
- #base(base_name = nil) ⇒ Object
- #connection ⇒ Object
- #drive(drive_name = nil) ⇒ Object
-
#initialize(project_key:, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(project_key:, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 |
# File 'lib/deta/client.rb', line 5 def initialize(project_key:, adapter: Faraday.default_adapter) @project_id = project_key.split("_").first @project_key = project_key @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/deta/client.rb', line 3 def adapter @adapter end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
3 4 5 |
# File 'lib/deta/client.rb', line 3 def project_id @project_id end |
#project_key ⇒ Object (readonly)
Returns the value of attribute project_key.
3 4 5 |
# File 'lib/deta/client.rb', line 3 def project_key @project_key end |
Instance Method Details
#base(base_name = nil) ⇒ Object
11 12 13 |
# File 'lib/deta/client.rb', line 11 def base(base_name = nil) BaseResource.new(self, base_name) end |
#connection ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/deta/client.rb', line 19 def connection @connection ||= Faraday.new do |conn| conn.headers['X-API-Key'] = project_key conn.request :json conn.response :json, content_type: "application/json" conn.adapter adapter end end |
#drive(drive_name = nil) ⇒ Object
15 16 17 |
# File 'lib/deta/client.rb', line 15 def drive(drive_name = nil) DriveResource.new(self, drive_name) end |