restiny 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d5b81f9aadd44def19fb9af625b26692992457edaf57eeba97b46896f26e032
4
- data.tar.gz: f058584408a167934ae67f9e8c160f75e542f80558446ee312fa2ce34b763ace
3
+ metadata.gz: 64bba6028ea7ef4119e6019011b4d35cf1fb850903b446387b3aae0ba47c03e7
4
+ data.tar.gz: 629969c98d6d518c3cefb7f9c85d177a404408f6d88dd8d979be5e2be75c1027
5
5
  SHA512:
6
- metadata.gz: 5b737a79ec4728c34106b701db09f654c9d642cfd62b3ff311501a70afcf954f07ad92f0d1282c9a59686bffef568ef2b1fb5466e97cd267b389c1634c28b742
7
- data.tar.gz: 99c7c3c4519a6a539a11a2970f18a38443ee4a9587b6df980cb74b03e425f1ce134e48c075af0d5b8d29339e086310eda6c44ac352e0b4daf80997923fded98b
6
+ metadata.gz: 65a76e2738de6da2e4e3dfaf6015f689d8c95d8fea9daa952d153fdf251feec6a145fa16b627bfd2baea1eb3c05cc7d83058e1670b1715d9ea21c18409f081c5
7
+ data.tar.gz: 70565f0ddc5c22d76f32cb1e4883261e3bbf181bd7e330a125a3c6982db1b95f6e14342aae7600379ded28697eef9f369ce4b50896b6388de984eea520aec971
@@ -9,20 +9,6 @@ module Restiny
9
9
  EPIC = 6
10
10
  end
11
11
 
12
- module ComponentType
13
- CHARACTERS = "Characters"
14
- CHARACTER_EQUIPMENT = "CharacterEquipment"
15
- CHARACTER_INVENTORIES = "CharacterInventories"
16
- CHARACTER_LOADOUTS = "CharacterLoadouts"
17
- PROFILES = "Profiles"
18
- PROFILE_INVENTORIES = "ProfileInventories"
19
- ITEM_INSTANCES = "ItemInstances"
20
- ITEM_SOCKETS = "ItemSockets"
21
- ITEM_COMMON_DATA = "ItemCommonData"
22
- ITEM_PLUG_STATES = "ItemPlugStates"
23
- ITEM_REUSABLE_PLUGS = "ItemReusablePlugs"
24
- end
25
-
26
12
  module ItemLocation
27
13
  UNKNOWN = 0
28
14
  INVENTORY = 1
@@ -41,7 +27,7 @@ module Restiny
41
27
  EXOTIC = 6
42
28
  end
43
29
 
44
- module Class
30
+ module GuardianClass
45
31
  TITAN = 0
46
32
  HUNTER = 1
47
33
  WARLOCK = 2
@@ -68,4 +54,18 @@ module Restiny
68
54
  HEAVY = 3
69
55
  UNKNOWN = 4
70
56
  end
57
+
58
+ module ComponentType
59
+ CHARACTERS = "Characters"
60
+ CHARACTER_EQUIPMENT = "CharacterEquipment"
61
+ CHARACTER_INVENTORIES = "CharacterInventories"
62
+ CHARACTER_LOADOUTS = "CharacterLoadouts"
63
+ PROFILES = "Profiles"
64
+ PROFILE_INVENTORIES = "ProfileInventories"
65
+ ITEM_INSTANCES = "ItemInstances"
66
+ ITEM_SOCKETS = "ItemSockets"
67
+ ITEM_COMMON_DATA = "ItemCommonData"
68
+ ITEM_PLUG_STATES = "ItemPlugStates"
69
+ ITEM_REUSABLE_PLUGS = "ItemReusablePlugs"
70
+ end
71
71
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string/literal: true
2
- require "down"
3
- require "json"
2
+
4
3
  require "sqlite3"
5
- require "zip"
6
4
 
7
5
  module Restiny
8
6
  class Manifest
@@ -72,7 +70,7 @@ module Restiny
72
70
  VendorGroup: %w[vendor_group vendor_groups]
73
71
  }
74
72
 
75
- attr_reader :file_path
73
+ attr_reader :file_path, :version
76
74
 
77
75
  ENTITIES.each do |entity, method_names|
78
76
  full_table_name = "Destiny#{entity}Definition"
@@ -87,26 +85,14 @@ module Restiny
87
85
  end
88
86
  end
89
87
 
90
- def self.download_by_url(url)
91
- zipped_file = Down.download(url)
92
- manifest_path = zipped_file.path + ".db"
93
-
94
- Zip::File.open(zipped_file) { |file| file.first.extract(manifest_path) }
95
-
96
- new(manifest_path)
97
- rescue Down::ResponseError => error
98
- raise Restiny::NetworkError.new("Unable to download the manifest file", error.response.code)
99
- rescue Zip::Error => error
100
- raise Restiny::Error.new("Unable to unzip the manifest file (#{error})")
101
- end
102
-
103
- def initialize(file_path)
88
+ def initialize(file_path, version)
104
89
  if file_path.empty? || !File.exist?(file_path) || !File.file?(file_path)
105
90
  raise Restiny::InvalidParamsError.new("You must provide a valid path for the manifest file")
106
91
  end
107
92
 
108
93
  @database = SQLite3::Database.new(file_path, results_as_hash: true)
109
94
  @file_path = file_path
95
+ @version = version
110
96
  end
111
97
 
112
98
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restiny
4
- VERSION = "2.0.1"
4
+ VERSION = "3.0.0"
5
5
  end
data/lib/restiny.rb CHANGED
@@ -11,7 +11,11 @@ require "faraday"
11
11
  require "faraday/follow_redirects"
12
12
  require "faraday/destiny/api"
13
13
  require "faraday/destiny/auth"
14
+
15
+ require "down"
16
+ require "json"
14
17
  require "securerandom"
18
+ require "zip"
15
19
 
16
20
  module Restiny
17
21
  extend self
@@ -19,7 +23,7 @@ module Restiny
19
23
  BUNGIE_URL = "https://www.bungie.net"
20
24
  API_BASE_URL = BUNGIE_URL + "/platform"
21
25
 
22
- attr_accessor :api_key, :oauth_state, :oauth_client_id, :access_token, :refresh_token, :manifest
26
+ attr_accessor :api_key, :oauth_state, :oauth_client_id, :access_token
23
27
 
24
28
  # OAuth methods
25
29
 
@@ -29,7 +33,7 @@ module Restiny
29
33
  @oauth_state = state || SecureRandom.hex(15)
30
34
 
31
35
  params = { response_type: "code", client_id: @oauth_client_id, state: @oauth_state }
32
- params[:redirect_url] = redirect_url unless redirect_url.nil?
36
+ params["redirect_url"] = redirect_url unless redirect_url.nil?
33
37
 
34
38
  auth_connection.build_url(BUNGIE_URL + "/en/oauth/authorize/", params).to_s
35
39
  end
@@ -38,23 +42,36 @@ module Restiny
38
42
  check_oauth_client_id
39
43
 
40
44
  params = { code: code, grant_type: "authorization_code", client_id: @oauth_client_id }
41
- params[:redirect_url] = redirect_url unless redirect_url.nil?
45
+ params["redirect_url"] = redirect_url unless redirect_url.nil?
42
46
 
43
47
  auth_post("app/oauth/token/", params)
44
48
  end
45
49
 
46
50
  # Manifest methods
47
51
 
48
- def get_manifest_url(locale: "en")
49
- result = api_get("Destiny2/Manifest/").dig("mobileWorldContentPaths", locale)
50
- BUNGIE_URL + result
51
- end
52
+ def get_manifest(locale: "en", force_download: false)
53
+ result = api_get("Destiny2/Manifest/")
54
+ raise Restiny::ResponseError.new("Unable to determine manifest details") if result.nil?
55
+
56
+ live_version = result.dig("version")
57
+
58
+ if force_download || @manifest.nil? || @manifest_version != live_version
59
+ url = BUNGIE_URL + result.dig("mobileWorldContentPaths", locale)
52
60
 
53
- def download_manifest(locale: "en")
54
- manifest_url = get_manifest_url
55
- raise Restiny::ResponseError.new("Unable to determine manifest URL") if manifest_url.nil?
61
+ zipped_file = Down.download(url)
62
+ database_file_path = zipped_file.path + ".db"
63
+
64
+ Zip::File.open(zipped_file) { |file| file.first.extract(database_file_path) }
65
+
66
+ @manifest = Manifest.new(database_file_path, live_version)
67
+ @manifest_version = live_version
68
+ end
56
69
 
57
- Manifest.download_by_url(BUNGIE_URL + manifest_url)
70
+ @manifest
71
+ rescue Down::Error => e
72
+ raise Restiny::NetworkError.new("Unable to download the manifest file", error.response.code)
73
+ rescue Zip::Error => error
74
+ raise Restiny::Error.new("Unable to unzip the manifest file (#{error})")
58
75
  end
59
76
 
60
77
  # Profile and related methods
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-02 00:00:00.000000000 Z
11
+ date: 2023-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday