restiny 2.0.1 → 3.1.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 +4 -4
- data/lib/restiny/constants.rb +15 -15
- data/lib/restiny/errors.rb +3 -0
- data/lib/restiny/manifest.rb +4 -18
- data/lib/restiny/version.rb +1 -1
- data/lib/restiny.rb +43 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d08e2f02105ea2a6330679fe9cae0534bbb4a7d3c0fb7803d43fc70ae4ebdd
|
4
|
+
data.tar.gz: 80ab03d4fdbbf65ae276265f89e7c00d9a4f55870fdc0398893e45d429f44179
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abf818ba76d6f6fefbf2070a1d56162462ac2d5a22dae7725383c34ae884d901be3539b78342510beaa93ddc9c3a554e90fcee473825bdcad144ab9a88af8c5
|
7
|
+
data.tar.gz: 78f09f843a2e5c00067b95e1e5aad5a938d181c56081b744e1ae0638605af65548de6d4b117d3667e326bc9ed2ef61aaa80b673990f15cc490045aa2aa9f95ca
|
data/lib/restiny/constants.rb
CHANGED
@@ -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
|
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
|
data/lib/restiny/errors.rb
CHANGED
data/lib/restiny/manifest.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string/literal: true
|
2
|
-
|
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
|
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
|
data/lib/restiny/version.rb
CHANGED
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, :
|
26
|
+
attr_accessor :api_key, :oauth_state, :oauth_client_id, :access_token, :user_agent
|
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[
|
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,39 @@ 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[
|
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
|
49
|
-
result = api_get("Destiny2/Manifest/")
|
50
|
-
|
51
|
-
|
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
|
+
@manifests ||= {}
|
59
|
+
@manifest_versions ||= {}
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
raise Restiny::ResponseError.new("Unable to determine manifest URL") if manifest_url.nil?
|
61
|
+
if force_download || @manifests[locale].nil? || @manifest_versions[locale] != live_version
|
62
|
+
url = BUNGIE_URL + result.dig("mobileWorldContentPaths", locale)
|
56
63
|
|
57
|
-
|
64
|
+
zipped_file = Down.download(url)
|
65
|
+
database_file_path = zipped_file.path + ".db"
|
66
|
+
|
67
|
+
Zip::File.open(zipped_file) { |file| file.first.extract(database_file_path) }
|
68
|
+
|
69
|
+
@manifests[locale] = Manifest.new(database_file_path, live_version)
|
70
|
+
@manifest_versions[locale] = live_version
|
71
|
+
end
|
72
|
+
|
73
|
+
@manifests[locale]
|
74
|
+
rescue Down::Error => error
|
75
|
+
raise Restiny::NetworkError.new("Unable to download the manifest file", error.response.code)
|
76
|
+
rescue Zip::Error => error
|
77
|
+
raise Restiny::Error.new("Unable to unzip the manifest file (#{error})")
|
58
78
|
end
|
59
79
|
|
60
80
|
# Profile and related methods
|
@@ -96,6 +116,17 @@ module Restiny
|
|
96
116
|
api_get("User/GetMembershipsById/#{membership_id}/#{membership_type}/")
|
97
117
|
end
|
98
118
|
|
119
|
+
def get_primary_membership(parent_membership_id, use_fallback: true)
|
120
|
+
result = get_user_memberships_by_id(parent_membership_id)
|
121
|
+
return nil if result.nil? || result["primaryMembershipId"].nil?
|
122
|
+
|
123
|
+
result["destinyMemberships"].each do |membership|
|
124
|
+
return membership if membership["membershipID"] == result["primaryMembershipId"]
|
125
|
+
end
|
126
|
+
|
127
|
+
return result["destinyMemberships"][0] if use_fallback
|
128
|
+
end
|
129
|
+
|
99
130
|
def search_player_by_bungie_name(name, membership_type: Platform::ALL)
|
100
131
|
display_name, display_name_code = name.split("#")
|
101
132
|
if display_name.nil? || display_name_code.nil?
|
@@ -136,7 +167,7 @@ module Restiny
|
|
136
167
|
end
|
137
168
|
|
138
169
|
def default_headers
|
139
|
-
{ "User-Agent": "restiny v#{Restiny::VERSION}" }
|
170
|
+
{ "User-Agent": @user_agent || "restiny v#{Restiny::VERSION}" }
|
140
171
|
end
|
141
172
|
|
142
173
|
def api_connection
|
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:
|
4
|
+
version: 3.1.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-
|
11
|
+
date: 2023-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|