api_client 0.1.2 → 0.1.3
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.
@@ -16,19 +16,19 @@ module ApiClient
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(id)
|
19
|
-
path
|
20
|
-
path
|
21
|
-
|
19
|
+
path = [@path, id].join('/')
|
20
|
+
path = append_format(path)
|
21
|
+
response = get(path)
|
22
22
|
scoped(self) do
|
23
|
-
@scopeable.build(
|
23
|
+
raw? ? response : @scopeable.build(response)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def find_all(params = {})
|
28
|
-
path
|
29
|
-
|
28
|
+
path = append_format(@path)
|
29
|
+
response = get(path, params)
|
30
30
|
scoped(self) do
|
31
|
-
@scopeable.build(
|
31
|
+
raw? ? response : @scopeable.build(response)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -41,7 +41,7 @@ module ApiClient
|
|
41
41
|
end
|
42
42
|
response = post(path, hash)
|
43
43
|
scoped(self) do
|
44
|
-
@scopeable.build(response)
|
44
|
+
raw? ? response : @scopeable.build(response)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -55,7 +55,7 @@ module ApiClient
|
|
55
55
|
end
|
56
56
|
response = put(path, hash)
|
57
57
|
scoped(self) do
|
58
|
-
@scopeable.build(response)
|
58
|
+
raw? ? response : @scopeable.build(response)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
data/lib/api_client/scope.rb
CHANGED
@@ -29,6 +29,15 @@ module ApiClient
|
|
29
29
|
@connection
|
30
30
|
end
|
31
31
|
|
32
|
+
def raw
|
33
|
+
@raw = true
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def raw?
|
38
|
+
!!@raw
|
39
|
+
end
|
40
|
+
|
32
41
|
# 3 Pillars of scoping
|
33
42
|
# options - passed on the the adapter
|
34
43
|
# params - converted to query or request body
|
@@ -63,7 +72,7 @@ module ApiClient
|
|
63
72
|
# Low-level connection methods
|
64
73
|
|
65
74
|
def request(method, path, options = {})
|
66
|
-
raw = options.delete(:raw)
|
75
|
+
raw = raw? || options.delete(:raw)
|
67
76
|
params(options)
|
68
77
|
response = connection.send method, path, @params, @headers
|
69
78
|
raw ? response : @scopeable.parse(response)
|
data/lib/api_client/version.rb
CHANGED
@@ -27,6 +27,13 @@ describe ApiClient::Resource::Scope do
|
|
27
27
|
result.id.should == 42
|
28
28
|
end
|
29
29
|
|
30
|
+
it "performs a find to fetch one record in raw mode" do
|
31
|
+
response = { "restful" => { "id" => 42 }}
|
32
|
+
@instance.should_receive(:get).with('/restfuls/1.json').and_return(response)
|
33
|
+
result = @instance.raw.find(1)
|
34
|
+
result.should == response
|
35
|
+
end
|
36
|
+
|
30
37
|
it "performs a find to fetch one record with a prefix if provided" do
|
31
38
|
@instance = ApiClient::Resource::Scope.new(Restful3)
|
32
39
|
response = { "restful3" => { "id" => 42 }}
|
@@ -48,6 +55,13 @@ describe ApiClient::Resource::Scope do
|
|
48
55
|
result.last.id.should == 112
|
49
56
|
end
|
50
57
|
|
58
|
+
it "performs a find_all to fetch many records in raw mode" do
|
59
|
+
response = [{ "restful" => { "id" => 42 } }, { "restful" => { "id" => 112 } }]
|
60
|
+
@instance.should_receive(:get).with('/restfuls.json', {}).and_return(response)
|
61
|
+
result = @instance.raw.find_all
|
62
|
+
result.should == response
|
63
|
+
end
|
64
|
+
|
51
65
|
it "performs a create to create a new record" do
|
52
66
|
response = { "restful" => { "id" => 42, "name" => "Foo" }}
|
53
67
|
@instance.should_receive(:post).with('/restfuls.json', {"restful" => {:name => "Foo"} }).and_return(response)
|
@@ -56,6 +70,13 @@ describe ApiClient::Resource::Scope do
|
|
56
70
|
result.id.should == 42
|
57
71
|
end
|
58
72
|
|
73
|
+
it "performs a create to create a new record in raw mode" do
|
74
|
+
response = { "restful" => { "id" => 42, "name" => "Foo" }}
|
75
|
+
@instance.should_receive(:post).with('/restfuls.json', {"restful" => {:name => "Foo"} }).and_return(response)
|
76
|
+
result = @instance.raw.create(:name => "Foo")
|
77
|
+
result.should == response
|
78
|
+
end
|
79
|
+
|
59
80
|
it "performs a create to create a new record skipping the namespace if it is not present" do
|
60
81
|
@instance = ApiClient::Resource::Scope.new(Restful2)
|
61
82
|
response = { "id" => 42, "name" => "Foo" }
|
@@ -73,6 +94,13 @@ describe ApiClient::Resource::Scope do
|
|
73
94
|
result.id.should == 42
|
74
95
|
end
|
75
96
|
|
97
|
+
it "performs a update to update an existing record in raw mode" do
|
98
|
+
response = { "restful" => { "id" => 42, "name" => "Foo" }}
|
99
|
+
@instance.should_receive(:put).with('/restfuls/42.json', {"restful" => {:name => "Foo"} }).and_return(response)
|
100
|
+
result = @instance.raw.update(42, :name => "Foo")
|
101
|
+
result.should == response
|
102
|
+
end
|
103
|
+
|
76
104
|
it "performs a update to update an existing record skipping the namespace if it is not present" do
|
77
105
|
@instance = ApiClient::Resource::Scope.new(Restful2)
|
78
106
|
response = { "id" => 42, "name" => "Foo" }
|
@@ -82,8 +110,6 @@ describe ApiClient::Resource::Scope do
|
|
82
110
|
result.id.should == 42
|
83
111
|
end
|
84
112
|
|
85
|
-
|
86
|
-
|
87
113
|
it "performs a destroy to remove a record" do
|
88
114
|
response = { "restful" => { "id" => 42, "name" => "Foo" }}
|
89
115
|
@instance.should_receive(:delete).with('/restfuls/42.json').and_return(response)
|
@@ -103,9 +103,11 @@ describe ApiClient::Scope do
|
|
103
103
|
instance = ApiClient::Scope.new(ApiClient::Base)
|
104
104
|
instance.stub(:connection).and_return(connection)
|
105
105
|
response = Faraday::Response.new(:body => '{"a": "1"}')
|
106
|
-
connection.should_receive(:get).with(@path, @params, @headers).and_return(response)
|
106
|
+
connection.should_receive(:get).twice.with(@path, @params, @headers).and_return(response)
|
107
107
|
result = instance.params(@params).headers(@headers).request(:get, @path, :raw => true)
|
108
108
|
result.should == response
|
109
|
+
result = instance.raw.params(@params).headers(@headers).request(:get, @path)
|
110
|
+
result.should == response
|
109
111
|
end
|
110
112
|
|
111
113
|
it "makes a GET request" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70184951743680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.7.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70184951743680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &70184951743180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70184951743180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yajl-ruby
|
38
|
-
requirement: &
|
38
|
+
requirement: &70184951742800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70184951742800
|
47
47
|
description: API client builder
|
48
48
|
email:
|
49
49
|
- marcin@futuresimple.com
|