lazy_ant 0.1.1 → 0.1.2

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: abfeb5915e5c186490911ea77856e51ded40b3ed
4
- data.tar.gz: 48c5636686ee764237097a5067fce4456cf6778f
3
+ metadata.gz: b225ea24eeb79986e6fc479711d71d75f83a96f6
4
+ data.tar.gz: 96c679f3c3e75d92d3f53cc8c1f7a2847ee38e89
5
5
  SHA512:
6
- metadata.gz: ce478952b5d53ba6cf90659c1a8fb6ec451066da63f3ff673bfadb85b09e414524741a13d818b0bab49a77b25ad7ddb316ae2774329be54d95a36daac6e3284c
7
- data.tar.gz: 2163d3a223567bdbfb2a29130c8c79203049a215f301060c7b3c7cdee528d622b1693224894fe0fd4c2c98e2c92d5772a9d21aa4187aae23563bc106ccc2d637
6
+ metadata.gz: 08269dd649cf7ae104327c0b6a52de1493b7f62c4cf9e1bd07e7b8063c80e6585530886348cb0ad6e0b314e45697e273783699cee0bbe806c7877415311964b1
7
+ data.tar.gz: 5504fbfa88965167eff8794db477c12e85e1b567206a4be43efb155d629a70889583a38b8ffa2d8dab35aa37121c8f6c49534f5106f82a0e890e2c01a1c127ee
@@ -10,6 +10,7 @@ module LazyAnt
10
10
  @connection ||= Faraday.new(base_url) do |con|
11
11
  con.request :url_encoded
12
12
  con.request :json
13
+ con.response converter_name if converter_name
13
14
  con.response :json
14
15
  con.response :raise_error
15
16
  con.adapter Faraday.default_adapter
@@ -21,6 +22,10 @@ module LazyAnt
21
22
  self.class.instance_variable_get(:@default_callback)
22
23
  end
23
24
 
25
+ def converter_name
26
+ self.class.instance_variable_get(:@converter_name)
27
+ end
28
+
24
29
  module ClassMethods
25
30
  def base_url(url = nil, &block)
26
31
  if block_given?
@@ -34,6 +39,10 @@ module LazyAnt
34
39
  end
35
40
  end
36
41
 
42
+ def converter(name)
43
+ @converter_name = name
44
+ end
45
+
37
46
  def connection(&block)
38
47
  @default_callback = block
39
48
  end
@@ -11,12 +11,12 @@ module LazyAnt
11
11
  module ClassMethods
12
12
  def api(name, options = {})
13
13
  method, path = endpoint(options)
14
- conv = converter(options)
14
+ converter = entity_converter(options)
15
15
  define_method name do |*args|
16
16
  params = args.extract_options!
17
17
  path = generate_url(path, args)
18
18
  response = connection.send(method, path, params)
19
- conv.call(response.body)
19
+ converter.call(response.body)
20
20
  end
21
21
  end
22
22
 
@@ -29,7 +29,7 @@ module LazyAnt
29
29
  [method, path]
30
30
  end
31
31
 
32
- def converter(entity: nil, multi: false)
32
+ def entity_converter(entity: nil, multi: false)
33
33
  conv = entity ? ->(x) { entity.new(x) } : ->(x) { x }
34
34
  multi ? -> (x) { x.map(&conv) } : -> (x) { conv.call(x) }
35
35
  end
@@ -1,3 +1,3 @@
1
1
  module LazyAnt
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_ant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport