Class: TT2::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tt2/api.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ad_idObject



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

def ad_id
  @ad_id || '00000000-0000-0000-0000-000000000000'
end

#auth_tokenObject

Returns the value of attribute auth_token.



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

def auth_token
  @auth_token
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#player_idObject

Returns the value of attribute player_id.



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

def player_id
  @player_id
end

Instance Method Details

#get(url) ⇒ Object



38
39
40
# File 'lib/tt2/api.rb', line 38

def get(url)
  self.class.get(url)
end

#post(url, body_params = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tt2/api.rb', line 42

def post(url, body_params = {})
  body = request_body(body_params)
  post_opts = {
    query:   query_params(body),
    body:    body,
    headers: {
      'X-HTTP-Method-Override' => 'POST',
      'Authorization'          => "token #{auth_token}"
    }
  }
  self.class.post(url, post_opts)
end

#query_params(body = '', overrides: {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/tt2/api.rb', line 20

def query_params(body = '', overrides: {})
  { d:     'ios',
    v:     '1.7.1',
    time:  TT2::Util.current_time_ticks,
    dummy: Time.now - @created_at,
    s:     TT2::Util.request_signature(body, ad_id: ad_id) }.merge(overrides)
end

#request_body(params = {}) ⇒ Object



28
29
30
31
32
# File 'lib/tt2/api.rb', line 28

def request_body(params = {})
  base = { ad_id:     ad_id,
           player_id: player_id }
  JSON.generate(base.merge(params))
end

#reset_timeObject



34
35
36
# File 'lib/tt2/api.rb', line 34

def reset_time
  @created_at = Time.now
end