class Chell::Client

Constants

FORMATS

Public Class Methods

new(options = {}) click to toggle source
# File lib/chell/client.rb, line 11
def initialize(options = {})
  @access_key = options.fetch(:access_key)
  @secret_key = options.fetch(:secret_key)
  @url = options.fetch(:url)
end

Public Instance Methods

course(id) click to toggle source
# File lib/chell/client.rb, line 21
def course(id)
  path = "/courses/#{id}"
  headers = { accept: FORMATS[:json] }

  response = resource[path].get(headers)
  parse_json(response.body)
end
course_content(id, version_id) click to toggle source
# File lib/chell/client.rb, line 29
def course_content(id, version_id)
  path = "/courses/#{id}/versions/#{version_id}"
  headers = { accept: FORMATS[:gzip] }

  resource[path].get(headers).body
end
courses() click to toggle source
# File lib/chell/client.rb, line 17
def courses
  parse_json(resource["/courses"].get.body)
end

Private Instance Methods

parse_json(body) click to toggle source
# File lib/chell/client.rb, line 38
def parse_json(body)
  Oj.default_options = { mode: :compat, symbol_keys: true }
  Oj.load(body)
end
resource() click to toggle source
# File lib/chell/client.rb, line 43
def resource
  @resource ||= RestClient::Resource.new(@url, user: @access_key, password: @secret_key)
end