lazy_ant 0.3.2 → 0.4.0
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.
- checksums.yaml +4 -4
- data/lib/lazy_ant/dsl/connection.rb +10 -1
- data/lib/lazy_ant/dsl/endpoint.rb +13 -1
- data/lib/lazy_ant/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26098317ee3b2d85a22f413947081f79b46d3a10
|
4
|
+
data.tar.gz: a51b5237282e3e25e16fd81399df763f8997c871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
data/lib/lazy_ant/version.rb
CHANGED