lazy_ant 0.3.2 → 0.4.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
  SHA1:
3
- metadata.gz: 0e999de036bc2ae90ef795d8d5a51183589fe002
4
- data.tar.gz: 02ba4ae6a1829d1d34e5d6292a7aad90630ecf19
3
+ metadata.gz: 26098317ee3b2d85a22f413947081f79b46d3a10
4
+ data.tar.gz: a51b5237282e3e25e16fd81399df763f8997c871
5
5
  SHA512:
6
- metadata.gz: a256b14cdc5f59c913e92f4f29c55843475c7987e6c64cd81b852a70ca9f0c356919f347bb524612a4f36148f3f650b6f6ff48288e78a71fd084218883195236
7
- data.tar.gz: ac6fe3536c63fe34b80bbbc45f69409e884534975946bad74c696f719231254898e33bacada4a60359d436a498fd124d4012a60170f5de0891210df1fc544650
6
+ metadata.gz: b2a4199fcd6ef7108ecb322f5ad0ecfba4990ad20947fae836d89f568c7540c977d260a136aeee4c753a3a72cd03fd4b982dc797d73fda14e7e3381ce7cc2192
7
+ data.tar.gz: a770fd7c63460a97e75e2fdbb11a912e9e292bba92712de2f6fb59db10852021ed68fd6a11cf44613af635d2623afbcbe25cab45e0c8d2dc0a800a14665292d0
@@ -5,9 +5,11 @@ module LazyAnt
5
5
  module DSL
6
6
  module Connection
7
7
  extend ActiveSupport::Concern
8
+ attr_reader :default_params
8
9
 
9
10
  def connection
10
- @connection ||= Faraday.new(base_url) do |con|
11
+ return @connection if @connection
12
+ @connection = Faraday.new(base_url) do |con|
11
13
  con.request request_type
12
14
  use_converter(con)
13
15
  con.response response_type
@@ -15,6 +17,13 @@ module LazyAnt
15
17
  con.adapter Faraday.default_adapter
16
18
  instance_exec(con, &default_callback) if default_callback
17
19
  end
20
+ fix_params
21
+ end
22
+
23
+ def fix_params
24
+ @default_params = @connection.params.dup
25
+ @connection.params.clear
26
+ @connection
18
27
  end
19
28
 
20
29
  def use_converter(con)
@@ -8,6 +8,16 @@ module LazyAnt
8
8
  include DSL::Connection
9
9
  include Grouping
10
10
 
11
+ def update_params(req)
12
+ case req.method
13
+ when :get, :head, :delete
14
+ default_params.each { |k, v| req.params[k] = v }
15
+ when :post, :put
16
+ default_params.each { |k, v| req.body[k] = v }
17
+ end
18
+ yield(req) if block_given?
19
+ end
20
+
11
21
  module ClassMethods
12
22
  def api(name, options = {}, &block)
13
23
  method, path = endpoint(options)
@@ -15,7 +25,9 @@ module LazyAnt
15
25
  define_method name do |*args|
16
26
  params = args.extract_options!
17
27
  path = generate_url(path, args)
18
- response = connection.send(method, path, params, &block)
28
+ response = connection.send(method, path, params) do |req|
29
+ update_params(req, &block)
30
+ end
19
31
  converter.call(response.body)
20
32
  end
21
33
  end
@@ -1,3 +1,3 @@
1
1
  module LazyAnt
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_ant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki