esi-sdk 2.1.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -8
  3. data/.yardext.rb +5 -5
  4. data/CHANGELOG.md +21 -0
  5. data/Gemfile +15 -15
  6. data/Gemfile.lock +10 -6
  7. data/Rakefile +105 -138
  8. data/bin/console +3 -3
  9. data/esi-sdk.gemspec +18 -17
  10. data/exe/esi-sdk +1 -1
  11. data/lib/esi/client/alliance.rb +5 -5
  12. data/lib/esi/client/assets.rb +4 -4
  13. data/lib/esi/client/calendar.rb +5 -5
  14. data/lib/esi/client/character.rb +16 -14
  15. data/lib/esi/client/clones.rb +2 -2
  16. data/lib/esi/client/contacts.rb +9 -9
  17. data/lib/esi/client/contracts.rb +3 -3
  18. data/lib/esi/client/corporation.rb +15 -15
  19. data/lib/esi/client/dogma.rb +7 -7
  20. data/lib/esi/client/faction_warfare.rb +14 -14
  21. data/lib/esi/client/fittings.rb +3 -3
  22. data/lib/esi/client/fleets.rb +14 -14
  23. data/lib/esi/client/incursions.rb +2 -2
  24. data/lib/esi/client/industry.rb +8 -8
  25. data/lib/esi/client/insurance.rb +2 -2
  26. data/lib/esi/client/killmails.rb +1 -1
  27. data/lib/esi/client/location.rb +3 -3
  28. data/lib/esi/client/loyalty.rb +2 -2
  29. data/lib/esi/client/mail.rb +8 -8
  30. data/lib/esi/client/market.rb +12 -12
  31. data/lib/esi/client/opportunities.rb +7 -7
  32. data/lib/esi/client/planetary_interaction.rb +3 -3
  33. data/lib/esi/client/routes.rb +4 -4
  34. data/lib/esi/client/search.rb +5 -5
  35. data/lib/esi/client/skills.rb +3 -3
  36. data/lib/esi/client/sovereignty.rb +6 -6
  37. data/lib/esi/client/status.rb +2 -2
  38. data/lib/esi/client/universe.rb +45 -45
  39. data/lib/esi/client/user_interface.rb +14 -14
  40. data/lib/esi/client/wallet.rb +6 -6
  41. data/lib/esi/client/wars.rb +4 -4
  42. data/lib/esi/client.rb +116 -87
  43. data/lib/esi/version.rb +1 -1
  44. data/lib/esi-sdk.rb +2 -2
  45. metadata +22 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f855ed4e984d89d9cc257a8fc6f3d0be138f60c5d89c691f19bd439ac7d7e37
4
- data.tar.gz: aaf3df11c827c8ec8d0459e4c5f787ee1740c63fd394a4239333b59db37590b2
3
+ metadata.gz: 53eb50161c8ed5745331ae4c5f5e758b16d26cbdb1a03477c6529ded6f6af0d1
4
+ data.tar.gz: 86bf63be109701505da29dc155f7678162614a21fff263fe28e15abd36b78d2b
5
5
  SHA512:
6
- metadata.gz: 4c8f39261ab146f8e82df2fd6f4285a2f1c9c99e8288ca78d9f4de8d362ca04ac24e8c8e036c439f99a94216fb2c0e3893bc32899fa1a7dbcafcece5377bc758
7
- data.tar.gz: dbfe5a04225bbc14b947bf017668dd97333ffdf838c09c9b185f0510459c7f5a77bbeb9b0d499831e1e9f4d621cf8697e83553a86ab7231eb7895ebd94ce2d9a
6
+ metadata.gz: a48179dc2da01171f4fc03cb04225b542f96ac6bef91cb27fbbb5a2edddaa5affa7465fb6f737aef2e98523e6e387d0e6592aa2b39f96ae9570847631d2501a7
7
+ data.tar.gz: 03f373c97e9d0daaa0bbfef87e739518650aa6733573795235c25d1225d293b27291b8665928a711b2625370544d7183cb9905c7e4236712676d3f2a51fb0cfa
data/.rubocop.yml CHANGED
@@ -2,19 +2,12 @@ AllCops:
2
2
  NewCops: enable
3
3
  TargetRubyVersion: 3.0
4
4
 
5
- Style/StringLiterals:
6
- Enabled: true
7
- EnforcedStyle: double_quotes
8
-
9
- Style/StringLiteralsInInterpolation:
10
- Enabled: true
11
- EnforcedStyle: double_quotes
12
-
13
5
  Layout/LineLength:
14
6
  Max: 120
15
7
  Exclude:
16
8
  - lib/esi/client/*.rb
17
9
  - spec/lib/esi/client/*_spec.rb
10
+ - spec/lib/esi/client_spec.rb
18
11
  - Rakefile
19
12
 
20
13
  Metrics/BlockLength:
data/.yardext.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "kramdown"
4
- require "yard"
3
+ require 'kramdown'
4
+ require 'yard'
5
5
 
6
6
  # Make new Kramdown class with Github Formatted Markdown on
7
7
  class KramdownGFM < Kramdown::Document
8
8
  def initialize(text, opts = {})
9
- super(text, opts.merge(input: "GFM", hard_wrap: false))
9
+ super(text, opts.merge(input: 'GFM', hard_wrap: false))
10
10
  end
11
11
  end
12
12
 
13
13
  # Register new KramdownGFM
14
14
  YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown] <<
15
- { lib: :"kramdown-parser-gfm", const: "KramdownGFM" }
15
+ { lib: :'kramdown-parser-gfm', const: 'KramdownGFM' }
16
16
 
17
17
  # Register custom templates
18
- YARD::Templates::Engine.register_template_path File.expand_path("yard/templates", __dir__)
18
+ YARD::Templates::Engine.register_template_path File.expand_path('yard/templates', __dir__)
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # ESI SDK Changelog
2
2
 
3
+ # [3.0.0](https://github.com/bokoboshahni/esi-sdk-ruby/compare/v2.1.3...v3.0.0) (2022-01-26)
4
+
5
+
6
+ * feat!: use typhoeus and oj for api calls ([b6b150e](https://github.com/bokoboshahni/esi-sdk-ruby/commit/b6b150eff93889415ddca98d497c437470030e09))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * Typhoeus is now used instead of HTTPX for API calls and
12
+ oj is used for JSON parsing.
13
+
14
+ The following options have been removed from `ESI::Client#initialize`:
15
+
16
+ - `:cache`: Configure Typhoeus cache globally with
17
+ `Typhoeus::Config.cache`
18
+ (see https://github.com/typhoeus/typhoeus#caching)
19
+ - `:logger`: Configure Ethon logger globally with `Ethon.logger`
20
+ (see https://www.rubydoc.info/github/typhoeus/ethon/Ethon/Loggable#logger=-instance_method)
21
+ - `:instrumentation`: Instrumentation support to be re-added in a later
22
+ release.
23
+
3
24
  ## [2.1.3](https://github.com/bokoboshahni/esi-sdk-ruby/compare/v2.1.2...v2.1.3) (2021-12-08)
4
25
 
5
26
 
data/Gemfile CHANGED
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- ruby "3.0.2"
5
+ ruby '3.0.2'
6
6
 
7
7
  gemspec
8
8
 
9
- gem "activesupport", "~> 6.1"
10
- gem "awesome_print", "~> 1.9"
11
- gem "rake", "~> 13.0"
12
- gem "rspec", "~> 3.10"
13
- gem "rubocop", "~> 1.18"
14
- gem "rubocop-performance", "~> 1.11"
15
- gem "rubocop-rake", "~> 0.6"
16
- gem "rubocop-rspec", "~> 2.4"
17
- gem "simplecov", "~> 0.21"
18
- gem "webmock", "~> 3.13"
19
- gem "yard", "~> 0.9"
9
+ gem 'activesupport', '~> 6.1'
10
+ gem 'awesome_print', '~> 1.9'
11
+ gem 'rake', '~> 13.0'
12
+ gem 'rspec', '~> 3.10'
13
+ gem 'rubocop', '~> 1.18'
14
+ gem 'rubocop-performance', '~> 1.11'
15
+ gem 'rubocop-rake', '~> 0.6'
16
+ gem 'rubocop-rspec', '~> 2.4'
17
+ gem 'simplecov', '~> 0.21'
18
+ gem 'webmock', '~> 3.14'
19
+ gem 'yard', '~> 0.9'
20
20
 
21
- gem "kramdown-parser-gfm", "~> 1.1"
21
+ gem 'kramdown-parser-gfm', '~> 1.1'
22
22
 
23
- gem "rouge", "~> 3.26"
23
+ gem 'rouge', '~> 3.26'
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- esi-sdk (2.1.3)
5
- httpx (~> 0.18)
4
+ esi-sdk (3.0.0)
5
+ oj (~> 3.13)
6
6
  retriable (~> 3.1)
7
+ typhoeus (~> 1.4)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -23,10 +24,10 @@ GEM
23
24
  rexml
24
25
  diff-lcs (1.4.4)
25
26
  docile (1.4.0)
27
+ ethon (0.15.0)
28
+ ffi (>= 1.15.0)
29
+ ffi (1.15.5)
26
30
  hashdiff (1.0.1)
27
- http-2-next (0.5.0)
28
- httpx (0.18.1)
29
- http-2-next (>= 0.4.1)
30
31
  i18n (1.8.10)
31
32
  concurrent-ruby (~> 1.0)
32
33
  kramdown (2.3.1)
@@ -34,6 +35,7 @@ GEM
34
35
  kramdown-parser-gfm (1.1.0)
35
36
  kramdown (~> 2.0)
36
37
  minitest (5.14.4)
38
+ oj (3.13.11)
37
39
  parallel (1.21.0)
38
40
  parser (3.0.2.0)
39
41
  ast (~> 2.4.1)
@@ -82,6 +84,8 @@ GEM
82
84
  simplecov_json_formatter (~> 0.1)
83
85
  simplecov-html (0.12.3)
84
86
  simplecov_json_formatter (0.1.3)
87
+ typhoeus (1.4.0)
88
+ ethon (>= 0.9.0)
85
89
  tzinfo (2.0.4)
86
90
  concurrent-ruby (~> 1.0)
87
91
  unicode-display_width (2.1.0)
@@ -109,7 +113,7 @@ DEPENDENCIES
109
113
  rubocop-rake (~> 0.6)
110
114
  rubocop-rspec (~> 2.4)
111
115
  simplecov (~> 0.21)
112
- webmock (~> 3.13)
116
+ webmock (~> 3.14)
113
117
  yard (~> 0.9)
114
118
 
115
119
  RUBY VERSION
data/Rakefile CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "yard"
5
- require "yard/rake/yardoc_task"
6
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'yard'
5
+ require 'yard/rake/yardoc_task'
6
+ require 'rspec/core/rake_task'
7
7
 
8
8
  RSpec::Core::RakeTask.new(:spec)
9
9
 
10
- require "rubocop/rake_task"
10
+ require 'rubocop/rake_task'
11
11
 
12
12
  RuboCop::RakeTask.new
13
13
 
@@ -16,30 +16,30 @@ YARD::Rake::YardocTask.new(:doc)
16
16
  task default: %i[spec rubocop]
17
17
 
18
18
  task :set_version do
19
- version_file = File.join(File.dirname(__FILE__), "lib/esi/version.rb")
19
+ version_file = File.join(File.dirname(__FILE__), 'lib/esi/version.rb')
20
20
  version_content = File.read(version_file)
21
- new_version = ENV["VERSION"]
22
- new_content = version_content.gsub(/VERSION = ".+"/m, "VERSION = \"#{new_version}\"")
23
- File.write("lib/esi/version.rb", new_content)
21
+ new_version = ENV['VERSION']
22
+ new_content = version_content.gsub(/VERSION = '.+'/m, "VERSION = \"#{new_version}\"")
23
+ File.write('lib/esi/version.rb', new_content)
24
24
  end
25
25
 
26
26
  task :generate do
27
- require "active_support/core_ext/string/inflections"
28
- require "json"
29
- require "open-uri"
27
+ require 'active_support/core_ext/string/inflections'
28
+ require 'json'
29
+ require 'open-uri'
30
30
 
31
- swagger = JSON.parse(URI.open("https://esi.evetech.net/latest/swagger.json").read)
31
+ swagger = JSON.parse(URI.open('https://esi.evetech.net/latest/swagger.json').read)
32
32
 
33
- paths = swagger["paths"]
33
+ paths = swagger['paths']
34
34
  all_operations = paths.each_with_object({}) do |(path, operations), h|
35
35
  operations.each do |(http_method, operation)|
36
- description = operation["description"].split("\n").first.strip
36
+ description = operation['description'].split("\n").first.strip
37
37
 
38
- method_name_parts = path.split("/").map { |p| p.gsub(/[{}]/, "") }.map { |p| p.gsub(/_id/, "") }
39
- operation_name = operation["operationId"]
38
+ method_name_parts = path.split('/').map { |p| p.gsub(/[{}]/, '') }.map { |p| p.gsub(/_id/, '') }
39
+ operation_name = operation['operationId']
40
40
  method_name_parts.map! do |p|
41
41
  if [(method_name_parts[method_name_parts.index(p) + 1]).to_s,
42
- "#{method_name_parts[method_name_parts.index(p) + 1]}s", ""].include?(p)
42
+ "#{method_name_parts[method_name_parts.index(p) + 1]}s", ''].include?(p)
43
43
  nil
44
44
  else
45
45
  p
@@ -55,75 +55,73 @@ task :generate do
55
55
  p.singularize
56
56
  end
57
57
  end
58
- method_name = "#{http_method}_#{method_name_parts.compact.join("_")}"
58
+ method_name = "#{http_method}_#{method_name_parts.compact.join('_')}"
59
59
 
60
- path_params = operation["parameters"].select { |p| p["in"] == "path" || p["$ref"] }
60
+ path_params = operation['parameters'].select { |p| p['in'] == 'path' || p['$ref'] }
61
61
  path_params.map! do |param|
62
- if param["$ref"]
63
- ref_name = param["$ref"].match(%r{#/parameters/(alliance_id|corporation_id|character_id)})
62
+ if param['$ref']
63
+ ref_name = param['$ref'].match(%r{#/parameters/(alliance_id|corporation_id|character_id)})
64
64
  ref_name = ref_name[1] if ref_name
65
65
 
66
66
  next unless ref_name
67
67
 
68
- swagger["parameters"][ref_name]
68
+ swagger['parameters'][ref_name]
69
69
  else
70
70
  param
71
71
  end
72
72
  end
73
- path_params.compact!.sort_by! { |p| p["name"] }
73
+ path_params.compact!.sort_by! { |p| p['name'] }
74
74
 
75
- body_param = operation["parameters"].select { |p| p["in"] == "body" }.first
75
+ body_param = operation['parameters'].select { |p| p['in'] == 'body' }.first
76
76
 
77
- tag = operation["tags"].first || "Untagged"
77
+ tag = operation['tags'].first || 'Untagged'
78
78
  operation[tag]
79
79
 
80
- scopes = (operation["security"].first["evesso"] if operation["security"].present?)
80
+ scopes = (operation['security'].first['evesso'] if operation['security'].present?)
81
81
 
82
- cache = operation["x-cached-seconds"]
83
- errors = operation["responses"].reject { |(k, _)| %w[200 201 204 304].include?(k) }
84
- versions = operation["x-alternate-versions"]
82
+ cache = operation['x-cached-seconds']
83
+ errors = operation['responses'].reject { |(k, _)| %w[200 201 204 304].include?(k) }
84
+ versions = operation['x-alternate-versions']
85
85
 
86
- query = operation["parameters"].select { |p| p["in"] == "query" }
86
+ query = operation['parameters'].select { |p| p['in'] == 'query' }
87
87
 
88
88
  h[method_name] =
89
89
  { params: path_params, method: http_method, description: description, tag: tag, path: path,
90
90
  name: operation_name, body: body_param, scopes: scopes, cache: cache, versions: versions, errors: errors,
91
- responses: operation["responses"], query: query }
91
+ responses: operation['responses'], query: query }
92
92
  end
93
93
  end
94
94
 
95
95
  method_aliases = {
96
- "get_killmail_killmail_hash" => "get_killmail",
97
- "get_markets_groups_market_group" => "get_market_group",
98
- "get_markets_groups" => "get_market_groups",
99
- "get_character_corporationhistory" => "get_character_corporation_history",
100
- "get_corporation_alliancehistory" => "get_corporation_alliance_history"
96
+ 'get_killmail_killmail_hash' => 'get_killmail',
97
+ 'get_markets_groups_market_group' => 'get_market_group',
98
+ 'get_markets_groups' => 'get_market_groups',
99
+ 'get_character_corporationhistory' => 'get_character_corporation_history',
100
+ 'get_corporation_alliancehistory' => 'get_corporation_alliance_history'
101
101
  }
102
102
 
103
103
  error_mapping = {
104
- 400 => "ESI::Errors::BadRequestError",
105
- 401 => "ESI::Errors::UnauthorizedError",
106
- 403 => "ESI::Errors::ForbiddenError",
107
- 404 => "ESI::Errors::NotFoundError",
108
- 420 => "ESI::Errors::ErrorLimitedError",
109
- 422 => "ESI::Errors::UnprocessableEntityError",
110
- 500 => "ESI::Errors::InternalServerError",
111
- 503 => "ESI::Errors::ServiceUnavailableError",
112
- 504 => "ESI::Errors::GatewayTimeoutError",
113
- 520 => "ESI::Errors::EveServerError"
104
+ 400 => 'ESI::Errors::BadRequestError',
105
+ 401 => 'ESI::Errors::UnauthorizedError',
106
+ 403 => 'ESI::Errors::ForbiddenError',
107
+ 404 => 'ESI::Errors::NotFoundError',
108
+ 420 => 'ESI::Errors::ErrorLimitedError',
109
+ 422 => 'ESI::Errors::UnprocessableEntityError',
110
+ 500 => 'ESI::Errors::InternalServerError',
111
+ 503 => 'ESI::Errors::ServiceUnavailableError',
112
+ 504 => 'ESI::Errors::GatewayTimeoutError',
113
+ 520 => 'ESI::Errors::EveServerError'
114
114
  }.freeze
115
115
 
116
- requires = []
117
- includes = []
118
116
  all_operations.group_by { |(_, v)| v[:tag] }.each do |(tag, operations)|
119
- lib_filename = "#{tag.gsub(/ /, "_").underscore}.rb"
120
- module_name = tag.gsub(/ /, "_").classify
117
+ lib_filename = "#{tag.gsub(/ /, '_').underscore}.rb"
118
+ module_name = tag.gsub(/ /, '_').classify
121
119
  method_definitions = operations.sort_by { |(k, _v)| k }.each_with_object([]) do |(method_name, operation), a|
122
- signature_params = operation[:params].map { |p| "#{p["name"]}:" }
123
- raw_call_params = operation[:params].map { |p| "#{p["name"]}: #{p["name"]}" }
120
+ signature_params = operation[:params].map { |p| "#{p['name']}:" }
121
+ raw_call_params = operation[:params].map { |p| "#{p['name']}: #{p['name']}" }
124
122
 
125
123
  description = "# #{operation[:description]}"
126
- description = "#{description}." unless description.end_with?(".")
124
+ description = "#{description}." unless description.end_with?('.')
127
125
  description += "\n"
128
126
 
129
127
  description += "#\n\n# This endpoint is cached for up to #{operation[:cache]} seconds.\n" if operation[:cache]
@@ -143,40 +141,40 @@ task :generate do
143
141
  end
144
142
 
145
143
  param_tags = operation[:params].map do |p|
146
- "# @param #{p["name"]} [#{p["type"].capitalize}] #{p["description"]}"
144
+ "# @param #{p['name']} [#{p['type'].capitalize}] #{p['description']}"
147
145
  end
148
146
 
149
147
  if operation[:body]
150
148
  body_param = operation[:body]
151
- body_name = body_param["name"]
149
+ body_name = body_param['name']
152
150
  body_type =
153
- case body_param["schema"]["type"]
154
- when "array"
155
- "Array"
156
- when "object"
157
- "Hash"
151
+ case body_param['schema']['type']
152
+ when 'array'
153
+ 'Array'
154
+ when 'object'
155
+ 'Hash'
158
156
  end
159
157
 
160
158
  signature_params << "#{body_name}:"
161
159
  raw_call_params << "#{body_name}: #{body_name}"
162
- param_tags += ["# @param #{body_name} [#{body_type}] #{body_param["description"]}"]
160
+ param_tags += ["# @param #{body_name} [#{body_type}] #{body_param['description']}"]
163
161
  end
164
162
 
165
163
  operation[:query]&.each do |p|
166
- p_tag = "# @param #{p["name"]} [#{p["type"].capitalize}] "
167
- p_tag += (p["description"]).to_s
168
- p_tag += ". Must be one of: #{p["enum"].map { |e| "`#{e}`" }.join(", ")}" if p["enum"]
169
- p_str = if p["default"] && p["type"] == "integer"
170
- "#{p["name"]}: #{p["default"]}"
171
- elsif p["default"] && p["type"] == "string"
172
- "#{p["name"]}: \"#{p["default"]}\""
173
- elsif !p["required"]
174
- "#{p["name"]}: nil"
164
+ p_tag = "# @param #{p['name']} [#{p['type'].capitalize}] "
165
+ p_tag += (p['description']).to_s
166
+ p_tag += ". Must be one of: #{p['enum'].map { |e| "`#{e}`" }.join(', ')}" if p['enum']
167
+ p_str = if p['default'] && p['type'] == 'integer'
168
+ "#{p['name']}: #{p['default']}"
169
+ elsif p['default'] && p['type'] == 'string'
170
+ "#{p['name']}: \"#{p['default']}\""
171
+ elsif !p['required']
172
+ "#{p['name']}: nil"
175
173
  else
176
- "#{p["name"]}:"
174
+ "#{p['name']}:"
177
175
  end
178
176
  signature_params << p_str
179
- raw_call_params << "#{p["name"]}: #{p["name"]}"
177
+ raw_call_params << "#{p['name']}: #{p['name']}"
180
178
  param_tags << p_tag
181
179
  end
182
180
 
@@ -186,10 +184,10 @@ task :generate do
186
184
  raw_call_params += %w[headers params].map do |p|
187
185
  "#{p}: #{p}"
188
186
  end
189
- param_tags << "# @param params [Hash] Additional query string parameters"
187
+ param_tags << '# @param params [Hash] Additional query string parameters'
190
188
 
191
189
  param_tags += [
192
- "# @param headers [Hash] Additional headers"
190
+ '# @param headers [Hash] Additional headers'
193
191
  ]
194
192
  description += "#\n"
195
193
  description += param_tags.join("\n")
@@ -197,18 +195,18 @@ task :generate do
197
195
 
198
196
  description += "#\n"
199
197
  raise_tags = operation[:errors].map do |(e, v)|
200
- "# @raise [#{error_mapping[e.to_i]}] #{v["description"]}"
198
+ "# @raise [#{error_mapping[e.to_i]}] #{v['description']}"
201
199
  end
202
200
  description += raise_tags.join("\n")
203
201
  description += "\n"
204
202
 
205
203
  description += "#\n"
206
204
  description += "# @see https://esi.evetech.net/ui/#/#{operation[:tag]}/#{operation[:name]}"
207
- description.gsub!(/^$\n/m, "")
205
+ description.gsub!(/^$\n/m, '')
208
206
 
209
- signature = "(#{signature_params.join(", ")})"
210
- raw_call = "(#{raw_call_params.join(", ")})"
211
- path_parts = operation[:path].split("/")
207
+ signature = "(#{signature_params.join(', ')})"
208
+ raw_call = "(#{raw_call_params.join(', ')})"
209
+ path_parts = operation[:path].split('/')
212
210
  path_parts.map! do |p|
213
211
  if p =~ /\{\w+\}/
214
212
  "##{p}"
@@ -216,18 +214,18 @@ task :generate do
216
214
  p
217
215
  end
218
216
  end
219
- path = "#{path_parts.join("/")}/"
217
+ path = "#{path_parts.join('/')}/"
220
218
 
221
219
  http_call_params = %w[headers params].map { |p| "#{p}: #{p}" }
222
- http_call_params << ("payload: #{body_param["name"]}" if operation[:body])
220
+ http_call_params << ("payload: #{body_param['name']}" if operation[:body])
223
221
 
224
222
  params_merge = if operation[:query].any?
225
- "params.merge!(#{operation[:query].map { |q| "'#{q["name"]}' => #{q["name"]}" }.join(", ")})"
223
+ "params.merge!(#{operation[:query].map { |q| "'#{q['name']}' => #{q['name']}" }.join(', ')})"
226
224
  else
227
- ""
225
+ ''
228
226
  end
229
227
 
230
- http_call = "#{operation[:method]}(\"#{path}\", #{http_call_params.join(", ")})"
228
+ http_call = "#{operation[:method]}(\"#{path}\", #{http_call_params.join(', ')})"
231
229
 
232
230
  alias_methods = if method_aliases[method_name]
233
231
  Array(method_aliases[method_name]).sort.map do |alias_name|
@@ -239,7 +237,7 @@ task :generate do
239
237
  alias_methods << "alias_method :#{operation[:name]}, :#{method_name}" unless operation[:name] == method_name
240
238
  alias_methods = alias_methods.join("\n")
241
239
 
242
- if operation[:responses]["200"] && operation[:responses]["200"]["headers"] && operation[:responses]["200"]["headers"].key?("X-Pages")
240
+ if operation[:responses]['200'] && operation[:responses]['200']['headers'] && operation[:responses]['200']['headers'].key?('X-Pages')
243
241
  a << <<~METHOD_DEFINITION
244
242
  #{description}
245
243
  def #{method_name}#{signature}
@@ -258,7 +256,7 @@ task :generate do
258
256
  a << <<~METHOD_DEFINITION
259
257
  #{description}
260
258
  def #{method_name}#{signature}
261
- #{method_name}_raw#{raw_call}.json
259
+ parse_response(#{method_name}_raw#{raw_call})
262
260
  end
263
261
  #{alias_methods}
264
262
 
@@ -286,43 +284,43 @@ task :generate do
286
284
 
287
285
  File.write(File.join("lib/esi/client/#{lib_filename}"), lib_content)
288
286
 
289
- spec_filename = "#{tag.gsub(/ /, "_").underscore}_spec.rb"
287
+ spec_filename = "#{tag.gsub(/ /, '_').underscore}_spec.rb"
290
288
  spec_path = File.join("spec/lib/esi/client/#{spec_filename}")
291
289
 
292
290
  describe_blocks = operations.sort_by { |(k, _v)| k }.each_with_object([]) do |(method_name, operation), a|
293
- success_path = operation[:path].gsub(/\{\w+\}/, "1234567890")
294
- success_response = operation[:responses].find { |(k, _)| k.start_with?("20") }
291
+ success_path = operation[:path].gsub(/\{\w+\}/, '1234567890')
292
+ success_response = operation[:responses].find { |(k, _)| k.start_with?('20') }
295
293
  success_code = success_response.first
296
294
  success_desc = success_response.last
297
295
 
298
296
  success_response_body = case success_code
299
- when "204"
300
- "nil"
297
+ when '204'
298
+ 'nil'
301
299
  else
302
- success_desc["examples"]["application/json"].inspect
300
+ success_desc['examples']['application/json'].inspect
303
301
  end
304
302
 
305
- success_params = operation[:params].map { |p| "#{p["name"]}: \"1234567890\"" }
306
- success_params += operation[:query].map { |p| "#{p["name"]}: \"1234567890\"" }
303
+ success_params = operation[:params].map { |p| "#{p['name']}: \"1234567890\"" }
304
+ success_params += operation[:query].map { |p| "#{p['name']}: \"1234567890\"" }
307
305
 
308
306
  if operation[:body]
309
307
  body_param = operation[:body]
310
- body_name = body_param["name"]
308
+ body_name = body_param['name']
311
309
  body_value =
312
- case body_param["schema"]["type"]
313
- when "array"
314
- "[1, 2, 3]"
315
- when "object"
310
+ case body_param['schema']['type']
311
+ when 'array'
312
+ '[1, 2, 3]'
313
+ when 'object'
316
314
  '{ "foo" => "bar" }'
317
315
  end
318
316
  success_params << "#{body_name}: #{body_value}"
319
317
  end
320
318
 
321
- with_query = operation[:query].any? ? ".with(query: { #{operation[:query].map { |p| "#{p["name"]}: \"1234567890\"" }.join(", ")} })" : ""
319
+ with_query = operation[:query].any? ? ".with(query: { #{operation[:query].map { |p| "#{p['name']}: \"1234567890\"" }.join(', ')} })" : ''
322
320
 
323
- extra_headers = success_desc["headers"] && success_desc["headers"]["X-Pages"] ? ", 'X-Pages': '1'" : ""
321
+ extra_headers = success_desc['headers'] && success_desc['headers']['X-Pages'] ? ", 'X-Pages': '1'" : ''
324
322
 
325
- describe = " describe \"##{method_name}\" do\n"
323
+ describe = " describe \"##{method_name}\" do\n"
326
324
  describe += " context \"when the response is #{success_code}\" do\n"
327
325
  describe += " let(:response) { #{success_response_body} }\n"
328
326
  describe += "\n"
@@ -331,33 +329,10 @@ task :generate do
331
329
  describe += " end\n"
332
330
  describe += "\n"
333
331
  describe += " it \"returns the response\" do\n"
334
- describe += " expect(client.#{method_name}(#{success_params.join(", ")})).to eq(response)\n"
332
+ describe += " expect(client.#{method_name}(#{success_params.join(', ')})).to eq(response)\n"
335
333
  describe += " end\n"
336
334
  describe += " end\n"
337
-
338
- describe += "\n"
339
-
340
- error_contexts = operation[:errors].map do |(code, error)|
341
- next if %w[502 503 504].include?(code)
342
-
343
- error_response_body = error["examples"]["application/json"].inspect
344
-
345
- context = " context \"when the response is #{code}\" do\n"
346
- context += " let(:response) { #{error_response_body} }\n"
347
- context += "\n"
348
- context += " before do\n"
349
- context += " stub_request(:#{operation[:method]}, \"https://esi.evetech.net/latest#{success_path}\")#{with_query}.to_return(body: response.to_json, status: #{code}, headers: { 'Content-Type': 'application/json' })\n"
350
- context += " end\n"
351
- context += "\n"
352
- context += " it \"raises a #{error_mapping[code.to_i]} error\" do\n"
353
- context += " expect { client.#{method_name}(#{success_params.join(", ")}) }.to raise_error(#{error_mapping[code.to_i]})\n"
354
- context += " end\n"
355
- "#{context} end\n"
356
- end
357
-
358
- describe += error_contexts.join("\n")
359
-
360
- describe += " end"
335
+ describe += ' end'
361
336
  a << describe
362
337
  end
363
338
 
@@ -365,22 +340,14 @@ task :generate do
365
340
  # frozen_string_literal: true
366
341
 
367
342
  RSpec.describe ESI::Client::#{module_name}, type: :stub do
368
- subject(:client) { ESI::Client.new(user_agent: \"esi-sdk-ruby Tests/1.0; +(https://github.com/bokoboshahni/esi-sdk-ruby)\") }
343
+ subject(:client) { ESI::Client.new(retries: 2, user_agent: \"esi-sdk-ruby Tests/1.0; +(https://github.com/bokoboshahni/esi-sdk-ruby)\") }
369
344
 
370
345
  #{describe_blocks.join("\n\n")}
371
346
  end
372
347
  SPEC_FILE
373
348
 
374
349
  File.write(spec_path, spec_content)
375
-
376
- requires << "require_relative \"./client/#{lib_filename.gsub(/\.rb/, "")}\""
377
- includes << "include ESI::Client::#{module_name}"
378
- end
379
-
380
- at_exit do
381
- puts requires
382
- puts includes
383
350
  end
384
351
 
385
- Rake::Task["rubocop:auto_correct"].invoke
352
+ Rake::Task['rubocop:auto_correct'].invoke
386
353
  end
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "esi-sdk"
4
+ require 'bundler/setup'
5
+ require 'esi-sdk'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require "esi-sdk"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)