clientele 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clientele/api.rb +4 -0
- data/lib/clientele/request.rb +1 -3
- data/lib/clientele/request_builder.rb +27 -12
- data/lib/clientele/resource.rb +4 -2
- data/lib/clientele/resource/pagination.rb +8 -7
- data/lib/clientele/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6582c99553295f93676db28a306f47c12a618c24
|
4
|
+
data.tar.gz: 981a484ad7dda1988ec60df5a2cd1c6a1f82d992
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f63be792b186af675a00945ff1e999813dfabfd4e8c6bbcf09a98f901b2ae8081971061a4da5adb29f74fd6764c0d58c445048ae062c7c9db78b534d4eba1f94
|
7
|
+
data.tar.gz: 7524c40b6373d57b3745e423f5fd9afead437495fab9d5356b580b33c54a80a6a445358caca7df0b2dafac32303f683b80c12a676847a6125db131f9c0983767
|
data/lib/clientele/api.rb
CHANGED
data/lib/clientele/request.rb
CHANGED
@@ -74,8 +74,6 @@ module Clientele
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
-
def paginateable?; false; end
|
78
|
-
|
79
77
|
private
|
80
78
|
|
81
79
|
def result
|
@@ -98,7 +96,7 @@ module Clientele
|
|
98
96
|
conn.request :url_encoded
|
99
97
|
|
100
98
|
conn.response :rashify
|
101
|
-
conn.response :logger
|
99
|
+
conn.response :logger, options[:logger], bodies: true
|
102
100
|
conn.response :json, content_type: options[:hashify_content_type], preserve_raw: true
|
103
101
|
|
104
102
|
conn.adapter options[:adapter] if options[:adapter]
|
@@ -6,7 +6,6 @@ module Clientele
|
|
6
6
|
include Clientele::Utils
|
7
7
|
include Enumerable
|
8
8
|
attr_accessor :stack, :client
|
9
|
-
alias_method :to_a, :stack
|
10
9
|
|
11
10
|
def initialize(*request_components, client: API.client)
|
12
11
|
@stack = request_components.flatten
|
@@ -52,28 +51,44 @@ module Clientele
|
|
52
51
|
merge_paths(stack.map(&:path))
|
53
52
|
end
|
54
53
|
|
55
|
-
def paginateable?; false; end
|
56
|
-
|
57
54
|
private
|
58
55
|
|
59
56
|
def method_missing(method_name, *args, &block)
|
60
|
-
if
|
61
|
-
|
62
|
-
elsif client.
|
63
|
-
|
64
|
-
elsif
|
65
|
-
|
57
|
+
if chain.respond_to? method_name, :public
|
58
|
+
chain_method method_name, *args, &block
|
59
|
+
elsif client.has_resource? method_name
|
60
|
+
chain_resource method_name
|
61
|
+
elsif should_paginate? method_name
|
62
|
+
chain.send :each, build, &block
|
66
63
|
else; super; end
|
67
64
|
end
|
68
65
|
|
69
66
|
def respond_to_missing?(method_name, include_private=false)
|
70
|
-
|
71
|
-
or
|
67
|
+
chain.respond_to? method_name, :public \
|
68
|
+
or client.has_resource? method_name \
|
69
|
+
or should_paginate? method_name \
|
72
70
|
or super
|
73
71
|
end
|
74
72
|
|
73
|
+
def chain
|
74
|
+
stack.last
|
75
|
+
end
|
76
|
+
|
77
|
+
def chain_method(method_name, *args, &block)
|
78
|
+
stack << stack.pop.send(method_name, *args, &block) and self
|
79
|
+
end
|
80
|
+
|
81
|
+
def chain_resource(resource_name)
|
82
|
+
stack << client.resources[method_name.to_s] and self
|
83
|
+
end
|
84
|
+
|
85
|
+
def should_paginate?(method_name)
|
86
|
+
chain.instance_variable_get :@paginateable \
|
87
|
+
and enumberable_methods.include? method_name
|
88
|
+
end
|
89
|
+
|
75
90
|
def enumberable_methods
|
76
|
-
Enumerable.instance_methods - Module.instance_methods
|
91
|
+
Enumerable.instance_methods - Module.instance_methods << :each
|
77
92
|
end
|
78
93
|
|
79
94
|
end
|
data/lib/clientele/resource.rb
CHANGED
@@ -66,6 +66,10 @@ module Clientele
|
|
66
66
|
@nested_plural_key || plural_key
|
67
67
|
end
|
68
68
|
|
69
|
+
def nested_plural_key
|
70
|
+
@nested_plural_key || plural_key
|
71
|
+
end
|
72
|
+
|
69
73
|
def build(data, client: nil, response: nil)
|
70
74
|
new(
|
71
75
|
catch(:build) do
|
@@ -89,8 +93,6 @@ module Clientele
|
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
92
|
-
def paginateable?; false; end
|
93
|
-
|
94
96
|
private
|
95
97
|
|
96
98
|
def inherited(base)
|
@@ -23,16 +23,16 @@ module Clientele
|
|
23
23
|
Proc.new do
|
24
24
|
|
25
25
|
def next_page(request)
|
26
|
-
request.query[:page] ||=
|
26
|
+
request.query[:page] ||= 1
|
27
27
|
request.query[:page] += 1
|
28
28
|
end
|
29
29
|
|
30
|
-
def total(
|
31
|
-
response.headers
|
30
|
+
def total(result)
|
31
|
+
Integer(result.response.headers['x-total-count']) or Float::INFINITY
|
32
32
|
end
|
33
33
|
|
34
|
-
def pages(
|
35
|
-
|
34
|
+
def pages(result)
|
35
|
+
result
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module Clientele
|
|
40
40
|
|
41
41
|
module Iterator
|
42
42
|
|
43
|
-
|
43
|
+
@paginateable = true
|
44
44
|
|
45
45
|
def each(request = self.to_request)
|
46
46
|
return enum_for(:each, request) unless block_given?
|
@@ -50,9 +50,10 @@ module Clientele
|
|
50
50
|
|
51
51
|
until counter == total(current_response) do
|
52
52
|
if pages(current_response).empty?
|
53
|
-
current_response = request.tap do |
|
53
|
+
current_response = request.tap do |request|
|
54
54
|
next_page(request)
|
55
55
|
end.call
|
56
|
+
|
56
57
|
else
|
57
58
|
counter +=1
|
58
59
|
yield pages(current_response).shift
|
data/lib/clientele/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clientele
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Keele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|