Module: Gameboy

Defined in:
lib/gameboy.rb,
lib/gameboy/version.rb

Constant Summary collapse

REQUEST_TIMEOUT =
60
OPEN_TIMEOUT =
5
VERSION =
"0.1.0"
@@api_key =
"SET_YOUR_API_KEY"
@@gamer_host =

Optional

nil

Class Method Summary collapse

Class Method Details

.api_key=(key) ⇒ Object



13
14
15
# File 'lib/gameboy.rb', line 13

def self.api_key=(key)
  @@api_key = key
end

.gamer_hostObject



21
22
23
# File 'lib/gameboy.rb', line 21

def self.gamer_host
  @@gamer_host ||= "https://gamer.edmodo.com"
end

.gamer_host=(host) ⇒ Object



17
18
19
# File 'lib/gameboy.rb', line 17

def self.gamer_host=(host)
  @@gamer_host = host
end

.upcoming_achievements_for_user(user_id, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gameboy.rb', line 25

def self.upcoming_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/upcoming?#{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

.user(user_id, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# 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 = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# 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