tt2 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a428227ce35f912c281e7ac78f5bb40d8b1bceb
4
- data.tar.gz: 7278b6126c0e732a29a9779578930c3bd1da6225
3
+ metadata.gz: '08eb90cc5e429850613e0be0e9b966553bf58c03'
4
+ data.tar.gz: ac3ddeb75fa3e99ce8afd72e940660415eef5a3a
5
5
  SHA512:
6
- metadata.gz: e71965509cc0692b09833ba53c902e0b39f836072e6af0b039bf3e43e9bf19d9c7dbc1b6618fb75b6d56720a4caf3ef2c9ac9c9c3ab975aaaa4c7d8a9547025a
7
- data.tar.gz: aa4bbf9ffa8b8a8d9bf6ce59f625805bc85111dbe6e6deee11fcbc6b153e448b3eacbc44919b4075b8fa4191e2ae5a7389ca8704026f7490c222f66c7b8c1362
6
+ metadata.gz: f940ff584c6b41f9acac46813cbccc8a91f3331566f31e7d56a7ff1fe29c49793d8b06b6a16b4f47e719969af2d283a4b530ac1b34df09c1b2bf8990bdc89336
7
+ data.tar.gz: 7d49fa5d354332260d3fda11cb483fec2229ee9437dc496629b185d925755a35f59cbbd8b5a42a84429bdd15ced56e02a122364b4c81bd9918b16707fc50564d
data/lib/tt2.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'tt2/version'
2
2
  require 'tt2/util'
3
3
  require 'tt2/save_parser'
4
+ require 'tt2/api'
5
+ require 'tt2/client'
4
6
 
5
7
  # Tap Titans 2 (TT2) is an incremental/clicker game made by Game Hive Games of
6
8
  # Toronto, Canada.
data/lib/tt2/api.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'httparty'
2
+
3
+ module TT2
4
+ class API
5
+ include HTTParty
6
+
7
+ attr_accessor :player_id, :auth_token, :created_at
8
+ attr_writer :ad_id
9
+
10
+ base_uri 'https://tt2.gamehivegames.com'
11
+ headers 'Accept' => 'application/vnd.gamehive.btb4-v1.0+json',
12
+ 'User-Agent' => 'BestHTTP',
13
+ 'Content-Type' => 'application/json; charset=UTF-8'
14
+
15
+ def ad_id
16
+ @ad_id || '00000000-0000-0000-0000-000000000000'
17
+ end
18
+
19
+ def query_params(body = '', overrides: {})
20
+ { d: 'ios',
21
+ v: '1.7.1',
22
+ time: TT2::Util.current_time_ticks,
23
+ dummy: Time.now - @created_at,
24
+ s: TT2::Util.request_signature(body, ad_id: ad_id) }.merge(overrides)
25
+ end
26
+
27
+ def request_body(params = {})
28
+ base = { ad_id: ad_id,
29
+ player_id: player_id }
30
+ JSON.generate(base.merge(params))
31
+ end
32
+
33
+ def reset_time
34
+ @created_at = Time.now
35
+ end
36
+
37
+ def get(url)
38
+ self.class.get(url)
39
+ end
40
+
41
+ def post(url, body_params = {})
42
+ body = request_body(body_params)
43
+ post_opts = {
44
+ query: query_params(body),
45
+ body: body,
46
+ headers: {
47
+ 'X-HTTP-Method-Override' => 'POST',
48
+ 'Authorization' => "token #{auth_token}"
49
+ }
50
+ }
51
+ self.class.post(url, post_opts)
52
+ end
53
+ end
54
+ end
data/lib/tt2/client.rb CHANGED
@@ -1,21 +1,11 @@
1
1
  require 'httparty'
2
+
2
3
  module TT2
3
4
  # The TT2 API client
4
- class Client
5
- include HTTParty
6
-
7
- base_uri 'https://tt2.gamehivegames.com'
8
- headers 'Accept' => 'application/vnd.gamehive.btb4-v1.0+json',
9
- 'User-Agent' => 'BestHTTP',
10
- 'Content-Type' => 'application/json; charset=UTF-8'
5
+ class Client < API
6
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
11
7
 
12
- def query_options(data = '')
13
- { d: 'ios',
14
- v: '1.7.1',
15
- time: Tt2::Util.current_time_ticks,
16
- dummy: Time.now - @created_at,
17
- s: Tt2::Util.request_signature(data) }
18
- end
8
+ include ServerTime
19
9
 
20
10
  def initialize(player_id:, auth_token:)
21
11
  @player_id = player_id
@@ -23,9 +13,5 @@ module TT2
23
13
 
24
14
  reset_time
25
15
  end
26
-
27
- def reset_time
28
- @created_at = Time.now
29
- end
30
16
  end
31
17
  end
@@ -0,0 +1,8 @@
1
+ class TT2::Client
2
+ module ServerTime
3
+ def server_time
4
+ data = get('/server_time')
5
+ Time.parse(data['server_time'])
6
+ end
7
+ end
8
+ end
data/lib/tt2/util.rb CHANGED
@@ -3,6 +3,8 @@ require 'openssl'
3
3
  module TT2
4
4
  # This is where all of the fun utility functions like to come and hang out.
5
5
  module Util
6
+ module_function
7
+
6
8
  BOSSES = %w[ Sponkinack Lucanus Caratacos Sklatborg Drakon
7
9
  Straton Grokstomp Grekksfist Zeksgrat FumpTorm
8
10
  RamBloggs Brongunk Plogriftus Darmbonack Gredmash
@@ -37,7 +39,8 @@ module TT2
37
39
  AVATARS = {}.freeze
38
40
 
39
41
  # The signature hash for all requests
40
- def request_signature(data, key: '000')
42
+ def request_signature(data, ad_id: '00000000-0000-0000-0000-000000000000')
43
+ key = ad_id[1] + ad_id[0] + ad_id[3]
41
44
  digest = OpenSSL::Digest.new('md5')
42
45
  OpenSSL::HMAC.hexdigest(digest, key, data)
43
46
  end
data/lib/tt2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TT2
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tt2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Whittaker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,7 +119,9 @@ files:
119
119
  - README.md
120
120
  - exe/tt2
121
121
  - lib/tt2.rb
122
+ - lib/tt2/api.rb
122
123
  - lib/tt2/client.rb
124
+ - lib/tt2/client/server_time.rb
123
125
  - lib/tt2/save_parser.rb
124
126
  - lib/tt2/util.rb
125
127
  - lib/tt2/version.rb