esi 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/esi.gemspec +1 -0
- data/lib/esi.rb +37 -32
- data/lib/esi/calls.rb +132 -73
- data/lib/esi/client.rb +59 -49
- data/lib/esi/o_auth.rb +9 -5
- data/lib/esi/response.rb +1 -0
- data/lib/esi/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cca478fd5427ecdcc25baebef64a0a6fd4f0f74
|
4
|
+
data.tar.gz: b61b8a1527217628dd0644b49668f31e0011ee79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e33ddf6dae4e6c65876e528cf4f7e4fe6b3fc5df725ba0660d4d9e50f8cdab47d45dc25c0d958281f4d75391d3029ada2ff2fb509aed49255dccc998af07e54
|
7
|
+
data.tar.gz: 45a8329ca80fa71af75a9406f6fddd66d27847f8a6fd0021740285ceca63feb8db09ed90f018c7c50057af8db36e7cb93c1a89278ea4d53998fdd2fa8798fed8
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
### You can optionally specify a callback that will be executed after a new token has been received using the refresh token
|
29
29
|
|
30
|
-
esi.refresh_callback =
|
30
|
+
esi.refresh_callback = -> (token, expires_at) {
|
31
31
|
# save new token & expires at
|
32
32
|
}
|
33
33
|
|
data/esi.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_dependency "oauth2", "~> 1.2"
|
21
21
|
spec.add_dependency "addressable", "~> 2.3"
|
22
22
|
spec.add_dependency "recursive-open-struct", "~> 1"
|
23
|
+
spec.add_dependency "activesupport"
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.14"
|
24
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
data/lib/esi.rb
CHANGED
@@ -2,6 +2,7 @@ require "oauth2"
|
|
2
2
|
require "forwardable"
|
3
3
|
require "ostruct"
|
4
4
|
require "addressable/uri"
|
5
|
+
require "active_support/notifications"
|
5
6
|
|
6
7
|
module Esi
|
7
8
|
autoload :Version, 'esi/version'
|
@@ -12,47 +13,51 @@ module Esi
|
|
12
13
|
autoload :Response, 'esi/response'
|
13
14
|
|
14
15
|
SCOPES = %w(
|
15
|
-
esi-
|
16
|
+
esi-assets.read_assets.v1
|
17
|
+
esi-bookmarks.read_character_bookmarks.v1
|
16
18
|
esi-calendar.read_calendar_events.v1
|
19
|
+
esi-calendar.respond_calendar_events.v1
|
20
|
+
esi-characters.read_agents_research.v1
|
21
|
+
esi-characters.read_blueprints.v1
|
22
|
+
esi-characters.read_chat_channels.v1
|
23
|
+
esi-characters.read_contacts.v1
|
24
|
+
esi-characters.read_corporation_roles.v1
|
25
|
+
esi-characters.read_fatigue.v1
|
26
|
+
esi-characters.read_loyalty.v1
|
27
|
+
esi-characters.read_medals.v1
|
28
|
+
esi-characters.read_opportunities.v1
|
29
|
+
esi-characters.read_standings.v1
|
30
|
+
esi-characters.write_contacts.v1
|
31
|
+
esi-clones.read_clones.v1
|
32
|
+
esi-clones.read_implants.v1
|
33
|
+
esi-contracts.read_character_contracts.v1
|
34
|
+
esi-corporations.read_corporation_membership.v1
|
35
|
+
esi-corporations.read_structures.v1
|
36
|
+
esi-corporations.track_members.v1
|
37
|
+
esi-corporations.write_structures.v1
|
38
|
+
esi-fittings.read_fittings.v1
|
39
|
+
esi-fittings.write_fittings.v1
|
40
|
+
esi-fleets.read_fleet.v1
|
41
|
+
esi-fleets.write_fleet.v1
|
42
|
+
esi-industry.read_character_jobs.v1
|
43
|
+
esi-killmails.read_killmails.v1
|
17
44
|
esi-location.read_location.v1
|
45
|
+
esi-location.read_online.v1
|
18
46
|
esi-location.read_ship_type.v1
|
19
47
|
esi-mail.organize_mail.v1
|
20
48
|
esi-mail.read_mail.v1
|
21
49
|
esi-mail.send_mail.v1
|
22
|
-
esi-
|
23
|
-
esi-
|
24
|
-
esi-wallet.read_character_wallet.v1
|
25
|
-
esi-search.search_structures.v1
|
26
|
-
esi-clones.read_clones.v1
|
27
|
-
esi-characters.read_contacts.v1
|
28
|
-
esi-universe.read_structures.v1
|
29
|
-
esi-bookmarks.read_character_bookmarks.v1
|
30
|
-
esi-killmails.read_killmails.v1
|
31
|
-
esi-corporations.read_corporation_membership.v1
|
32
|
-
esi-assets.read_assets.v1
|
50
|
+
esi-markets.read_character_orders.v1
|
51
|
+
esi-markets.structure_markets.v1
|
33
52
|
esi-planets.manage_planets.v1
|
34
|
-
esi-
|
35
|
-
esi-
|
53
|
+
esi-search.search_structures.v1
|
54
|
+
esi-skills.read_skillqueue.v1
|
55
|
+
esi-skills.read_skills.v1
|
36
56
|
esi-ui.open_window.v1
|
37
57
|
esi-ui.write_waypoint.v1
|
38
|
-
esi-
|
39
|
-
esi-
|
40
|
-
esi-
|
41
|
-
esi-markets.structure_markets.v1
|
42
|
-
esi-corporations.read_structures.v1
|
43
|
-
esi-corporations.write_structures.v1
|
44
|
-
esi-characters.read_loyalty.v1
|
45
|
-
esi-characters.read_opportunities.v1
|
46
|
-
esi-characters.read_chat_channels.v1
|
47
|
-
esi-characters.read_medals.v1
|
48
|
-
esi-characters.read_standings.v1
|
49
|
-
esi-characters.read_agents_research.v1
|
50
|
-
esi-industry.read_character_jobs.v1
|
51
|
-
esi-markets.read_character_orders.v1
|
52
|
-
esi-characters.read_blueprints.v1
|
53
|
-
esi-characters.read_corporation_roles.v1
|
54
|
-
esi-location.read_online.v1
|
55
|
-
esi-contracts.read_character_contracts.v1
|
58
|
+
esi-universe.read_structures.v1
|
59
|
+
esi-wallet.read_character_wallet.v1
|
60
|
+
esi-wallet.read_corporation_wallets.v1
|
56
61
|
)
|
57
62
|
DEFAULT_CONFIG = {
|
58
63
|
datasource: :tranquility,
|
data/lib/esi/calls.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Esi
|
2
2
|
class Calls
|
3
3
|
class Base
|
4
|
+
class_attribute :scope
|
5
|
+
class_attribute :cache_duration
|
4
6
|
attr_accessor :path, :params
|
5
7
|
|
6
8
|
def method
|
@@ -21,14 +23,6 @@ module Esi
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
class OpenMarketDetails < Base
|
25
|
-
def initialize(type_id)
|
26
|
-
@path = "/ui/openwindow/marketdetails"
|
27
|
-
@method = :post
|
28
|
-
@params = { type_id: type_id }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
26
|
class SolarSystem < Base
|
33
27
|
def initialize(system_id)
|
34
28
|
@path = "/universe/systems/#{system_id}"
|
@@ -55,126 +49,164 @@ module Esi
|
|
55
49
|
end
|
56
50
|
end
|
57
51
|
|
58
|
-
class
|
59
|
-
def initialize(
|
60
|
-
@path = "/
|
61
|
-
@
|
52
|
+
class StructureOrders < Base
|
53
|
+
def initialize(structure_id:)
|
54
|
+
@path = "/markets/structures/#{structure_id}"
|
55
|
+
@paginated = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class MarketHistory < Base
|
60
|
+
def initialize(type_id:, region_id: Region::FORGE)
|
61
|
+
@path = "/markets/#{region_id}/history"
|
62
|
+
@params = { type_id: type_id }
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
66
|
class CharacterNames < Base
|
67
|
+
self.cache_duration = 3600
|
68
|
+
|
66
69
|
def initialize(character_ids)
|
67
70
|
@path = "/characters/names"
|
68
71
|
@params = { character_ids: character_ids.join(',') }
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
# Link: https://esi.tech.ccp.is/latest/#!/Character/get_characters_character_id
|
73
|
-
# Cache: 1 hour
|
74
75
|
class Character < Base
|
76
|
+
self.cache_duration = 3600
|
77
|
+
|
75
78
|
def initialize(character_id)
|
76
79
|
@path = "/characters/#{character_id}"
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
80
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Wallet/get_characters_character_id_wallet
|
81
|
-
# Scope: esi-wallet.read_character_wallet.v1
|
82
83
|
# Cache: 2 minutes
|
83
84
|
class CharacterWallet < Base
|
85
|
+
self.scope = 'esi-wallet.read_character_wallet.v1'
|
86
|
+
self.cache_duration = 120
|
87
|
+
|
84
88
|
def initialize(character_id)
|
85
89
|
@path = "/characters/#{character_id}/wallet"
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
89
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Wallet/get_characters_character_id_wallet_journal
|
90
|
-
# Scope: esi-wallet.read_character_wallet.v1
|
91
|
-
# Cache: 1 hour
|
92
93
|
class CharacterWalletJournal < Base
|
94
|
+
self.scope = 'esi-wallet.read_character_wallet.v1'
|
95
|
+
self.cache_duration = 3600
|
96
|
+
|
93
97
|
def initialize(character_id)
|
94
98
|
@path = "/characters/#{character_id}/wallet/journal"
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
98
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Wallet/get_characters_character_id_wallet_transactions
|
99
|
-
# Scope: esi-wallet.read_character_wallet.v1
|
100
|
-
# Cache: 1 hour
|
101
102
|
class CharacterWalletTransactions < Base
|
103
|
+
self.scope = 'esi-wallet.read_character_wallet.v1'
|
104
|
+
self.cache_duration = 3600
|
105
|
+
|
102
106
|
def initialize(character_id)
|
103
107
|
@path = "/characters/#{character_id}/wallet/transactions"
|
104
108
|
end
|
105
109
|
end
|
106
110
|
|
107
|
-
# Link: https://esi.tech.ccp.is/latest/#!/Market/get_characters_character_id_orders
|
108
|
-
# Scope: esi-markets.read_character_orders.v1
|
109
|
-
# Cache: 1 hour
|
110
111
|
class CharacterOrders < Base
|
112
|
+
self.scope = 'esi-markets.read_character_orders.v1'
|
113
|
+
self.cache_duration = 3600
|
114
|
+
|
111
115
|
def initialize(character_id)
|
112
116
|
@path = "/characters/#{character_id}/orders"
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
116
|
-
# Link: https://esi.tech.ccp.is/latest/#!/Industry/get_characters_character_id_industry_jobs
|
117
|
-
# Scope: esi-industry.read_character_jobs.v1
|
118
|
-
# Cache: 5 minutes
|
119
120
|
class CharacterIndustryJobs < Base
|
121
|
+
self.scope = 'esi-industry.read_character_jobs.v1'
|
122
|
+
self.cache_duration = 300
|
123
|
+
|
120
124
|
def initialize(character_id, with_completed: false)
|
121
125
|
@path = "/characters/#{character_id}/industry/jobs"
|
122
126
|
@params = { with_completed: with_completed }
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
|
-
# Link: https://esi.tech.ccp.is/dev/?datasource=tranquility#!/Contacts/get_characters_character_id_contacts
|
127
|
-
# Scope: esi-contracts.read_character_contracts.v1
|
128
|
-
# Cache: 1 hour
|
129
130
|
class CharacterContracts < Base
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
131
|
+
self.scope = 'esi-contracts.read_character_contracts.v1'
|
132
|
+
self.cache_duration = 3600
|
134
133
|
|
135
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Location/get_characters_character_id_location
|
136
|
-
# Scope: esi-location.read_location.v1
|
137
|
-
# Cache: 1 hour
|
138
|
-
class CharacterLocation < Base
|
139
134
|
def initialize(character_id)
|
140
|
-
@path = "/characters/#{character_id}/
|
135
|
+
@path = "/characters/#{character_id}/contracts"
|
141
136
|
end
|
142
137
|
end
|
143
138
|
|
144
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Contracts/get_characters_character_id_contracts_contract_id_items
|
145
|
-
# Scope: esi-contracts.read_character_contracts.v1
|
146
|
-
# Cache: 1 hour
|
147
139
|
class ContractItems < Base
|
140
|
+
self.scope = 'esi-contracts.read_character_contracts.v1'
|
141
|
+
self.cache_duration = 3600
|
142
|
+
|
148
143
|
def initialize(character_id, contract_id)
|
149
144
|
@path = "/characters/#{character_id}/contracts/#{contract_id}/items"
|
150
145
|
end
|
151
146
|
end
|
152
147
|
|
153
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Location/get_characters_character_id_location
|
154
|
-
# Scope: esi-location.read_location.v1
|
155
|
-
# Cache: 5 seconds
|
156
148
|
class CharacterLocation < Base
|
149
|
+
self.scope = 'esi-location.read_location.v1'
|
150
|
+
self.cache_duration = 5
|
151
|
+
|
157
152
|
def initialize(character_id)
|
158
153
|
@path = "/characters/#{character_id}/location"
|
159
154
|
end
|
160
155
|
end
|
161
156
|
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
157
|
+
# characters/{character_id}/online
|
158
|
+
# esi-location.read_online.v1
|
159
|
+
# 60
|
160
|
+
|
161
|
+
# /characters/{character_id}/attributes
|
162
|
+
# esi-skills.read_skills.v1
|
163
|
+
# 3600
|
164
|
+
|
165
|
+
# /characters/{character_id}/chat_channels
|
166
|
+
# esi-characters.read_chat_channels.v1
|
167
|
+
# 300
|
168
|
+
|
169
|
+
# /characters/{character_id}/clones
|
170
|
+
# esi-clones.read_clones.v1
|
171
|
+
# 120
|
172
|
+
|
173
|
+
# /characters/{character_id}/implants
|
174
|
+
# esi-clones.read_implants.v1
|
175
|
+
# 3600
|
176
|
+
|
177
|
+
# /characters/{character_id}/roles
|
178
|
+
# esi-characters.read_corporation_roles.v1
|
179
|
+
# 3600
|
180
|
+
|
181
|
+
class CharacterMail < Base
|
182
|
+
self.scope = 'esi-mail.read_mail.v1'
|
183
|
+
self.cache_duration = 30
|
184
|
+
|
185
|
+
def initialize(character_id)
|
186
|
+
@path = "/characters/#{character_id}/mail"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
165
190
|
class Assets < Base
|
191
|
+
self.scope = 'esi-assets.read_assets.v1'
|
192
|
+
self.cache_duration = 3600
|
193
|
+
|
166
194
|
def initialize(character_id)
|
167
195
|
@path = "/characters/#{character_id}/assets"
|
168
196
|
end
|
169
197
|
end
|
170
198
|
|
171
199
|
class Alliances < Base
|
200
|
+
self.cache_duration = 3600
|
201
|
+
|
172
202
|
def initialize
|
173
203
|
@path = "/alliances"
|
174
204
|
end
|
175
205
|
end
|
176
206
|
|
177
207
|
class AllianceNames < Base
|
208
|
+
self.cache_duration = 3600
|
209
|
+
|
178
210
|
def initialize(alliance_ids)
|
179
211
|
@path = "/alliances/names"
|
180
212
|
@params = { alliance_ids: alliance_ids.join(',') }
|
@@ -182,12 +214,16 @@ module Esi
|
|
182
214
|
end
|
183
215
|
|
184
216
|
class Alliance < Base
|
217
|
+
self.cache_duration = 3600
|
218
|
+
|
185
219
|
def initialize(alliance_id)
|
186
220
|
@path = "/alliances/#{alliance_id}"
|
187
221
|
end
|
188
222
|
end
|
189
223
|
|
190
224
|
class CorporationNames < Base
|
225
|
+
self.cache_duration = 3600
|
226
|
+
|
191
227
|
def initialize(corporation_ids)
|
192
228
|
@path = "/corporations/names"
|
193
229
|
@params = { corporation_ids: corporation_ids.join(',') }
|
@@ -195,41 +231,64 @@ module Esi
|
|
195
231
|
end
|
196
232
|
|
197
233
|
class Corporation < Base
|
234
|
+
self.cache_duration = 3600
|
235
|
+
|
198
236
|
def initialize(corporation_id)
|
199
237
|
@path = "/corporations/#{corporation_id}"
|
200
238
|
end
|
201
239
|
end
|
202
240
|
|
203
|
-
class
|
241
|
+
class CorporationWallet < Base
|
242
|
+
self.scope = 'esi-wallet.read_corporation_wallet.v1'
|
243
|
+
self.cache_duration = 120
|
244
|
+
|
204
245
|
def initialize(corporation_id)
|
205
|
-
@path = "/corporations/#{corporation_id}/
|
246
|
+
@path = "/corporations/#{corporation_id}/wallets"
|
206
247
|
end
|
207
248
|
end
|
208
249
|
|
209
|
-
class
|
210
|
-
|
211
|
-
|
250
|
+
class CorporationStructures < Base
|
251
|
+
self.scope = 'esi-corporations.read_structures.v1'
|
252
|
+
self.cache_duration = 3600
|
253
|
+
|
254
|
+
def initialize(corporation_id)
|
255
|
+
@path = "/corporations/#{corporation_id}/structures"
|
212
256
|
end
|
213
257
|
end
|
214
258
|
|
215
|
-
# Link: https://esi.tech.ccp.is/dev/#!/Corporation/get_corporations_corporation_id_members
|
216
|
-
# Scope: esi-corporations.read_corporation_membership.v1
|
217
|
-
# Cache: 1 hour
|
218
259
|
class CorporationMembers < Base
|
260
|
+
self.scope = 'esi-corporations.read_corporation_membership.v1'
|
261
|
+
self.cache_duration = 3600
|
262
|
+
|
219
263
|
def initialize(corporation_id)
|
220
264
|
@path = "/corporations/#{corporation_id}/members"
|
221
265
|
end
|
222
266
|
end
|
223
267
|
|
268
|
+
class CorporationMemberTracking < Base
|
269
|
+
self.scope = 'esi-corporations.track_members.v1'
|
270
|
+
self.cache_duration = 3600
|
271
|
+
|
272
|
+
def initialize(corporation_id)
|
273
|
+
@path = "/corporations/#{corporation_id}/membertracking"
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
224
277
|
# Link: https://esi.tech.ccp.is/dev/#!/Corporation/get_corporations_corporation_id_roles
|
225
|
-
# Scope: esi-corporations.read_corporation_membership.v1
|
226
|
-
# Cache: 1 hour
|
227
278
|
class CorporationRoles < Base
|
279
|
+
self.scope = 'esi-corporations.read_corporation_membership.v1'
|
280
|
+
self.cache_duration = 3600
|
281
|
+
|
228
282
|
def initialize(corporation_id)
|
229
283
|
@path = "/corporations/#{corporation_id}/roles"
|
230
284
|
end
|
231
285
|
end
|
232
286
|
|
287
|
+
class CorporationWallets < Base
|
288
|
+
self.scope = 'esi-wallet.read_corporation_wallets.v1'
|
289
|
+
self.cache_duration = 300
|
290
|
+
end
|
291
|
+
|
233
292
|
class Structures < Base
|
234
293
|
def initialize
|
235
294
|
@path = "/universe/structures"
|
@@ -277,21 +336,9 @@ module Esi
|
|
277
336
|
end
|
278
337
|
end
|
279
338
|
|
280
|
-
class StructureOrders < Base
|
281
|
-
def initialize(structure_id:)
|
282
|
-
@path = "/markets/structures/#{structure_id}"
|
283
|
-
@paginated = true
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
class MarketHistory < Base
|
288
|
-
def initialize(type_id:, region_id: Region::FORGE)
|
289
|
-
@path = "/markets/#{region_id}/history"
|
290
|
-
@params = { type_id: type_id }
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
339
|
class Killmails < Base
|
340
|
+
self.scope = 'esi-killmails.read_killmails.v1'
|
341
|
+
|
295
342
|
def initialize(character_id:, max_count: 50, max_kill_id: nil)
|
296
343
|
@path = "/characters/#{character_id}/killmails/recent"
|
297
344
|
@params = { max_count: max_count }
|
@@ -324,6 +371,8 @@ module Esi
|
|
324
371
|
end
|
325
372
|
|
326
373
|
class Fittings < Base
|
374
|
+
self.scope = 'esi-fittings.read_fittings.v1'
|
375
|
+
|
327
376
|
def initialize(character_id)
|
328
377
|
@path = "characters/#{character_id}/fittings"
|
329
378
|
end
|
@@ -335,5 +384,15 @@ module Esi
|
|
335
384
|
@method = :delete
|
336
385
|
end
|
337
386
|
end
|
387
|
+
|
388
|
+
class OpenMarketDetails < Base
|
389
|
+
self.scope = 'esi-ui.open_window.v1'
|
390
|
+
|
391
|
+
def initialize(type_id)
|
392
|
+
@path = "/ui/openwindow/marketdetails"
|
393
|
+
@method = :post
|
394
|
+
@params = { type_id: type_id }
|
395
|
+
end
|
396
|
+
end
|
338
397
|
end
|
339
398
|
end
|
data/lib/esi/client.rb
CHANGED
@@ -13,11 +13,14 @@ module Esi
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(name, *args, &block)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
klass = nil
|
17
|
+
ActiveSupport::Notifications.instrument('esi.client.detect_call') do
|
18
|
+
class_name = name.to_s.split('_').map(&:capitalize).join
|
19
|
+
begin
|
20
|
+
klass = Esi::Calls.const_get(class_name)
|
21
|
+
rescue NameError
|
22
|
+
super(name, *args, &block)
|
23
|
+
end
|
21
24
|
end
|
22
25
|
|
23
26
|
call = klass.new(*args)
|
@@ -53,12 +56,14 @@ module Esi
|
|
53
56
|
items = []
|
54
57
|
page = 1
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
ActiveSupport::Notifications.instrument('esi.client.request.paginated') do
|
60
|
+
loop do
|
61
|
+
call.page = page
|
62
|
+
response = request(call, &block)
|
63
|
+
break if response.data.blank?
|
64
|
+
items += response.data
|
65
|
+
page += 1
|
66
|
+
end
|
62
67
|
end
|
63
68
|
|
64
69
|
items
|
@@ -67,54 +72,59 @@ module Esi
|
|
67
72
|
def request(call, url=nil, &block)
|
68
73
|
response = nil
|
69
74
|
url ||= call.url
|
70
|
-
|
71
75
|
debug "Starting request: #{url}"
|
72
76
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
response = Response.new(e.response)
|
94
|
-
logger.error "ApiUnknownError (#{response.status}): #{url}"
|
95
|
-
|
96
|
-
case response.error
|
97
|
-
when 'invalid_client' then
|
98
|
-
raise ApiInvalidAppClientKeysError.new(response)
|
77
|
+
ActiveSupport::Notifications.instrument('esi.client.request') do
|
78
|
+
1.upto(MAX_ATTEMPTS) do |try|
|
79
|
+
begin
|
80
|
+
response = oauth.request(call.method, url)
|
81
|
+
rescue OAuth2::Error => e
|
82
|
+
case e.response.status
|
83
|
+
when 502 # Temporary server error
|
84
|
+
logger.error "TemporaryServerError, sleeping for 15 seconds"
|
85
|
+
sleep 15
|
86
|
+
next
|
87
|
+
when 503 # Rate Limit
|
88
|
+
logger.error "RateLimit error, sleeping for 15 seconds"
|
89
|
+
sleep 15
|
90
|
+
next
|
91
|
+
when 403 # Forbidden
|
92
|
+
logger.error "ApiForbiddenError: #{e.response.status}: #{e.response.body}"
|
93
|
+
logger.error url
|
94
|
+
raise Esi::ApiForbiddenError.new(Response.new(e.response))
|
95
|
+
when 404 # Not Found
|
96
|
+
raise Esi::ApiNotFoundError.new(Response.new(e.response))
|
99
97
|
else
|
100
|
-
|
98
|
+
response = Response.new(e.response)
|
99
|
+
logger.error "ApiUnknownError (#{response.status}): #{url}"
|
100
|
+
|
101
|
+
case response.error
|
102
|
+
when 'invalid_client' then
|
103
|
+
raise ApiInvalidAppClientKeysError.new(response)
|
104
|
+
else
|
105
|
+
raise Esi::ApiUnknownError.new(response)
|
106
|
+
end
|
101
107
|
end
|
102
108
|
end
|
109
|
+
break if response
|
103
110
|
end
|
104
|
-
break if response
|
105
111
|
end
|
106
112
|
|
107
113
|
debug "Request finished"
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
114
|
+
ActiveSupport::Notifications.instrument('esi.client.response.initialize') do
|
115
|
+
response = Response.new(response)
|
116
|
+
end
|
117
|
+
ActiveSupport::Notifications.instrument('esi.client.response.save') do
|
118
|
+
if Esi.config.response_log_path && Dir.exists?(Esi.config.response_log_path)
|
119
|
+
call_name = call.class.to_s.downcase.split('::').last
|
120
|
+
folder = Pathname.new(Esi.config.response_log_path).join(call_name)
|
121
|
+
FileUtils.mkdir_p(folder)
|
122
|
+
File.write(folder.join("#{Time.now.to_i.to_s}.json"), response.to_s)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
ActiveSupport::Notifications.instrument('esi.client.response.classify') do
|
126
|
+
response.data.each { |item| block.call(item) } if block
|
115
127
|
end
|
116
|
-
|
117
|
-
response.data.each { |item| block.call(item) } if block
|
118
128
|
response
|
119
129
|
end
|
120
130
|
end
|
data/lib/esi/o_auth.rb
CHANGED
@@ -12,7 +12,9 @@ module Esi
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def obtain_token(code)
|
15
|
-
|
15
|
+
ActiveSupport::Notifications.instrument('esi.oauth.obtain_token') do
|
16
|
+
Esi::AccessToken.new(client.auth_code.get_token(code))
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def client
|
@@ -45,10 +47,12 @@ module Esi
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def refresh_access_token
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
ActiveSupport::Notifications.instrument('esi.oauth.refresh_token') do
|
51
|
+
@token = @token.refresh!
|
52
|
+
@access_token = @token.token
|
53
|
+
@expires_at = @token.expires_at.integer? ? Time.at(@token.expires_at) : @token.expires_at
|
54
|
+
@callback.call(@access_token, @expires_at) if @callback
|
55
|
+
end
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
data/lib/esi/response.rb
CHANGED
data/lib/esi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Hiemstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
147
|
version: '0'
|
134
148
|
requirements: []
|
135
149
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.5.2
|
137
151
|
signing_key:
|
138
152
|
specification_version: 4
|
139
153
|
summary: EVE ESI API wrapper
|