class CanvasDataClient::Client

Attributes

account[RW]
key[RW]
logger[RW]
secret[RW]
subdomain[RW]

Public Class Methods

new(key, secret, opts = {}) click to toggle source
# File lib/canvas_data_client/client.rb, line 10
def initialize(key, secret, opts = {})
  self.key = key
  self.secret = secret
  self.subdomain = opts[:subdomain] || 'portal'
  self.account = opts[:account] || 'self'
  self.logger = Logger.new(STDOUT)
end

Public Instance Methods

domain() click to toggle source
# File lib/canvas_data_client/client.rb, line 18
def domain
  "https://#{subdomain}.inshosteddata.com"
end
dump(dump_id) click to toggle source
# File lib/canvas_data_client/client.rb, line 35
def dump(dump_id)
  json_request "#{domain}/api/account/#{account}/file/byDump/#{dump_id}"
end
dumps() click to toggle source
# File lib/canvas_data_client/client.rb, line 27
def dumps
  paginated_request "#{domain}/api/account/#{account}/dump?after=%s"
end
get_latest_dumps() click to toggle source
# File lib/canvas_data_client/client.rb, line 31
def get_latest_dumps
  json_request "#{domain}/api/account/#{account}/dump"
end
latest()
Alias for: latest_files
latest_files() click to toggle source
# File lib/canvas_data_client/client.rb, line 22
def latest_files
  json_request "#{domain}/api/account/#{account}/file/latest"
end
Also aliased as: latest
latest_schema() click to toggle source
# File lib/canvas_data_client/client.rb, line 47
def latest_schema
  json_request "#{domain}/api/schema/latest"
end
schema(version) click to toggle source
# File lib/canvas_data_client/client.rb, line 51
def schema(version)
  json_request "#{domain}/api/schema/#{version}"
end
schemas() click to toggle source
# File lib/canvas_data_client/client.rb, line 43
def schemas
  json_request "#{domain}/api/schema"
end
tables(table) click to toggle source
# File lib/canvas_data_client/client.rb, line 39
def tables(table)
  paginated_request "#{domain}/api/account/#{account}/file/byTable/#{table}?after=%s"
end

Private Instance Methods

json_request(path, method = 'get') click to toggle source
# File lib/canvas_data_client/client.rb, line 56
def json_request(path, method = 'get')
  resp = RestClient::Request.execute(method: :get, url: path, timeout: 180, headers: headers(key, secret, { path: path, method: method }))
  JSON.parse resp
end
paginated_request(path) click to toggle source
# File lib/canvas_data_client/client.rb, line 61
def paginated_request(path)
  received = []
  sequence = '0'
  loop do
    resp = json_request(path % sequence)
    resp = resp['history'] if resp.is_a?(Hash)
    resp.sort_by! { |h| h['sequence'] }
    received += resp
    break if resp.length < 50
    sequence = resp.last['sequence']
  end
  received
end