swgoh_comlink 0.1.0 → 0.2.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/comlink_api_request.rb +4 -10
- data/lib/swgoh_comlink.rb +46 -52
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72d9903becab7ebfd24af4c0dd670d75d857c5c27805807ffadb290cad2dce1b
|
4
|
+
data.tar.gz: 3c133648ded6dd5f903ae9a18933609b1c0834ae4a02bc76aa7475b698b34c41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9819959f94a67fe0d6e220eca9d01fed1f7382bb259477b0aa951b8c4314b05a4ec5fd8c8a9b15ea017863d307acd504106787694801da7ecad253c0d540208f
|
7
|
+
data.tar.gz: 6f17edc8b9df09cf3fe7d44fe58ad8310351a8fce7511a8bc185735a764c30943b6640535f7a4592a6cfb2ca5a557eb5b671e59a6dfe6bd8a997f8548de85563
|
data/lib/comlink_api_request.rb
CHANGED
@@ -3,7 +3,6 @@ require 'digest'
|
|
3
3
|
require 'json'
|
4
4
|
require 'net/http'
|
5
5
|
require 'uri'
|
6
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
7
6
|
|
8
7
|
class ComlinkApiRequest
|
9
8
|
attr_accessor :hmac_enabled, :comlink_url
|
@@ -13,9 +12,9 @@ class ComlinkApiRequest
|
|
13
12
|
@hmac_enabled = false
|
14
13
|
return if keys.empty?
|
15
14
|
|
16
|
-
keys = keys.
|
17
|
-
@secret_key = keys[
|
18
|
-
@access_key = keys[
|
15
|
+
keys = keys.transform_keys(&:to_sym)
|
16
|
+
@secret_key = keys[:secret_key]
|
17
|
+
@access_key = keys[:access_key]
|
19
18
|
|
20
19
|
raise ArgumentError, 'Secret key missing' unless @secret_key
|
21
20
|
raise ArgumentError, 'Access key missing' unless @access_key
|
@@ -24,12 +23,7 @@ class ComlinkApiRequest
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def get(path)
|
27
|
-
|
28
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
-
http.use_ssl = true
|
30
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
31
|
-
|
32
|
-
http.request(request).body
|
26
|
+
Net::HTTP.get_response(URI("#{@comlink_url}#{path}")).body
|
33
27
|
end
|
34
28
|
|
35
29
|
def post(path, body)
|
data/lib/swgoh_comlink.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_support/core_ext/hash'
|
4
|
-
require 'active_support/core_ext/string'
|
5
3
|
require_relative 'comlink_api_request'
|
6
4
|
|
7
5
|
# Base class for the gem, a wrapper for Comlink
|
8
6
|
# See https://github.com/swgoh-utils/swgoh-comlink for more info on Comlink
|
9
7
|
class SwgohComlink
|
10
|
-
def initialize(comlink_url, keys
|
8
|
+
def initialize(comlink_url, **keys)
|
11
9
|
@api_requester = ComlinkApiRequest.new(comlink_url, keys)
|
12
10
|
end
|
13
11
|
|
@@ -16,56 +14,51 @@ class SwgohComlink
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def localization(id, unzip = false, enums = false)
|
19
|
-
body = {
|
20
|
-
payload: {
|
21
|
-
id: id
|
22
|
-
},
|
23
|
-
unzip: unzip,
|
24
|
-
enums: enums
|
25
|
-
}
|
17
|
+
body = { payload: { id: }, unzip:, enums: }
|
26
18
|
|
27
|
-
|
19
|
+
parse_post_response('/localization', body.to_json)
|
28
20
|
end
|
29
21
|
|
30
22
|
def metadata(client_specs = {}, enums = false)
|
31
23
|
body = {}
|
32
|
-
|
33
|
-
|
24
|
+
unless client_specs.empty?
|
25
|
+
body['payload'] = {
|
26
|
+
clientSpecs: verify_parameters(client_specs, [:platform, :bundleId, :externalVersion, :internalVersion, :region])
|
27
|
+
}
|
28
|
+
end
|
29
|
+
body['enums'] = enums
|
34
30
|
|
35
|
-
|
31
|
+
parse_post_response('/metadata', body.to_json)
|
36
32
|
end
|
37
33
|
|
38
34
|
def data(version, include_pve_units = true, request_segment = 0, enums = false)
|
39
35
|
body = {
|
40
36
|
payload: {
|
41
|
-
version
|
37
|
+
version:,
|
42
38
|
includePveUnits: include_pve_units,
|
43
39
|
requestSegment: request_segment
|
44
40
|
},
|
45
|
-
enums:
|
41
|
+
enums:
|
46
42
|
}
|
47
43
|
|
48
44
|
body_validation(body, [ { validation: (0..4), error_message: 'Request segment must be between 0 and 4', path: [:payload, :requestSegment] } ])
|
49
45
|
|
50
|
-
|
46
|
+
parse_post_response('/data', body.to_json)
|
51
47
|
end
|
52
48
|
|
53
49
|
def player(player_id, enums = false)
|
54
|
-
body = {
|
55
|
-
payload: format_player_id_hash(player_id),
|
56
|
-
enums: enums
|
57
|
-
}
|
50
|
+
body = { payload: format_player_id_hash(player_id), enums: }
|
58
51
|
|
59
|
-
|
52
|
+
parse_post_response('/player', body.to_json)
|
60
53
|
end
|
61
54
|
|
62
55
|
def player_arena(player_id, enums = false)
|
63
56
|
body = {
|
64
57
|
payload: format_player_id_hash(player_id),
|
65
|
-
enums:
|
58
|
+
enums:
|
66
59
|
}
|
67
60
|
|
68
|
-
|
61
|
+
parse_post_response('/playerArena', body.to_json)
|
69
62
|
end
|
70
63
|
|
71
64
|
def guild(guild_id, include_recent_guild_activity = false, enums = false)
|
@@ -74,18 +67,18 @@ class SwgohComlink
|
|
74
67
|
guildId: guild_id,
|
75
68
|
includeRecentGuildActivityInfo: include_recent_guild_activity
|
76
69
|
},
|
77
|
-
enums:
|
70
|
+
enums:
|
78
71
|
}
|
79
72
|
|
80
|
-
|
73
|
+
parse_post_response('/guild', body.to_json)
|
81
74
|
end
|
82
75
|
|
83
76
|
def get_guilds(filter_type, name = nil, search_criteria = nil, count = 10, enums = false)
|
84
77
|
body = {
|
85
78
|
payload: {
|
86
79
|
filterType: filter_type,
|
87
|
-
count
|
88
|
-
enums:
|
80
|
+
count:,
|
81
|
+
enums:
|
89
82
|
}
|
90
83
|
}
|
91
84
|
|
@@ -95,50 +88,45 @@ class SwgohComlink
|
|
95
88
|
body[:payload][:name] = name
|
96
89
|
validations << { error_message: 'Name is required when filterType is 4', path: [:payload, :name], required: true }
|
97
90
|
elsif filter_type == 5
|
98
|
-
body[:payload][:searchCriteria] = search_criteria && verify_parameters(search_criteria, [
|
91
|
+
body[:payload][:searchCriteria] = search_criteria && verify_parameters(search_criteria, [:minMemberCount, :maxMemberCount, :includeInviteOnly, :minGuildGalacticPower, :maxGuildGalacticPower, :recentTbParticipatedIn])
|
99
92
|
validations << { error_message: 'searchCriteria is required when filterType is 5', path: [:payload, :searchCriteria], required: true }
|
100
93
|
end
|
101
94
|
|
102
95
|
body_validation(body, validations)
|
103
96
|
|
104
|
-
|
97
|
+
parse_post_response('/getGuilds', body.to_json)
|
105
98
|
end
|
106
99
|
|
107
100
|
def get_events(enums = false)
|
108
|
-
body = {
|
109
|
-
enums: enums
|
110
|
-
}
|
101
|
+
body = { enums: }
|
111
102
|
|
112
|
-
|
103
|
+
parse_post_response('/getEvents', body.to_json)
|
113
104
|
end
|
114
105
|
|
115
106
|
def get_leaderboard(payload, enums = false)
|
116
107
|
body_validation(payload, [ { validation: [4, 6], error_message: 'leaderboardType must be 4 or 6', path: [:leaderboardType] } ])
|
117
108
|
|
118
109
|
if payload[:leaderboardType] == 4 || payload[:leaderboard_type] == 4
|
119
|
-
payload = verify_parameters(payload, [
|
110
|
+
payload = verify_parameters(payload, [:leaderboardType, :eventInstanceId, :groupId])
|
120
111
|
body_validation(payload, [
|
121
112
|
{ error_message: 'eventInstanceId must be present', path: [:eventInstanceId], required: true },
|
122
113
|
{ error_message: 'groupId must be present', path: [:groupId], required: true }
|
123
114
|
])
|
124
115
|
else
|
125
|
-
payload = verify_parameters(payload, [
|
116
|
+
payload = verify_parameters(payload, [:leaderboardType, :league, :division])
|
126
117
|
body_validation(payload, [
|
127
118
|
{ validation: [20, 40, 60, 80, 100], error_message: 'league must be in [20, 40, 60, 80, 100]', path: [:league], required: true },
|
128
119
|
{ validation: [5, 10, 15, 20, 25], error_message: 'division must be in [5, 10, 15, 20, 25]', path: [:division], required: true }
|
129
120
|
])
|
130
121
|
end
|
131
122
|
|
132
|
-
body = {
|
133
|
-
payload: payload,
|
134
|
-
enums: false
|
135
|
-
}
|
123
|
+
body = { payload:, enums: }
|
136
124
|
|
137
|
-
|
125
|
+
parse_post_response('/getLeaderboard', body.to_json)
|
138
126
|
end
|
139
127
|
|
140
128
|
def get_guild_leaderboard(leaderboards, count, enums = false)
|
141
|
-
|
129
|
+
valid_def_ids = [
|
142
130
|
'sith_raid',
|
143
131
|
'rancor',
|
144
132
|
'aat',
|
@@ -161,10 +149,10 @@ class SwgohComlink
|
|
161
149
|
]
|
162
150
|
|
163
151
|
leaderboards.each do |leaderboard|
|
164
|
-
payload = verify_parameters(leaderboard, [
|
152
|
+
payload = verify_parameters(leaderboard, [:leaderboardType, :defId, :monthOffset])
|
165
153
|
body_validation(leaderboard, [
|
166
154
|
{ validation: [0, 2, 3, 4, 5, 6], error_message: 'leaderboardType must in [0, 2, 3, 4, 5, 6]', path: [:leaderboardType], required: true },
|
167
|
-
{ validation:
|
155
|
+
{ validation: valid_def_ids, error_message: 'defId must be certain values, see docs', path: [:defId], required: [2, 4, 5, 6].include?(leaderboard.transform_keys(&:to_sym)[:leaderboardType]) },
|
168
156
|
{ validation: [0, 1], error_message: 'monthOffset must 0 or 1', path: [:monthOffset] }
|
169
157
|
])
|
170
158
|
end
|
@@ -172,12 +160,12 @@ class SwgohComlink
|
|
172
160
|
body = {
|
173
161
|
payload: {
|
174
162
|
leaderboardId: leaderboards,
|
175
|
-
count:
|
163
|
+
count:
|
176
164
|
},
|
177
|
-
enums:
|
165
|
+
enums:
|
178
166
|
}
|
179
167
|
|
180
|
-
|
168
|
+
parse_post_response('/getGuildLeaderboard', body.to_json)
|
181
169
|
end
|
182
170
|
|
183
171
|
private
|
@@ -191,12 +179,10 @@ class SwgohComlink
|
|
191
179
|
end
|
192
180
|
|
193
181
|
def verify_parameters(original_hash, permitted_keys)
|
194
|
-
original_hash = original_hash.
|
195
|
-
|
196
|
-
original_hash.transform_keys! { |key| key.to_s.camelize(:lower) }
|
197
|
-
original_hash.slice!(*permitted_keys)
|
182
|
+
original_hash = original_hash.transform_keys(&:to_sym)
|
198
183
|
|
199
|
-
original_hash
|
184
|
+
original_hash.transform_keys! { |key| camelize(key.to_s).to_sym }
|
185
|
+
original_hash.select { |key| permitted_keys.include?(key) }
|
200
186
|
end
|
201
187
|
|
202
188
|
def body_validation(body, requirements)
|
@@ -210,4 +196,12 @@ class SwgohComlink
|
|
210
196
|
|
211
197
|
true
|
212
198
|
end
|
199
|
+
|
200
|
+
def parse_post_response(route, body)
|
201
|
+
JSON.parse(@api_requester.post(route, body.to_json))
|
202
|
+
end
|
203
|
+
|
204
|
+
def camelize(string)
|
205
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
206
|
+
end
|
213
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swgoh_comlink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Moses
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -72,14 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.1.0
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubygems_version: 3.5.
|
82
|
+
rubygems_version: 3.5.11
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: 'Created to connect with deployed Star Wars: Galaxy of Heroes Comlink APIs.
|