api_recipes 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee06dcfdc43e19eeb0e2c101061fcae81cbdcd426911ba44c7b78ead44800e12
4
- data.tar.gz: 2a53571c7b048774579c9132b9ef89a52a674ff2818d16e46be0b5ffcf4c1829
3
+ metadata.gz: c808d9077305dc07cd888f517b57f1522490866a548dc769a3c96c083d24ce27
4
+ data.tar.gz: 205b4aaaa135b8682f7d7f0d44f471263852e997f2b1791fe60eea4efc0a2ee3
5
5
  SHA512:
6
- metadata.gz: 5aa6283219f68dad431806374fa7dbba514c3ec05e6c1d0bf9b10b59ce0df41f0cfb617f107067aba90ac3e64e830874e286c5ccfdd0a92d54230fa1f648fbcb
7
- data.tar.gz: 34e77a1d6e67185bdbe884a42c8e92de8bc1bd6922f01dbefcd7cbaaf91855ac7f19ec260314cf391c8c011c0174393e994f7500d80d39b36c0a40079b8e208b
6
+ metadata.gz: 89acbd66ece24f8cd88100eb447c45e3b73c30c9f894b51a5995aa7697f6a76b92bae0b41c117dbc0b38f993876ca8b4efd17f64eaf7ca1ae31e0d04b5544120
7
+ data.tar.gz: a831d53f7a337cc65ec28d09eb74ca8efa69123cf34ae835776c5414dd58725cc0223e7ee7aa70d0c1dbbebfff924f8d3d8340227ade47f42d7be4e3ffd877dd
@@ -4,7 +4,7 @@ module ApiRecipes
4
4
  attr_accessor :name, :configs, :authorization, :basic_auth
5
5
  attr_reader :base_configs, :object
6
6
 
7
- BASE_CONFIGS_KEYS = [:protocol, :host, :port, :api_version, :timeout, :on_bad_code, :verify_with]
7
+ BASE_CONFIGS_KEYS = [:protocol, :host, :port, :api_version, :timeout, :on_bad_code, :mime_type, :verify_with]
8
8
 
9
9
  def initialize(name, configs, object)
10
10
  @name = name
@@ -1,12 +1,15 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+
1
4
  module ApiRecipes
2
5
  class Configuration
3
6
 
4
- attr_accessor :log_to, :log_level, :print_urls
7
+ attr_accessor :log_to, :log_level, :print_urls, :apis_files_paths
5
8
 
6
9
  def apis_configs=(configs = {})
7
10
  raise ArgumentError, 'apis_configs must be an Hash' unless configs.is_a? Hash
11
+
8
12
  @apis_configs = configs.deep_symbolize_keys
9
- ApiRecipes._aprcps_define_global_apis
10
13
  end
11
14
 
12
15
  def apis_configs
@@ -16,6 +19,34 @@ module ApiRecipes
16
19
  @apis_configs
17
20
  end
18
21
 
22
+ def apis_files_paths=(paths = [])
23
+ raise ArgumentError, 'apis_files_paths must be an Array' unless paths.is_a? Array
24
+
25
+ @apis_files_paths = paths
26
+ @apis_files_paths.each do |file_path|
27
+ template = ERB.new File.read File.expand_path(file_path)
28
+ data = begin
29
+ YAML.load(template.result(binding), aliases: true)
30
+ rescue ArgumentError
31
+ YAML.load(template.result binding)
32
+ end.deep_symbolize_keys
33
+ # Merge file contents into apis_configs
34
+ data.each do |api, params|
35
+ if apis_configs[api]
36
+ logger.warn "File at #{file_path} overrides config for '#{api}' API"
37
+ end
38
+ apis_configs[api] = params
39
+ end
40
+ end
41
+ end
42
+
43
+ def apis_files_paths
44
+ unless @apis_files_paths
45
+ @apis_files_paths = []
46
+ end
47
+ @apis_files_paths
48
+ end
49
+
19
50
  def logger=(logger)
20
51
  @logger = logger
21
52
  end
@@ -31,6 +62,10 @@ module ApiRecipes
31
62
  @logger
32
63
  end
33
64
 
65
+ def setup
66
+ ApiRecipes._aprcps_define_global_apis
67
+ end
68
+
34
69
  private
35
70
 
36
71
  # @private
@@ -62,7 +62,6 @@ module ApiRecipes
62
62
  end
63
63
  end
64
64
  end
65
- # Route.new(api: @api, endpoint: self, name: route_name, attributes: route_attrs, req_pars: request_params).start_request &block
66
65
  end
67
66
 
68
67
  def ensure_route_does_not_clash(route_name)
@@ -12,7 +12,7 @@ module ApiRecipes
12
12
  return @data unless @data.nil?
13
13
 
14
14
  # TODO: rescue nil?
15
- @data = @original_response.parse
15
+ @data = @original_response.parse @attributes[:mime_type]
16
16
  end
17
17
 
18
18
  # Forward method calls to 'original' Response class
@@ -16,7 +16,7 @@ module ApiRecipes
16
16
  end
17
17
 
18
18
  def fill(object)
19
- data = @response.parse
19
+ data = @response.parse @attributes[:mime_type]
20
20
  if block_given?
21
21
  tap do
22
22
  try_to_fill object, data
@@ -10,7 +10,8 @@ module ApiRecipes
10
10
  timeout: 3,
11
11
  on_bad_code: 'raise',
12
12
  endpoints: {},
13
- verify_with: nil
13
+ verify_with: nil,
14
+ mime_type: nil
14
15
  }
15
16
 
16
17
  DEFAULT_ROUTE_ATTRIBUTES = {
@@ -20,6 +21,7 @@ module ApiRecipes
20
21
  ok_code: nil,
21
22
  timeout: DEFAULT[:timeout],
22
23
  on_bad_code: DEFAULT[:on_bad_code],
24
+ mime_type: DEFAULT[:mime_type],
23
25
  verify_with: DEFAULT[:verify_with]
24
26
  }
25
27
 
@@ -1,3 +1,3 @@
1
1
  module ApiRecipes
2
- VERSION = '2.9.0'.freeze
2
+ VERSION = '2.10.0'.freeze
3
3
  end
data/lib/api_recipes.rb CHANGED
@@ -65,6 +65,7 @@ module ApiRecipes
65
65
  def self.configure
66
66
  if block_given?
67
67
  yield(configuration)
68
+ configuration.setup
68
69
  else
69
70
  configuration
70
71
  end
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: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.0.9
71
+ rubygems_version: 3.3.7
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Consume HTTP APIs with style