Class: TT2::API
Direct Known Subclasses
Instance Attribute Summary collapse
- #ad_id ⇒ Object
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
Instance Method Summary collapse
- #get(url) ⇒ Object
- #post(url, body_params = {}) ⇒ Object
- #query_params(body = '', overrides: {}) ⇒ Object
- #request_body(params = {}) ⇒ Object
- #reset_time ⇒ Object
Instance Attribute Details
#ad_id ⇒ Object
16 17 18 |
# File 'lib/tt2/api.rb', line 16 def ad_id @ad_id || '00000000-0000-0000-0000-000000000000' end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
8 9 10 |
# File 'lib/tt2/api.rb', line 8 def auth_token @auth_token end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/tt2/api.rb', line 8 def created_at @created_at end |
#player_id ⇒ Object
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_time ⇒ Object
34 35 36 |
# File 'lib/tt2/api.rb', line 34 def reset_time @created_at = Time.now end |