eve_online 0.35.1 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +12 -24
- data/.fasterer.yml +2 -0
- data/.ruby-version +1 -1
- data/.standard.yml +5 -0
- data/Appraisals +8 -2
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +92 -70
- data/LICENSE.txt +1 -1
- data/README.md +43 -16
- data/eve_online.gemspec +5 -3
- data/lib/eve_online.rb +224 -221
- data/lib/eve_online/esi/alliance.rb +1 -1
- data/lib/eve_online/esi/alliance_icon.rb +1 -1
- data/lib/eve_online/esi/base.rb +54 -86
- data/lib/eve_online/esi/character_assets_locations.rb +1 -1
- data/lib/eve_online/esi/character_assets_names.rb +1 -1
- data/lib/eve_online/esi/character_corporation_history.rb +1 -1
- data/lib/eve_online/esi/corporation_assets_locations.rb +1 -1
- data/lib/eve_online/esi/corporation_assets_names.rb +1 -1
- data/lib/eve_online/esi/corporation_members.rb +29 -0
- data/lib/eve_online/esi/faraday_middlewares/raise_errors.rb +40 -0
- data/lib/eve_online/formulas/training_rate.rb +18 -0
- data/lib/eve_online/version.rb +1 -1
- metadata +38 -9
- data/Gemfile.mutant +0 -10
- data/Gemfile.mutant.lock +0 -155
- data/TODO.md +0 -7
- data/mutant.sh +0 -4
data/lib/eve_online/esi/base.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "json"
|
3
|
+
require "faraday"
|
4
|
+
require "faraday_middleware"
|
6
5
|
require "active_support/time"
|
7
6
|
|
8
7
|
module EveOnline
|
@@ -10,23 +9,20 @@ module EveOnline
|
|
10
9
|
class Base
|
11
10
|
API_HOST = "esi.evetech.net"
|
12
11
|
|
13
|
-
attr_reader :token, :
|
14
|
-
:language
|
12
|
+
attr_reader :token, :_read_timeout, :_open_timeout, :_write_timeout,
|
13
|
+
:_etag, :language, :adapter, :middlewares
|
15
14
|
|
16
|
-
|
17
|
-
attr_reader :_write_timeout
|
18
|
-
end
|
15
|
+
attr_writer :token
|
19
16
|
|
20
17
|
def initialize(options = {})
|
21
18
|
@token = options.fetch(:token, nil)
|
22
|
-
@parser = options.fetch(:parser, JSON)
|
23
19
|
@_read_timeout = options.fetch(:read_timeout, 60)
|
24
20
|
@_open_timeout = options.fetch(:open_timeout, 60)
|
25
|
-
|
26
|
-
@_write_timeout = options.fetch(:write_timeout, 60)
|
27
|
-
end
|
21
|
+
@_write_timeout = options.fetch(:write_timeout, 60)
|
28
22
|
@_etag = options.fetch(:etag, nil)
|
29
23
|
@language = options.fetch(:language, "en-us")
|
24
|
+
@adapter = options.fetch(:adapter, Faraday.default_adapter)
|
25
|
+
@middlewares = options.fetch(:middlewares, [])
|
30
26
|
end
|
31
27
|
|
32
28
|
def url
|
@@ -42,33 +38,31 @@ module EveOnline
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def http_method
|
45
|
-
|
41
|
+
:get
|
46
42
|
end
|
47
43
|
|
48
44
|
def read_timeout
|
49
|
-
|
45
|
+
connection.options.read_timeout
|
50
46
|
end
|
51
47
|
|
52
48
|
def read_timeout=(value)
|
53
|
-
|
49
|
+
connection.options.read_timeout = value
|
54
50
|
end
|
55
51
|
|
56
52
|
def open_timeout
|
57
|
-
|
53
|
+
connection.options.open_timeout
|
58
54
|
end
|
59
55
|
|
60
56
|
def open_timeout=(value)
|
61
|
-
|
57
|
+
connection.options.open_timeout = value
|
62
58
|
end
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
60
|
+
def write_timeout
|
61
|
+
connection.options.write_timeout
|
62
|
+
end
|
68
63
|
|
69
|
-
|
70
|
-
|
71
|
-
end
|
64
|
+
def write_timeout=(value)
|
65
|
+
connection.options.write_timeout = value
|
72
66
|
end
|
73
67
|
|
74
68
|
def etag=(value)
|
@@ -76,56 +70,54 @@ module EveOnline
|
|
76
70
|
end
|
77
71
|
|
78
72
|
def etag
|
79
|
-
resource.
|
73
|
+
resource.headers["etag"]&.gsub("W/", "")&.gsub('"', "")
|
80
74
|
end
|
81
75
|
|
82
76
|
def page
|
83
77
|
end
|
84
78
|
|
85
79
|
def total_pages
|
86
|
-
resource.
|
80
|
+
resource.headers["x-pages"]&.to_i
|
87
81
|
end
|
88
82
|
|
89
83
|
def error_limit_remain
|
90
|
-
resource.
|
84
|
+
resource.headers["x-esi-error-limit-remain"]&.to_i
|
91
85
|
end
|
92
86
|
|
93
87
|
def error_limit_reset
|
94
|
-
resource.
|
88
|
+
resource.headers["x-esi-error-limit-reset"]&.to_i
|
95
89
|
end
|
96
90
|
|
97
|
-
def
|
98
|
-
|
99
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
100
|
-
http.read_timeout = _read_timeout
|
101
|
-
http.open_timeout = _open_timeout
|
102
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
|
103
|
-
http.write_timeout = _write_timeout
|
104
|
-
end
|
105
|
-
http.use_ssl = true
|
106
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
107
|
-
# http.set_debug_output($stdout)
|
108
|
-
http
|
109
|
-
end
|
91
|
+
def request_id
|
92
|
+
resource.headers["x-esi-request-id"]
|
110
93
|
end
|
111
94
|
|
112
|
-
def
|
113
|
-
@
|
114
|
-
request = "Net::HTTP::#{http_method}".constantize.new(uri.request_uri)
|
115
|
-
|
116
|
-
request["User-Agent"] = user_agent
|
117
|
-
request["Accept"] = "application/json"
|
118
|
-
request["Authorization"] = "Bearer #{token}" if token
|
119
|
-
request["If-None-Match"] = _etag if _etag
|
120
|
-
request["Content-Type"] = "application/json" if http_method == "Post"
|
121
|
-
request.body = payload if http_method == "Post"
|
122
|
-
|
123
|
-
request
|
124
|
-
end
|
95
|
+
def add_middleware(middleware)
|
96
|
+
@middlewares << middleware
|
125
97
|
end
|
126
98
|
|
127
|
-
|
128
|
-
|
99
|
+
def connection
|
100
|
+
@connection ||= Faraday.new do |f|
|
101
|
+
f.headers["User-Agent"] = user_agent
|
102
|
+
f.headers["If-None-Match"] = _etag if _etag
|
103
|
+
f.headers["Accept"] = "application/json"
|
104
|
+
f.authorization :Bearer, token if token
|
105
|
+
f.options.read_timeout = _read_timeout
|
106
|
+
f.options.open_timeout = _open_timeout
|
107
|
+
f.options.write_timeout = _write_timeout
|
108
|
+
f.use FaradayMiddlewares::RaiseErrors
|
109
|
+
middlewares.each do |middleware|
|
110
|
+
if middleware[:esi].present?
|
111
|
+
f.use middleware[:class], esi: middleware[:esi]
|
112
|
+
else
|
113
|
+
f.use middleware[:class]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
# f.use Faraday::Response::Logger
|
117
|
+
# f.use FaradayMiddleware::FollowRedirects, limit: 5
|
118
|
+
f.response :json, content_type: "application/json"
|
119
|
+
f.adapter adapter
|
120
|
+
end
|
129
121
|
end
|
130
122
|
|
131
123
|
def uri
|
@@ -159,49 +151,25 @@ module EveOnline
|
|
159
151
|
end
|
160
152
|
|
161
153
|
def resource
|
162
|
-
@resource ||=
|
163
|
-
rescue
|
154
|
+
@resource ||= connection.public_send(http_method, uri)
|
155
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
164
156
|
raise EveOnline::Exceptions::Timeout
|
165
157
|
end
|
166
158
|
|
167
159
|
def not_modified?
|
168
|
-
resource.
|
160
|
+
resource.status == 304
|
169
161
|
end
|
170
162
|
|
171
163
|
def content
|
172
|
-
|
173
|
-
when Net::HTTPOK
|
174
|
-
# TODO: memoize resource.body as @content
|
175
|
-
resource.body
|
176
|
-
when Net::HTTPCreated
|
177
|
-
# TODO: write
|
178
|
-
raise NotImplementedError
|
179
|
-
when Net::HTTPNoContent
|
180
|
-
raise EveOnline::Exceptions::NoContent
|
181
|
-
when Net::HTTPNotModified
|
164
|
+
if not_modified?
|
182
165
|
raise EveOnline::Exceptions::NotModified
|
183
|
-
when Net::HTTPBadRequest
|
184
|
-
raise EveOnline::Exceptions::BadRequest
|
185
|
-
when Net::HTTPUnauthorized
|
186
|
-
raise EveOnline::Exceptions::Unauthorized
|
187
|
-
when Net::HTTPForbidden
|
188
|
-
raise EveOnline::Exceptions::Forbidden
|
189
|
-
when Net::HTTPNotFound
|
190
|
-
raise EveOnline::Exceptions::ResourceNotFound
|
191
|
-
when Net::HTTPInternalServerError
|
192
|
-
raise EveOnline::Exceptions::InternalServerError
|
193
|
-
when Net::HTTPBadGateway
|
194
|
-
raise EveOnline::Exceptions::BadGateway
|
195
|
-
when Net::HTTPServiceUnavailable
|
196
|
-
raise EveOnline::Exceptions::ServiceUnavailable
|
197
166
|
else
|
198
|
-
|
199
|
-
raise NotImplementedError
|
167
|
+
resource.body
|
200
168
|
end
|
201
169
|
end
|
202
170
|
|
203
171
|
def response
|
204
|
-
@response ||=
|
172
|
+
@response ||= content
|
205
173
|
end
|
206
174
|
|
207
175
|
private
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EveOnline
|
4
|
+
module ESI
|
5
|
+
class CorporationMembers < Base
|
6
|
+
API_PATH = "/v3/corporations/%<corporation_id>s/members/"
|
7
|
+
|
8
|
+
attr_reader :corporation_id
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
|
13
|
+
@corporation_id = options.fetch(:corporation_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def character_ids
|
17
|
+
response
|
18
|
+
end
|
19
|
+
|
20
|
+
def scope
|
21
|
+
"esi-corporations.read_corporation_membership.v1"
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
format(API_PATH, corporation_id: corporation_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
module EveOnline
|
6
|
+
module ESI
|
7
|
+
module FaradayMiddlewares
|
8
|
+
class RaiseErrors < Faraday::Middleware
|
9
|
+
def call(env)
|
10
|
+
@app.call(env).on_complete do |environment|
|
11
|
+
on_complete(environment)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_complete(env)
|
16
|
+
case env[:status]
|
17
|
+
when 204
|
18
|
+
raise EveOnline::Exceptions::NoContent
|
19
|
+
when 400
|
20
|
+
raise EveOnline::Exceptions::BadRequest
|
21
|
+
when 401
|
22
|
+
raise EveOnline::Exceptions::Unauthorized
|
23
|
+
when 403
|
24
|
+
raise EveOnline::Exceptions::Forbidden
|
25
|
+
when 404
|
26
|
+
raise EveOnline::Exceptions::ResourceNotFound
|
27
|
+
when 420
|
28
|
+
raise EveOnline::Exceptions::ErrorLimited
|
29
|
+
when 500
|
30
|
+
raise EveOnline::Exceptions::InternalServerError
|
31
|
+
when 502
|
32
|
+
raise EveOnline::Exceptions::BadGateway
|
33
|
+
when 503
|
34
|
+
raise EveOnline::Exceptions::ServiceUnavailable
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EveOnline
|
4
|
+
module Formulas
|
5
|
+
class TrainingRate
|
6
|
+
attr_reader :primary, :secondary
|
7
|
+
|
8
|
+
def initialize(primary, secondary)
|
9
|
+
@primary = primary
|
10
|
+
@secondary = secondary
|
11
|
+
end
|
12
|
+
|
13
|
+
def rate
|
14
|
+
primary + (secondary / 2.0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/eve_online/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eve_online
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.40.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Zubkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,34 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: faraday
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: faraday_middleware
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: activesupport
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,20 +187,19 @@ extra_rdoc_files: []
|
|
159
187
|
files:
|
160
188
|
- ".circleci/config.yml"
|
161
189
|
- ".deepsource.toml"
|
190
|
+
- ".fasterer.yml"
|
162
191
|
- ".github/FUNDING.yml"
|
163
192
|
- ".gitignore"
|
164
193
|
- ".mdlrc"
|
165
194
|
- ".ruby-version"
|
195
|
+
- ".standard.yml"
|
166
196
|
- Appraisals
|
167
197
|
- CHANGELOG.md
|
168
198
|
- Gemfile
|
169
199
|
- Gemfile.lock
|
170
|
-
- Gemfile.mutant
|
171
|
-
- Gemfile.mutant.lock
|
172
200
|
- LICENSE.txt
|
173
201
|
- README.md
|
174
202
|
- Rakefile
|
175
|
-
- TODO.md
|
176
203
|
- eve_online.gemspec
|
177
204
|
- lib/eve_online.rb
|
178
205
|
- lib/eve_online/esi/alliance.rb
|
@@ -219,12 +246,14 @@ files:
|
|
219
246
|
- lib/eve_online/esi/corporation_industry_jobs.rb
|
220
247
|
- lib/eve_online/esi/corporation_killmails_recent.rb
|
221
248
|
- lib/eve_online/esi/corporation_loyalty_store_offers.rb
|
249
|
+
- lib/eve_online/esi/corporation_members.rb
|
222
250
|
- lib/eve_online/esi/corporation_npc.rb
|
223
251
|
- lib/eve_online/esi/corporation_orders.rb
|
224
252
|
- lib/eve_online/esi/dogma_attribute.rb
|
225
253
|
- lib/eve_online/esi/dogma_attributes.rb
|
226
254
|
- lib/eve_online/esi/dogma_effect.rb
|
227
255
|
- lib/eve_online/esi/dogma_effects.rb
|
256
|
+
- lib/eve_online/esi/faraday_middlewares/raise_errors.rb
|
228
257
|
- lib/eve_online/esi/killmail.rb
|
229
258
|
- lib/eve_online/esi/market_group.rb
|
230
259
|
- lib/eve_online/esi/market_groups.rb
|
@@ -361,8 +390,8 @@ files:
|
|
361
390
|
- lib/eve_online/exceptions/timeout.rb
|
362
391
|
- lib/eve_online/exceptions/unauthorized.rb
|
363
392
|
- lib/eve_online/formulas/blueprint_copy_time.rb
|
393
|
+
- lib/eve_online/formulas/training_rate.rb
|
364
394
|
- lib/eve_online/version.rb
|
365
|
-
- mutant.sh
|
366
395
|
homepage: https://github.com/evemonk/eve_online
|
367
396
|
licenses:
|
368
397
|
- MIT
|
@@ -380,15 +409,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
380
409
|
requirements:
|
381
410
|
- - ">="
|
382
411
|
- !ruby/object:Gem::Version
|
383
|
-
version: '2.
|
412
|
+
version: '2.6'
|
384
413
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
385
414
|
requirements:
|
386
415
|
- - ">="
|
387
416
|
- !ruby/object:Gem::Version
|
388
417
|
version: '0'
|
389
418
|
requirements: []
|
390
|
-
rubygems_version: 3.
|
419
|
+
rubygems_version: 3.2.15
|
391
420
|
signing_key:
|
392
421
|
specification_version: 4
|
393
|
-
summary: EveOnline ESI API
|
422
|
+
summary: EveOnline ESI API
|
394
423
|
test_files: []
|