module Gameboy

Constants

OPEN_TIMEOUT
REQUEST_TIMEOUT
VERSION

Public Class Methods

achievements_for_user(user_id, options={}) click to toggle source
# File lib/gameboy.rb, line 25
def self.achievements_for_user(user_id, options={})
  api_key = options.delete(:api_key) || @@api_key

  response = RestClient::Request.execute(
    method: :get,
    url: "#{self.gamer_host}/users/#{user_id}/achievements?#{options.to_query}",
    headers: {"Authorization" => "api_key #{api_key}", :content_type => :json, :accept => :json},
    timeout: REQUEST_TIMEOUT,
    open_timeout: OPEN_TIMEOUT
  )
  JSON.parse(response).map{|r| Hashie::Mash.new(r)}
end
api_key=(key) click to toggle source
# File lib/gameboy.rb, line 13
def self.api_key=(key)
  @@api_key = key
end
gamer_host() click to toggle source
# File lib/gameboy.rb, line 21
def self.gamer_host
  @@gamer_host ||= "https://gamer.edmodo.com"
end
gamer_host=(host) click to toggle source
# File lib/gameboy.rb, line 17
def self.gamer_host=(host)
  @@gamer_host = host
end
user(user_id, options={}) click to toggle source
# File lib/gameboy.rb, line 51
def self.user(user_id, options={})
  api_key = options.delete(:api_key) || @@api_key
  response = RestClient::Request.execute(
    method: :get,
    url: "#{self.gamer_host}/users/#{user_id}?#{options.to_query}",
    headers: {"Authorization" => "api_key #{api_key}", :content_type => :json, :accept => :json},
    timeout: REQUEST_TIMEOUT,
    open_timeout: OPEN_TIMEOUT
  )
  Hashie::Mash.new(JSON.parse(response))
end
users(user_ids, options={}) click to toggle source
# File lib/gameboy.rb, line 38
def self.users(user_ids, options={})
  api_key = options.delete(:api_key) || @@api_key
  options[:ids] = Array.wrap(user_ids).join(',')
  response = RestClient::Request.execute(
    method: :get,
    url: "#{self.gamer_host}/users?#{options.to_query}",
    headers: {"Authorization" => "api_key #{api_key}", :content_type => :json, :accept => :json},
    timeout: REQUEST_TIMEOUT,
    open_timeout: OPEN_TIMEOUT
  )
  JSON.parse(response).map{|r| Hashie::Mash.new(r)}
end