SWGOH-API 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +7 -5
- data/lib/SWGOH/API/CLIENT/LOG/log.rb +11 -0
- data/lib/SWGOH/API/CLIENT/client.rb +135 -161
- data/lib/SWGOH/API/CLIENT/requester.rb +74 -0
- data/lib/SWGOH/API/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0936d97bbc27257a609fa8780d870f1694439ef96c8ff9224fe93f74e8db77fc'
|
4
|
+
data.tar.gz: 7533b6ec009211503537a4d1c6ddc076546bb88e59840b3229c2570beaf35de9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa3b5622c70b2e6935db81a7d946310f1364956c1620684bf6a32b3aa88b7d48a90af687203e6f12d949e5b5d35c2367edb1269ba66c04a44dee7434b537b46d
|
7
|
+
data.tar.gz: 8e6bf057f7b99a1705ae576bb092341ef0e60f27f8275fc032f11123e31f01badbb26cc286532209f920ae2aac13ed817ffb90e9a1152ffe3076ae746359724b
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
2
2
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
3
3
|
|
4
|
-
## [
|
4
|
+
## [1.0.0]
|
5
|
+
## Added
|
6
|
+
- Added param Hash to methods by [@jquass](https://github.com/jquass)
|
7
|
+
- Added LOG helper class by [@jquass](https://github.com/jquass)
|
8
|
+
- Added Requester class by [@jquass](https://github.com/jquass)
|
5
9
|
|
6
10
|
## [0.4.0] - 2020-10-16
|
7
11
|
## Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,15 +3,17 @@ Ruby client wrapper for the API at https://api.swgoh.help .
|
|
3
3
|
|
4
4
|
### Installation
|
5
5
|
|
6
|
-
|
6
|
+
Gemfile:
|
7
7
|
|
8
8
|
```ruby
|
9
|
-
gem 'SWGOH-API'
|
9
|
+
gem 'SWGOH-API', '~> 1.0.0'
|
10
10
|
```
|
11
11
|
|
12
|
-
|
12
|
+
Install:
|
13
13
|
|
14
|
-
|
14
|
+
```ruby
|
15
|
+
gem install SWGOH-API
|
16
|
+
```
|
15
17
|
|
16
18
|
## Usage
|
17
19
|
```ruby
|
@@ -62,7 +64,7 @@ Run `rake test` to run the unit tests.
|
|
62
64
|
These are the steps to create and tag a new version, push git commits and tags, and push the new gem version to [rubygems.org](https://rubygems.org).
|
63
65
|
|
64
66
|
- Update the CHANGELOG and assign version number
|
65
|
-
- Update the version number in `version.rb
|
67
|
+
- Update the version number in `version.rb`, and the README.md
|
66
68
|
- Run `gem build SWGOH-API.gemspec` to build the new gem version
|
67
69
|
- Run the release once to generate all files to commit `bundle exec rake release`
|
68
70
|
- Create a new version commit with all changes
|
@@ -1,21 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'SWGOH/API'
|
4
|
-
require '
|
5
|
-
require 'net/http'
|
6
|
-
require 'json'
|
4
|
+
require 'SWGOH/API/CLIENT/requester'
|
7
5
|
|
8
6
|
# The CLIENT class makes requests to api.swgoh.api
|
9
7
|
class CLIENT
|
10
|
-
|
11
|
-
attr_writer :access_token
|
8
|
+
attr_writer :access_token, :requester
|
12
9
|
|
13
10
|
def initialize
|
14
|
-
@language = SWGOH::API::LANGUAGE::ENG_US
|
15
|
-
@enums = false
|
16
|
-
@structure = false
|
17
11
|
@access_token = nil
|
18
|
-
@
|
12
|
+
@requester = REQUESTER.new
|
19
13
|
end
|
20
14
|
|
21
15
|
# @return [Boolean]
|
@@ -27,299 +21,279 @@ class CLIENT
|
|
27
21
|
# @param [String] password
|
28
22
|
# @return [String | nil]
|
29
23
|
def authorize(username, password)
|
30
|
-
|
31
|
-
|
32
|
-
res = Net::HTTP.post_form(URI(path), form)
|
33
|
-
return log_error(res) unless res.is_a?(Net::HTTPSuccess)
|
34
|
-
|
35
|
-
@access_token = JSON.parse(res.body)['access_token']
|
24
|
+
response = @requester.auth_request(username, password)
|
25
|
+
@access_token = response['access_token'] unless response.nil?
|
36
26
|
end
|
37
27
|
|
38
28
|
# @param [Array] ally_codes
|
29
|
+
# @param [Hash] params
|
39
30
|
# @return [JSON || nil]
|
40
|
-
def players(ally_codes)
|
41
|
-
ally_codes_request(SWGOH::API::PATH::PLAYER, ally_codes)
|
31
|
+
def players(ally_codes, params = {})
|
32
|
+
ally_codes_request(SWGOH::API::PATH::PLAYER, ally_codes, params)
|
42
33
|
end
|
43
34
|
|
44
35
|
# @param [Array] ally_codes
|
36
|
+
# @param [Hash] params
|
45
37
|
# @return [JSON || nil]
|
46
|
-
def guilds(ally_codes)
|
47
|
-
ally_codes_request(SWGOH::API::PATH::GUILD, ally_codes)
|
38
|
+
def guilds(ally_codes, params = {})
|
39
|
+
ally_codes_request(SWGOH::API::PATH::GUILD, ally_codes, params)
|
48
40
|
end
|
49
41
|
|
50
42
|
# @param [Array] ally_codes
|
43
|
+
# @param [Hash] params
|
51
44
|
# @return [JSON || nil]
|
52
|
-
def rosters(ally_codes)
|
53
|
-
ally_codes_request(SWGOH::API::PATH::ROSTER, ally_codes)
|
45
|
+
def rosters(ally_codes, params = {})
|
46
|
+
ally_codes_request(SWGOH::API::PATH::ROSTER, ally_codes, params)
|
54
47
|
end
|
55
48
|
|
56
49
|
# @param [Array] ally_codes
|
50
|
+
# @param [Hash] params
|
57
51
|
# @return [JSON || nil]
|
58
|
-
def units(ally_codes)
|
59
|
-
ally_codes_request(SWGOH::API::PATH::UNITS, ally_codes)
|
52
|
+
def units(ally_codes, params = {})
|
53
|
+
ally_codes_request(SWGOH::API::PATH::UNITS, ally_codes, params)
|
60
54
|
end
|
61
55
|
|
56
|
+
# @param [Hash] params
|
62
57
|
# @return [JSON || nil]
|
63
|
-
def zetas
|
64
|
-
request(SWGOH::API::PATH::ZETAS)
|
58
|
+
def zetas(params = {})
|
59
|
+
request(SWGOH::API::PATH::ZETAS, params)
|
65
60
|
end
|
66
61
|
|
62
|
+
# @param [Hash] params
|
67
63
|
# @return [JSON || nil]
|
68
|
-
def squads
|
69
|
-
request(SWGOH::API::PATH::SQUADS)
|
64
|
+
def squads(params = {})
|
65
|
+
request(SWGOH::API::PATH::SQUADS, params)
|
70
66
|
end
|
71
67
|
|
68
|
+
# @param [Hash] params
|
72
69
|
# @return [JSON || nil]
|
73
|
-
def events
|
74
|
-
request(SWGOH::API::PATH::EVENTS)
|
70
|
+
def events(params = {})
|
71
|
+
request(SWGOH::API::PATH::EVENTS, params)
|
75
72
|
end
|
76
73
|
|
74
|
+
# @param [Hash] params
|
77
75
|
# @return [JSON || nil]
|
78
|
-
def battles
|
79
|
-
request(SWGOH::API::PATH::BATTLES)
|
76
|
+
def battles(params = {})
|
77
|
+
request(SWGOH::API::PATH::BATTLES, params)
|
80
78
|
end
|
81
79
|
|
80
|
+
# @param [Hash] params
|
82
81
|
# @return [JSON || nil]
|
83
|
-
def abilities
|
84
|
-
|
82
|
+
def abilities(params = {})
|
83
|
+
data_collection_request(SWGOH::API::COLLECTION::ABILITY, params)
|
85
84
|
end
|
86
85
|
|
86
|
+
# @param [Hash] params
|
87
87
|
# @return [JSON || nil]
|
88
|
-
def battle_environments
|
89
|
-
|
88
|
+
def battle_environments(params = {})
|
89
|
+
data_collection_request(SWGOH::API::COLLECTION::BATTLE_ENVIRONMENT, params)
|
90
90
|
end
|
91
91
|
|
92
|
+
# @param [Hash] params
|
92
93
|
# @return [JSON || nil]
|
93
|
-
def battle_targeting_rules
|
94
|
-
|
94
|
+
def battle_targeting_rules(params = {})
|
95
|
+
data_collection_request(SWGOH::API::COLLECTION::BATTLE_TARGETING_RULE, params)
|
95
96
|
end
|
96
97
|
|
98
|
+
# @param [Hash] params
|
97
99
|
# @return [JSON || nil]
|
98
|
-
def categories
|
99
|
-
|
100
|
+
def categories(params = {})
|
101
|
+
data_collection_request(SWGOH::API::COLLECTION::CATEGORY, params)
|
100
102
|
end
|
101
103
|
|
104
|
+
# @param [Hash] params
|
102
105
|
# @return [JSON || nil]
|
103
|
-
def challenges
|
104
|
-
|
106
|
+
def challenges(params = {})
|
107
|
+
data_collection_request(SWGOH::API::COLLECTION::CHALLENGE, params)
|
105
108
|
end
|
106
109
|
|
110
|
+
# @param [Hash] params
|
107
111
|
# @return [JSON || nil]
|
108
|
-
def challenge_styles
|
109
|
-
|
112
|
+
def challenge_styles(params = {})
|
113
|
+
data_collection_request(SWGOH::API::COLLECTION::CHALLENGE_STYLE, params)
|
110
114
|
end
|
111
115
|
|
116
|
+
# @param [Hash] params
|
112
117
|
# @return [JSON || nil]
|
113
|
-
def effects
|
114
|
-
|
118
|
+
def effects(params = {})
|
119
|
+
data_collection_request(SWGOH::API::COLLECTION::EFFECT, params)
|
115
120
|
end
|
116
121
|
|
122
|
+
# @param [Hash] params
|
117
123
|
# @return [JSON || nil]
|
118
|
-
def environment_collections
|
119
|
-
|
124
|
+
def environment_collections(params = {})
|
125
|
+
data_collection_request(SWGOH::API::COLLECTION::ENVIRONMENT_COLLECTION, params)
|
120
126
|
end
|
121
127
|
|
128
|
+
# @param [Hash] params
|
122
129
|
# @return [JSON || nil]
|
123
|
-
def equipment
|
124
|
-
|
130
|
+
def equipment(params = {})
|
131
|
+
data_collection_request(SWGOH::API::COLLECTION::EQUIPMENT, params)
|
125
132
|
end
|
126
133
|
|
134
|
+
# @param [Hash] params
|
127
135
|
# @return [JSON || nil]
|
128
|
-
def event_samples
|
129
|
-
|
136
|
+
def event_samples(params = {})
|
137
|
+
data_collection_request(SWGOH::API::COLLECTION::EVENT_SAMPLING, params)
|
130
138
|
end
|
131
139
|
|
140
|
+
# @param [Hash] params
|
132
141
|
# @return [JSON || nil]
|
133
|
-
def guild_exchange_items
|
134
|
-
|
142
|
+
def guild_exchange_items(params = {})
|
143
|
+
data_collection_request(SWGOH::API::COLLECTION::GUILD_EXCHANGE_ITEM, params)
|
135
144
|
end
|
136
145
|
|
146
|
+
# @param [Hash] params
|
137
147
|
# @return [JSON || nil]
|
138
|
-
def guild_raids
|
139
|
-
|
148
|
+
def guild_raids(params = {})
|
149
|
+
data_collection_request(SWGOH::API::COLLECTION::GUILD_RAID, params)
|
140
150
|
end
|
141
151
|
|
152
|
+
# @param [Hash] params
|
142
153
|
# @return [JSON || nil]
|
143
|
-
def help_entries
|
144
|
-
|
154
|
+
def help_entries(params = {})
|
155
|
+
data_collection_request(SWGOH::API::COLLECTION::HELP_ENTRY, params)
|
145
156
|
end
|
146
157
|
|
158
|
+
# @param [Hash] params
|
147
159
|
# @return [JSON || nil]
|
148
|
-
def materials
|
149
|
-
|
160
|
+
def materials(params = {})
|
161
|
+
data_collection_request(SWGOH::API::COLLECTION::MATERIAL, params)
|
150
162
|
end
|
151
163
|
|
164
|
+
# @param [Hash] params
|
152
165
|
# @return [JSON || nil]
|
153
|
-
def player_titles
|
154
|
-
|
166
|
+
def player_titles(params = {})
|
167
|
+
data_collection_request(SWGOH::API::COLLECTION::PLAYER_TITLE, params)
|
155
168
|
end
|
156
169
|
|
170
|
+
# @param [Hash] params
|
157
171
|
# @return [JSON || nil]
|
158
|
-
def power_up_bundles
|
159
|
-
|
172
|
+
def power_up_bundles(params = {})
|
173
|
+
data_collection_request(SWGOH::API::COLLECTION::POWER_UP_BUNDLE, params)
|
160
174
|
end
|
161
175
|
|
176
|
+
# @param [Hash] params
|
162
177
|
# @return [JSON || nil]
|
163
|
-
def raid_configs
|
164
|
-
|
178
|
+
def raid_configs(params = {})
|
179
|
+
data_collection_request(SWGOH::API::COLLECTION::RAID_CONFIG, params)
|
165
180
|
end
|
166
181
|
|
182
|
+
# @param [Hash] params
|
167
183
|
# @return [JSON || nil]
|
168
|
-
def recipes
|
169
|
-
|
184
|
+
def recipes(params = {})
|
185
|
+
data_collection_request(SWGOH::API::COLLECTION::RECIPE, params)
|
170
186
|
end
|
171
187
|
|
188
|
+
# @param [Hash] params
|
172
189
|
# @return [JSON || nil]
|
173
|
-
def requirements
|
174
|
-
|
190
|
+
def requirements(params = {})
|
191
|
+
data_collection_request(SWGOH::API::COLLECTION::REQUIREMENT, params)
|
175
192
|
end
|
176
193
|
|
194
|
+
# @param [Hash] params
|
177
195
|
# @return [JSON || nil]
|
178
|
-
def skills
|
179
|
-
|
196
|
+
def skills(params = {})
|
197
|
+
data_collection_request(SWGOH::API::COLLECTION::SKILL, params)
|
180
198
|
end
|
181
199
|
|
200
|
+
# @param [Hash] params
|
182
201
|
# @return [JSON || nil]
|
183
|
-
def starter_guilds
|
184
|
-
|
202
|
+
def starter_guilds(params = {})
|
203
|
+
data_collection_request(SWGOH::API::COLLECTION::STARTER_GUILD, params)
|
185
204
|
end
|
186
205
|
|
206
|
+
# @param [Hash] params
|
187
207
|
# @return [JSON || nil]
|
188
|
-
def stat_mods
|
189
|
-
|
208
|
+
def stat_mods(params = {})
|
209
|
+
data_collection_request(SWGOH::API::COLLECTION::STAT_MOD, params)
|
190
210
|
end
|
191
211
|
|
212
|
+
# @param [Hash] params
|
192
213
|
# @return [JSON || nil]
|
193
|
-
def stat_mod_sets
|
194
|
-
|
214
|
+
def stat_mod_sets(params = {})
|
215
|
+
data_collection_request(SWGOH::API::COLLECTION::STAT_MOD_SET, params)
|
195
216
|
end
|
196
217
|
|
218
|
+
# @param [Hash] params
|
197
219
|
# @return [JSON || nil]
|
198
|
-
def stat_progressions
|
199
|
-
|
220
|
+
def stat_progressions(params = {})
|
221
|
+
data_collection_request(SWGOH::API::COLLECTION::STAT_PROGRESSION, params)
|
200
222
|
end
|
201
223
|
|
224
|
+
# @param [Hash] params
|
202
225
|
# @return [JSON || nil]
|
203
|
-
def tables
|
204
|
-
|
226
|
+
def tables(params = {})
|
227
|
+
data_collection_request(SWGOH::API::COLLECTION::TABLE, params)
|
205
228
|
end
|
206
229
|
|
230
|
+
# @param [Hash] params
|
207
231
|
# @return [JSON || nil]
|
208
|
-
def targeting_sets
|
209
|
-
|
232
|
+
def targeting_sets(params = {})
|
233
|
+
data_collection_request(SWGOH::API::COLLECTION::TARGETING_SET, params)
|
210
234
|
end
|
211
235
|
|
236
|
+
# @param [Hash] params
|
212
237
|
# @return [JSON || nil]
|
213
|
-
def territory_battle_definitions
|
214
|
-
|
238
|
+
def territory_battle_definitions(params = {})
|
239
|
+
data_collection_request(SWGOH::API::COLLECTION::TERRITORY_BATTLE_DEFINITION, params)
|
215
240
|
end
|
216
241
|
|
242
|
+
# @param [Hash] params
|
217
243
|
# @return [JSON || nil]
|
218
|
-
def territory_war_definitions
|
219
|
-
|
244
|
+
def territory_war_definitions(params = {})
|
245
|
+
data_collection_request(SWGOH::API::COLLECTION::TERRITORY_WAR_DEFINITION, params)
|
220
246
|
end
|
221
247
|
|
248
|
+
# @param [Hash] params
|
222
249
|
# @return [JSON || nil]
|
223
|
-
def units_list
|
224
|
-
|
250
|
+
def units_list(params = {})
|
251
|
+
data_collection_request(SWGOH::API::COLLECTION::UNIT, params)
|
225
252
|
end
|
226
253
|
|
254
|
+
# @param [Hash] params
|
227
255
|
# @return [JSON || nil]
|
228
|
-
def unlock_announcement_defs
|
229
|
-
|
256
|
+
def unlock_announcement_defs(params = {})
|
257
|
+
data_collection_request(SWGOH::API::COLLECTION::UNLOCK_ANNOUNCEMENT_DEFINITION, params)
|
230
258
|
end
|
231
259
|
|
260
|
+
# @param [Hash] params
|
232
261
|
# @return [JSON || nil]
|
233
|
-
def war_definitions
|
234
|
-
|
262
|
+
def war_definitions(params = {})
|
263
|
+
data_collection_request(SWGOH::API::COLLECTION::WAR_DEFINITION, params)
|
235
264
|
end
|
236
265
|
|
266
|
+
# @param [Hash] params
|
237
267
|
# @return [JSON || nil]
|
238
|
-
def xp_tables
|
239
|
-
|
268
|
+
def xp_tables(params = {})
|
269
|
+
data_collection_request(SWGOH::API::COLLECTION::XP_TABLE, params)
|
240
270
|
end
|
241
271
|
|
242
272
|
private
|
243
273
|
|
244
|
-
attr_reader :access_token
|
274
|
+
attr_reader :access_token, :requester
|
245
275
|
|
246
276
|
# @param [PATH] path
|
277
|
+
# @param [Hash] params
|
247
278
|
# @return [JSON || nil]
|
248
|
-
def request(path)
|
279
|
+
def request(path, params = {})
|
249
280
|
return unless authorized?
|
250
281
|
|
251
|
-
|
252
|
-
data = request_data
|
253
|
-
data[:project] = @project unless @project.nil?
|
254
|
-
response = Net::HTTP.post(uri, data.to_json, request_headers)
|
255
|
-
return log_error(response) unless response.is_a?(Net::HTTPSuccess)
|
256
|
-
|
257
|
-
JSON.parse(response.body)
|
282
|
+
@requester.request(@access_token, path, params)
|
258
283
|
end
|
259
284
|
|
260
285
|
# @param [PATH] path
|
261
286
|
# @param [Array] ally_codes
|
287
|
+
# @param [Hash] params
|
262
288
|
# @return [JSON || nil]
|
263
|
-
def ally_codes_request(path, ally_codes)
|
264
|
-
|
265
|
-
|
266
|
-
uri = URI("https://#{SWGOH::API::PATH::BASE}/#{path}")
|
267
|
-
data = request_data
|
268
|
-
data[:allyCodes] = ally_codes
|
269
|
-
data[:project] = @project unless @project.nil?
|
270
|
-
response = Net::HTTP.post(uri, data.to_json, request_headers)
|
271
|
-
return log_error(response) unless response.is_a?(Net::HTTPSuccess)
|
272
|
-
|
273
|
-
JSON.parse(response.body)
|
289
|
+
def ally_codes_request(path, ally_codes, params = {})
|
290
|
+
request(path, params.merge({ allyCodes: ally_codes }))
|
274
291
|
end
|
275
292
|
|
276
293
|
# @param [SWGOH::API::PATH::COLLECTION] collection
|
294
|
+
# @param [Hash] params
|
277
295
|
# @return [JSON || nil]
|
278
|
-
def
|
279
|
-
|
280
|
-
|
281
|
-
uri = URI("https://#{SWGOH::API::PATH::BASE}/#{SWGOH::API::PATH::DATA}")
|
282
|
-
data = request_data
|
283
|
-
data[:collection] = collection
|
284
|
-
data[:project] = @project unless @project.nil?
|
285
|
-
response = Net::HTTP.post(uri, data.to_json, request_headers)
|
286
|
-
return log_error(response) unless response.is_a?(Net::HTTPSuccess)
|
287
|
-
|
288
|
-
JSON.parse(response.body)
|
289
|
-
end
|
290
|
-
|
291
|
-
# @return [Hash]
|
292
|
-
def request_headers
|
293
|
-
{
|
294
|
-
Authorization: 'Bearer ' + @access_token,
|
295
|
-
'Content-Type': 'application/json;charset=utf-8'
|
296
|
-
}
|
297
|
-
end
|
298
|
-
|
299
|
-
# @param [String] username
|
300
|
-
# @param [String] password
|
301
|
-
# @return [Hash]
|
302
|
-
def auth_request_form(username, password)
|
303
|
-
{
|
304
|
-
username: username,
|
305
|
-
password: password,
|
306
|
-
grant_type: 'password',
|
307
|
-
client_id: 123,
|
308
|
-
client_secret: 'abc'
|
309
|
-
}
|
310
|
-
end
|
311
|
-
|
312
|
-
# @return [Hash]
|
313
|
-
def request_data
|
314
|
-
{
|
315
|
-
language: language,
|
316
|
-
enums: enums,
|
317
|
-
structure: structure
|
318
|
-
}
|
319
|
-
end
|
320
|
-
|
321
|
-
def log_error(result)
|
322
|
-
puts result.inspect
|
323
|
-
puts result.body if result.is_a?(Net::HTTPResponse)
|
296
|
+
def data_collection_request(collection, params = {})
|
297
|
+
request(SWGOH::API::PATH::DATA, params.merge({ collection: collection }))
|
324
298
|
end
|
325
299
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'SWGOH/API'
|
6
|
+
require 'SWGOH/API/CLIENT/LOG/log'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
# Makes requests for the client
|
10
|
+
class REQUESTER
|
11
|
+
attr_accessor :log
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@log = LOG.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] username
|
18
|
+
# @param [String] password
|
19
|
+
# @return [JSON || nil]
|
20
|
+
def auth_request(username, password)
|
21
|
+
response = Net::HTTP.post_form(uri(SWGOH::API::PATH::AUTH_SIGNIN), auth_request_form(username, password))
|
22
|
+
return @log.error(response) unless response.is_a?(Net::HTTPSuccess)
|
23
|
+
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [String] access_token
|
28
|
+
# @param [PATH] path
|
29
|
+
# @param [Hash] data
|
30
|
+
# @return [JSON || nil]
|
31
|
+
def request(access_token, path, data)
|
32
|
+
response = Net::HTTP.post(uri(path), default_data.merge(data).to_json, request_headers(access_token))
|
33
|
+
return @log.error(response) unless response.is_a?(Net::HTTPSuccess)
|
34
|
+
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# @return [Module<URI>]
|
41
|
+
def uri(path)
|
42
|
+
URI("https://#{SWGOH::API::PATH::BASE}/#{path}")
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [String] username
|
46
|
+
# @param [String] password
|
47
|
+
# @return [Hash]
|
48
|
+
def auth_request_form(username, password)
|
49
|
+
{
|
50
|
+
username: username,
|
51
|
+
password: password,
|
52
|
+
grant_type: 'password',
|
53
|
+
client_id: 123,
|
54
|
+
client_secret: 'abc'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Hash]
|
59
|
+
def request_headers(access_token)
|
60
|
+
{
|
61
|
+
Authorization: 'Bearer ' + access_token,
|
62
|
+
'Content-Type': 'application/json;charset=utf-8'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Hash]
|
67
|
+
def default_data
|
68
|
+
{
|
69
|
+
language: SWGOH::API::LANGUAGE::ENG_US,
|
70
|
+
enums: false,
|
71
|
+
structure: false
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
data/lib/SWGOH/API/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SWGOH-API
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Quass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A ruby gem client for api.swgoh.help
|
14
14
|
email:
|
@@ -29,7 +29,9 @@ files:
|
|
29
29
|
- SWGOH-API.gemspec
|
30
30
|
- bin/setup
|
31
31
|
- lib/SWGOH/API.rb
|
32
|
+
- lib/SWGOH/API/CLIENT/LOG/log.rb
|
32
33
|
- lib/SWGOH/API/CLIENT/client.rb
|
34
|
+
- lib/SWGOH/API/CLIENT/requester.rb
|
33
35
|
- lib/SWGOH/API/version.rb
|
34
36
|
homepage: https://github.com/jquass/SWGOH-API
|
35
37
|
licenses:
|