eve_online 0.35.0 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module EveOnline
7
7
  class Alliance < Base
8
8
  extend Forwardable
9
9
 
10
- API_PATH = "/v3/alliances/%<alliance_id>s/"
10
+ API_PATH = "/v4/alliances/%<alliance_id>s/"
11
11
 
12
12
  attr_reader :alliance_id
13
13
 
@@ -7,7 +7,7 @@ module EveOnline
7
7
  class AllianceIcon < Base
8
8
  extend Forwardable
9
9
 
10
- API_PATH = "/v1/alliances/%<alliance_id>s/icons/"
10
+ API_PATH = "/v2/alliances/%<alliance_id>s/icons/"
11
11
 
12
12
  attr_reader :alliance_id
13
13
 
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "openssl"
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, :parser, :_read_timeout, :_open_timeout, :_etag,
14
- :language
12
+ attr_reader :token, :_read_timeout, :_open_timeout, :_write_timeout,
13
+ :_etag, :language, :adapter, :middlewares
15
14
 
16
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
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
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
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
- "Get"
41
+ :get
46
42
  end
47
43
 
48
44
  def read_timeout
49
- client.read_timeout
45
+ connection.options.read_timeout
50
46
  end
51
47
 
52
48
  def read_timeout=(value)
53
- client.read_timeout = value
49
+ connection.options.read_timeout = value
54
50
  end
55
51
 
56
52
  def open_timeout
57
- client.open_timeout
53
+ connection.options.open_timeout
58
54
  end
59
55
 
60
56
  def open_timeout=(value)
61
- client.open_timeout = value
57
+ connection.options.open_timeout = value
62
58
  end
63
59
 
64
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
65
- def write_timeout
66
- client.write_timeout
67
- end
60
+ def write_timeout
61
+ connection.options.write_timeout
62
+ end
68
63
 
69
- def write_timeout=(value)
70
- client.write_timeout = value
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.header["Etag"]&.gsub("W/", "")&.gsub('"', "")
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.header["X-Pages"]&.to_i
80
+ resource.headers["x-pages"]&.to_i
87
81
  end
88
82
 
89
83
  def error_limit_remain
90
- resource.header["X-ESI-Error-Limit-Remain"]&.to_i
84
+ resource.headers["x-esi-error-limit-remain"]&.to_i
91
85
  end
92
86
 
93
87
  def error_limit_reset
94
- resource.header["X-ESI-Error-Limit-Reset"]&.to_i
88
+ resource.headers["x-esi-error-limit-reset"]&.to_i
95
89
  end
96
90
 
97
- def client
98
- @client ||= begin
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 request
113
- @request ||= begin
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
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6.0")
128
- class Net::WriteTimeout < StandardError; end
99
+ def connection
100
+ @connection ||= Faraday.new { |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
+ }
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 ||= client.request(request)
163
- rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout
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.is_a?(Net::HTTPNotModified)
160
+ resource.status == 304
169
161
  end
170
162
 
171
163
  def content
172
- case resource
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
- # raise EveOnline::Exceptions::UnknownStatus
199
- raise NotImplementedError
167
+ resource.body
200
168
  end
201
169
  end
202
170
 
203
171
  def response
204
- @response ||= parser.parse(content)
172
+ @response ||= content
205
173
  end
206
174
 
207
175
  private
@@ -26,7 +26,7 @@ module EveOnline
26
26
  end
27
27
 
28
28
  def http_method
29
- "Post"
29
+ :post
30
30
  end
31
31
 
32
32
  def payload
@@ -26,7 +26,7 @@ module EveOnline
26
26
  end
27
27
 
28
28
  def http_method
29
- "Post"
29
+ :post
30
30
  end
31
31
 
32
32
  def payload
@@ -3,7 +3,7 @@
3
3
  module EveOnline
4
4
  module ESI
5
5
  class CharacterCorporationHistory < Base
6
- API_PATH = "/v1/characters/%<character_id>s/corporationhistory/"
6
+ API_PATH = "/v2/characters/%<character_id>s/corporationhistory/"
7
7
 
8
8
  attr_reader :character_id
9
9
 
@@ -26,7 +26,7 @@ module EveOnline
26
26
  end
27
27
 
28
28
  def http_method
29
- "Post"
29
+ :post
30
30
  end
31
31
 
32
32
  def payload
@@ -26,7 +26,7 @@ module EveOnline
26
26
  end
27
27
 
28
28
  def http_method
29
- "Post"
29
+ :post
30
30
  end
31
31
 
32
32
  def payload
@@ -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
@@ -20,7 +20,7 @@ module EveOnline
20
20
  reward: reward,
21
21
  start_location_id: start_location_id,
22
22
  title: title,
23
- type: type,
23
+ kind: kind,
24
24
  volume: volume
25
25
  }
26
26
  end
@@ -85,7 +85,7 @@ module EveOnline
85
85
  options["title"]
86
86
  end
87
87
 
88
- def type
88
+ def kind
89
89
  options["type"]
90
90
  end
91
91
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EveOnline
4
- VERSION = "0.35.0"
4
+ VERSION = "0.39.0"
5
5
  end
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.35.0
4
+ version: 0.39.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: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2021-02-28 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
@@ -362,7 +391,6 @@ files:
362
391
  - lib/eve_online/exceptions/unauthorized.rb
363
392
  - lib/eve_online/formulas/blueprint_copy_time.rb
364
393
  - lib/eve_online/version.rb
365
- - mutant.sh
366
394
  homepage: https://github.com/evemonk/eve_online
367
395
  licenses:
368
396
  - MIT
@@ -380,15 +408,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
380
408
  requirements:
381
409
  - - ">="
382
410
  - !ruby/object:Gem::Version
383
- version: '2.5'
411
+ version: '2.6'
384
412
  required_rubygems_version: !ruby/object:Gem::Requirement
385
413
  requirements:
386
414
  - - ">="
387
415
  - !ruby/object:Gem::Version
388
416
  version: '0'
389
417
  requirements: []
390
- rubygems_version: 3.1.2
418
+ rubygems_version: 3.2.11
391
419
  signing_key:
392
420
  specification_version: 4
393
- summary: EveOnline ESI API.
421
+ summary: EveOnline ESI API
394
422
  test_files: []