Class: Deta::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deta/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adapterObject (readonly)

Returns the value of attribute adapter.



3
4
5
# File 'lib/deta/client.rb', line 3

def adapter
  @adapter
end

#project_idObject (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_keyObject (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

#connectionObject



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