class Daru::TD::Connection
Attributes
client[R]
Public Class Methods
new(apikey=nil, endpoint=nil, **kwargs)
click to toggle source
# 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
Public Instance Methods
apikey()
click to toggle source
@return [String] TreasureData API key
# File lib/daru/td/connection.rb, line 36 def apikey @client.apikey end
databases()
click to toggle source
# 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.permission, db.created_at, db.updated_at] end else Daru::DataFrame.new() end end
endpoint()
click to toggle source
See github.com/treasure-data/td-client-ruby/blob/master/lib/td/client/api.rb#L67 @return [String] TreasureData endpoint URL
# File lib/daru/td/connection.rb, line 42 def endpoint @kwargs[:endpoint] || ENV['TD_API_SERVER'] || ::TD::API::DEFAULT_ENDPOINT end
tables(database)
click to toggle source
# 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.last_log_timestamp, t.created_at] end else Daru::DataFrame.new() end end
Private Instance Methods
get_client(apikey, **kwargs)
click to toggle source
# File lib/daru/td/connection.rb, line 70 def get_client(apikey, **kwargs) ::TD::Client.new(apikey, **kwargs) end
make_dataframe(enum, fields) { |item| ... }
click to toggle source
# File lib/daru/td/connection.rb, line 74 def make_dataframe(enum, fields) Daru::DataFrame.new([], order: fields).tap do |df| enum.each do |item| df.add_row(yield(item)) end end end