consumer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/consumer/proxy.rb +8 -0
- data/lib/consumer/version.rb +1 -1
- data/spec/consumer_spec.rb +69 -37
- data/spec/fixtures/example.json +26 -0
- data/spec/fixtures/link.json +12 -0
- data/spec/spec_helper.rb +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1030e7427ab1393c68f0f03b306b841e237c3eed
|
4
|
+
data.tar.gz: 4f6630aae34aac32caee6c9ef0b449233a823b42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 137ec48b052e6fda33489b30988724b83ec96b423d2e008304854971bab427ff8c02563e34adc4b04bf404c097b0028cdcba49ab7c1abe755402197a99f0ee48
|
7
|
+
data.tar.gz: 2a21fb9f0f11365fe65e66bcb02096aa66ce29b735a865179bbf2f1d425514d20449553877d46014ecefe84d53c62f53131ea4dc7cfb530886a740eb83cc46cb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/consumer/proxy.rb
CHANGED
@@ -11,6 +11,14 @@ module Consumer
|
|
11
11
|
return methodize_me(self[_method])
|
12
12
|
end
|
13
13
|
|
14
|
+
def link(rel)
|
15
|
+
_link = self["link"] || self["links"]
|
16
|
+
_link = [_link].flatten
|
17
|
+
_link = _link.find {|l| l.is_a?(Hash) and l["rel"] == rel }
|
18
|
+
|
19
|
+
methodize_me(_link)
|
20
|
+
end
|
21
|
+
|
14
22
|
def respond_to?(method)
|
15
23
|
self.has_key?(method.to_s) or super
|
16
24
|
end
|
data/lib/consumer/version.rb
CHANGED
data/spec/consumer_spec.rb
CHANGED
@@ -2,44 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Consumer do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
{
|
7
|
-
|
8
|
-
"first_item" => "item 1",
|
9
|
-
"second" => "item 2",
|
10
|
-
"third" => 3,
|
11
|
-
"fourthly" => nil,
|
12
|
-
"array" => [ {
|
13
|
-
"item1" => "test 1",
|
14
|
-
"item2" => "test 2"
|
15
|
-
},
|
16
|
-
{
|
17
|
-
"item3" => "test 3",
|
18
|
-
"item4" => "test 4"
|
19
|
-
} ],
|
20
|
-
"child_hash" => {
|
21
|
-
"hash1" => "value 1",
|
22
|
-
"hash2" => "value 2",
|
23
|
-
"array1" => [1,2,3]
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:url) { "http://mock.url/feed_test" }
|
29
|
-
before { register_uri(:get, url, body: hash.to_json) }
|
30
|
-
subject { described_class.get(url) }
|
5
|
+
let(:url) { "http://mock.url/feed_test" }
|
6
|
+
before { register_uri(:get, url, body: fixture("example.json")) }
|
7
|
+
subject { described_class.get(url) }
|
31
8
|
|
32
|
-
its(:id)
|
33
|
-
its(:first_item)
|
34
|
-
its(:second)
|
35
|
-
its(:third)
|
36
|
-
its(:fourthly)
|
9
|
+
its(:id) { should == "0ffe01" }
|
10
|
+
its(:first_item) { should == "item 1" }
|
11
|
+
its(:second) { should == "item 2" }
|
12
|
+
its(:third) { should == 3 }
|
13
|
+
its(:fourthly) { should be_nil }
|
37
14
|
|
38
|
-
it { expect(subject.respond_to?(:id)).to be_truthy
|
39
|
-
it { expect(subject.respond_to?(:first_item)).to be_truthy
|
40
|
-
it { expect(subject.respond_to?(:second)).to be_truthy
|
41
|
-
it { expect(subject.respond_to?(:third)).to be_truthy
|
42
|
-
it { expect(subject.respond_to?(:fourthly)).to be_truthy
|
15
|
+
it { expect(subject.respond_to?(:id)).to be_truthy }
|
16
|
+
it { expect(subject.respond_to?(:first_item)).to be_truthy }
|
17
|
+
it { expect(subject.respond_to?(:second)).to be_truthy }
|
18
|
+
it { expect(subject.respond_to?(:third)).to be_truthy }
|
19
|
+
it { expect(subject.respond_to?(:fourthly)).to be_truthy }
|
43
20
|
|
44
21
|
it { expect(subject.array).to be_a Array }
|
45
22
|
it { expect(subject.array.size).to eq(2) }
|
@@ -70,5 +47,60 @@ describe Consumer do
|
|
70
47
|
it { expect(subject.respond_to?(:fifth)).to be_falsey }
|
71
48
|
it { expect(subject.respond_to?(:class)).to be_truthy }
|
72
49
|
|
73
|
-
it { expect(subject).to eq(
|
50
|
+
it { expect(subject).to eq(JSON.parse(fixture("example.json"))) }
|
51
|
+
|
52
|
+
describe "#link" do
|
53
|
+
shared_examples_for "first item" do
|
54
|
+
it { expect(subject.link("interno").rel).to eq("interno") }
|
55
|
+
it { expect(subject.link("interno").href).to eq("http://url-interna") }
|
56
|
+
it { expect(subject.link("interno").type).to eq("image/jpeg") }
|
57
|
+
end
|
58
|
+
|
59
|
+
shared_examples_for "second item" do
|
60
|
+
it { expect(subject.link("externo").rel).to eq("externo") }
|
61
|
+
it { expect(subject.link("externo").href).to eq("http://url-externa") }
|
62
|
+
it { expect(subject.link("externo").type).to eq("image/jpeg") }
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:example) { JSON.parse(fixture('link.json')) }
|
66
|
+
|
67
|
+
let(:url) { "http://mock.url/feed_with_link" }
|
68
|
+
before { register_uri(:get, url, body: link.to_json) }
|
69
|
+
subject { described_class.get(url) }
|
70
|
+
|
71
|
+
context "when node is links" do
|
72
|
+
context "when is an array" do
|
73
|
+
let(:link) { {"links" => example } }
|
74
|
+
it_behaves_like "first item"
|
75
|
+
it_behaves_like "second item"
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when is a hash" do
|
79
|
+
let(:link) { {"links" => example.first } }
|
80
|
+
it_behaves_like "first item"
|
81
|
+
it { expect(subject.link("externo")).to be_nil }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when node is link" do
|
86
|
+
context "when is an array" do
|
87
|
+
let(:link) { {"link" => example } }
|
88
|
+
it_behaves_like "first item"
|
89
|
+
it_behaves_like "second item"
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when is a hash" do
|
93
|
+
let(:link) { {"link" => example.first } }
|
94
|
+
it_behaves_like "first item"
|
95
|
+
it { expect(subject.link("externo")).to be_nil }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when doesnt exists link node" do
|
100
|
+
let(:link) { {} }
|
101
|
+
|
102
|
+
it { expect(subject.link("interno")).to be_nil }
|
103
|
+
it { expect(subject.link("externo")).to be_nil }
|
104
|
+
end
|
105
|
+
end
|
74
106
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"id": "0ffe01",
|
3
|
+
"first_item": "item 1",
|
4
|
+
"second": "item 2",
|
5
|
+
"third": 3,
|
6
|
+
"fourthly": null,
|
7
|
+
"array": [
|
8
|
+
{
|
9
|
+
"item1": "test 1",
|
10
|
+
"item2": "test 2"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"item3": "test 3",
|
14
|
+
"item4": "test 4"
|
15
|
+
}
|
16
|
+
],
|
17
|
+
"child_hash": {
|
18
|
+
"hash1": "value 1",
|
19
|
+
"hash2": "value 2",
|
20
|
+
"array1": [
|
21
|
+
1,
|
22
|
+
2,
|
23
|
+
3
|
24
|
+
]
|
25
|
+
}
|
26
|
+
}
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consumer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,8 @@ files:
|
|
114
114
|
- lib/consumer/proxy.rb
|
115
115
|
- lib/consumer/version.rb
|
116
116
|
- spec/consumer_spec.rb
|
117
|
+
- spec/fixtures/example.json
|
118
|
+
- spec/fixtures/link.json
|
117
119
|
- spec/spec_helper.rb
|
118
120
|
homepage: ''
|
119
121
|
licenses:
|
@@ -141,4 +143,6 @@ specification_version: 4
|
|
141
143
|
summary: Simple gem to consume json api
|
142
144
|
test_files:
|
143
145
|
- spec/consumer_spec.rb
|
146
|
+
- spec/fixtures/example.json
|
147
|
+
- spec/fixtures/link.json
|
144
148
|
- spec/spec_helper.rb
|