Class: Johki::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/johki/client.rb

Constant Summary collapse

ROOT_URL =
"https://api.steampowered.com/"

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.


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

def initialize(token)
  @token = token
end

Instance Method Details

#dota2_match(appid = 570) ⇒ Object


36
37
38
# File 'lib/johki/client.rb', line 36

def dota2_match(appid = 570)
  IDOTA2Match.new(self, appid)
end

#get(path, params = {}) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/johki/client.rb', line 17

def get(path, params = {})
  params[:key] = @token
  path += "?" + URI.encode_www_form(params)
  uri = URI.parse(ROOT_URL + path)
  result = Net::HTTP.get_response(uri)
  self.parse(result)
end

#parse(result) ⇒ Object


25
26
27
28
29
30
# File 'lib/johki/client.rb', line 25

def parse(result)
  if result.code != "200"
    raise JohkiError.new(result.body)
  end
  JSON.parse(result.body, symbolize_names: true)
end

#steam_userObject


32
33
34
# File 'lib/johki/client.rb', line 32

def steam_user
  ISteamUser.new(self)
end