Class: Daru::TD::Connection
- Inherits:
-
Object
- Object
- Daru::TD::Connection
- Defined in:
- lib/daru/td/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#apikey ⇒ String
TreasureData API key.
- #databases ⇒ Object
- #endpoint ⇒ String
-
#initialize(apikey = nil, endpoint = nil, **kwargs) ⇒ Connection
constructor
A new instance of Connection.
- #tables(database) ⇒ Object
Constructor Details
#initialize(apikey = nil, endpoint = nil, **kwargs) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/daru/td/connection.rb', line 8 def initialize(apikey=nil, endpoint=nil, **kwargs) if apikey.nil? && kwargs[:apikey] apikey = kwargs.delete(:apikey) end if endpoint unless endpoint.end_with?('/') endpoint = endpoint + '/' end kwargs[:endpoint] = endpoint end if kwargs[:user_agent].nil? versions = [ "daru/#{Daru::VERSION}", "td-client/#{::TD::Client::VERSION}", "ruby/#{RUBY_VERSION}" ] kwargs[:user_agent] = "daru-td/#{Daru::TD::VERSION} (#{versions.join(' ')})" end @kwargs = kwargs @client = get_client(apikey, **kwargs) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
33 34 35 |
# File 'lib/daru/td/connection.rb', line 33 def client @client end |
Instance Method Details
#apikey ⇒ String
Returns TreasureData API key.
36 37 38 |
# File 'lib/daru/td/connection.rb', line 36 def apikey @client.apikey end |
#databases ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/daru/td/connection.rb', line 46 def databases if (databases = self.client.databases()) fields = [:name, :count, :permission, :created_at, :updated_at] make_dataframe(databases, [:name, :count, :permission, :created_at, :updated_at]) do |db| [db.name, db.count, db., db.created_at, db.updated_at] end else Daru::DataFrame.new() end end |
#endpoint ⇒ String
42 43 44 |
# File 'lib/daru/td/connection.rb', line 42 def endpoint @kwargs[:endpoint] || ENV['TD_API_SERVER'] || ::TD::API::DEFAULT_ENDPOINT end |
#tables(database) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/daru/td/connection.rb', line 57 def tables(database) if (tables = self.client.tables(database)) fields = [:name, :count, :estimated_storage_size, :last_log_timestamp, :created_at] make_dataframe(tables, [:name, :count, :estimated_storage_size, :last_log_timestamp, :created_at]) do |t| [t.name, t.count, t.estimated_storage_size, t., t.created_at] end else Daru::DataFrame.new() end end |