api_recipes 3.0.0.beta3 → 3.0.0.beta5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +377 -76
  3. data/UPGRADING.md +223 -59
  4. data/lib/api_recipes/cli/calls.rb +27 -0
  5. data/lib/api_recipes/cli/code.rb +153 -0
  6. data/lib/api_recipes/cli/convert/migration.rb +819 -0
  7. data/lib/api_recipes/cli/convert/snippet.rb +67 -0
  8. data/lib/api_recipes/cli/convert.rb +614 -0
  9. data/lib/api_recipes/cli/description.rb +65 -0
  10. data/lib/api_recipes/cli/import/server.rb +20 -9
  11. data/lib/api_recipes/cli/import/writer.rb +16 -4
  12. data/lib/api_recipes/cli/import.rb +23 -9
  13. data/lib/api_recipes/cli/recipes/summary.rb +25 -6
  14. data/lib/api_recipes/cli/recipes.rb +5 -2
  15. data/lib/api_recipes/cli/routes.rb +63 -8
  16. data/lib/api_recipes/cli/tags.rb +19 -0
  17. data/lib/api_recipes/cli/upgrade/fix.rb +206 -0
  18. data/lib/api_recipes/cli/upgrade/project.rb +194 -0
  19. data/lib/api_recipes/cli/upgrade/screen.rb +165 -0
  20. data/lib/api_recipes/cli/upgrade/tree_rules.rb +290 -0
  21. data/lib/api_recipes/cli/upgrade.rb +706 -57
  22. data/lib/api_recipes/cli.rb +171 -17
  23. data/lib/api_recipes/configuration.rb +17 -95
  24. data/lib/api_recipes/endpoint.rb +1 -1
  25. data/lib/api_recipes/internals/compiler.rb +102 -67
  26. data/lib/api_recipes/internals/context.rb +35 -6
  27. data/lib/api_recipes/internals/declaration.rb +17 -15
  28. data/lib/api_recipes/internals/definition.rb +16 -3
  29. data/lib/api_recipes/internals/option_value.rb +92 -0
  30. data/lib/api_recipes/internals/recipe.rb +1 -1
  31. data/lib/api_recipes/internals/recipe_lock.rb +12 -9
  32. data/lib/api_recipes/internals/request.rb +17 -6
  33. data/lib/api_recipes/version.rb +1 -1
  34. data/lib/api_recipes.rb +1 -0
  35. metadata +13 -1
@@ -38,16 +38,18 @@ module ApiRecipes
38
38
 
39
39
  check_follow
40
40
  check_headers
41
- chain = @context.levels
41
+ chain = @chain = @context.levels
42
42
  origin = @context.origin(chain: chain)
43
43
  credential = @context.credential(origin, chain: chain)
44
44
  address = checked(url(origin), origin)
45
45
  logger = ApiRecipes.logger
46
46
  logger.info(address) if ApiRecipes.configuration.print_urls
47
47
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
48
- http_response = send_request(client(credential, chain), address, send_options(credential, origin, chain))
48
+ verb = @context.resolve(:verb, @definition.verb, chain: chain)
49
+ SETTINGS.each { |key| setting(key) }
50
+ http_response = send_request(client(credential, chain), verb, address, send_options(credential, origin, chain))
49
51
  elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started) * 1000
50
- logger.debug("#{@definition.verb.to_s.upcase} #{address} -> #{http_response.code} (#{elapsed.round(1)}ms)")
52
+ logger.debug("#{verb.to_s.upcase} #{address} -> #{http_response.code} (#{elapsed.round(1)}ms)")
51
53
  respond(http_response)
52
54
  end
53
55
 
@@ -59,7 +61,16 @@ module ApiRecipes
59
61
 
60
62
  private
61
63
 
62
- def setting(key) = @context.setting(key, @definition, @overrides)
64
+ # The levels are those the request read: a variable in an option gets
65
+ # the value the origin and the credential were made with.
66
+ def setting(key)
67
+ @settings ||= {}
68
+ @settings.fetch(key) { @settings[key] = @context.setting(key, @definition, @overrides, chain: @chain) }
69
+ end
70
+
71
+ # The options written with variables are made before anything is sent:
72
+ # a value that does not fit stops the request, whatever the answer.
73
+ SETTINGS = %i[timeout on_bad_code mime_type ok_code].freeze
63
74
 
64
75
  def auth = @context.definition.auth || {}
65
76
 
@@ -98,8 +109,8 @@ module ApiRecipes
98
109
  # with the optional addressable gem. Without the gem that is a LoadError,
99
110
  # which a server must not be able to cause: it becomes InvalidUrl. Any
100
111
  # other LoadError passes.
101
- def send_request(client, address, options)
102
- client.request(@definition.verb, address, **options)
112
+ def send_request(client, verb, address, options)
113
+ client.request(verb, address, **options)
103
114
  rescue LoadError => e
104
115
  raise unless e.path.to_s.start_with?('addressable')
105
116
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiRecipes
4
- VERSION = '3.0.0.beta3'
4
+ VERSION = '3.0.0.beta5'
5
5
  end
data/lib/api_recipes.rb CHANGED
@@ -8,6 +8,7 @@ require 'api_recipes/internals/credential'
8
8
  require 'api_recipes/internals/level'
9
9
  require 'api_recipes/internals/path_template'
10
10
  require 'api_recipes/internals/template'
11
+ require 'api_recipes/internals/option_value'
11
12
  require 'api_recipes/internals/plain_yaml'
12
13
  require 'api_recipes/internals/definition'
13
14
  require 'api_recipes/internals/compiler'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta3
4
+ version: 3.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato
@@ -57,6 +57,12 @@ files:
57
57
  - lib/api_recipes.rb
58
58
  - lib/api_recipes/api.rb
59
59
  - lib/api_recipes/cli.rb
60
+ - lib/api_recipes/cli/calls.rb
61
+ - lib/api_recipes/cli/code.rb
62
+ - lib/api_recipes/cli/convert.rb
63
+ - lib/api_recipes/cli/convert/migration.rb
64
+ - lib/api_recipes/cli/convert/snippet.rb
65
+ - lib/api_recipes/cli/description.rb
60
66
  - lib/api_recipes/cli/import.rb
61
67
  - lib/api_recipes/cli/import/document.rb
62
68
  - lib/api_recipes/cli/import/security.rb
@@ -68,7 +74,12 @@ files:
68
74
  - lib/api_recipes/cli/recipes/lock_file.rb
69
75
  - lib/api_recipes/cli/recipes/summary.rb
70
76
  - lib/api_recipes/cli/routes.rb
77
+ - lib/api_recipes/cli/tags.rb
71
78
  - lib/api_recipes/cli/upgrade.rb
79
+ - lib/api_recipes/cli/upgrade/fix.rb
80
+ - lib/api_recipes/cli/upgrade/project.rb
81
+ - lib/api_recipes/cli/upgrade/screen.rb
82
+ - lib/api_recipes/cli/upgrade/tree_rules.rb
72
83
  - lib/api_recipes/configuration.rb
73
84
  - lib/api_recipes/endpoint.rb
74
85
  - lib/api_recipes/errors.rb
@@ -79,6 +90,7 @@ files:
79
90
  - lib/api_recipes/internals/definition.rb
80
91
  - lib/api_recipes/internals/handles.rb
81
92
  - lib/api_recipes/internals/level.rb
93
+ - lib/api_recipes/internals/option_value.rb
82
94
  - lib/api_recipes/internals/path_template.rb
83
95
  - lib/api_recipes/internals/plain_yaml.rb
84
96
  - lib/api_recipes/internals/recipe.rb