Class: Dotka

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDotka

Returns a new instance of Dotka.



8
9
10
# File 'lib/dotka.rb', line 8

def initialize
  @key = nil
end

Class Method Details

.versionObject

Rather than updating the gemspec every time.



57
58
59
# File 'lib/dotka.rb', line 57

def self.version
  "1.2.2"
end

Instance Method Details

#get_api_keyObject



16
17
18
# File 'lib/dotka.rb', line 16

def get_api_key
  @key
end

#match(id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dotka.rb', line 20

def match id

  raise "Please set up the API key!" unless not @key.nil?

  response = RestClient.get(
    "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001",
    {"params" => {"key" => @key, "match_id" => id}}
  )

  raise "Can not load a match with ID #{id}." unless response.code == 200

  DotkaM::Match.new(JSON.parse(response.to_str)["result"])

end

#matches(account_id, conditions = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dotka.rb', line 35

def matches , conditions = {}

  raise "Please set up the API key!" unless not @key.nil?

  response = RestClient.get(
    "https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001",
    {"params" => {"key" => @key, "account_id" => }.merge(conditions)}
  )

  raise "Can not load matches for account ID #{account_id}." unless response.code == 200

  matches = Array.new

  JSON.parse(response.to_str)["result"]["matches"].each { |match|
    matches.push DotkaM::Match.new(match)
  }

  matches

end

#set_api_key(key) ⇒ Object



12
13
14
# File 'lib/dotka.rb', line 12

def set_api_key key
  @key = key
end