consumer 0.1.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/lib/consumer/version.rb +1 -1
- data/lib/consumer.rb +7 -1
- data/spec/consumer_spec.rb +18 -0
- data/spec/fixtures/array.json +82 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 382b551fc46684e01dc949ab99234a4d95ada0b1
|
4
|
+
data.tar.gz: cb33d7142a0cf0e14f8feb40ab32bea87c777ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdac72417c7cd806cd423ba3a71edaba3606f4d40c9f283c25082771803fdc625f78582ea6e25b9f8e47c52875b8174c89cf152059097e2d83a68a05cdd861a1
|
7
|
+
data.tar.gz: 64c9b2e3b8a1cf468b04d5f6c5d287da2f5fae3209413b9d67570ea1e8e923b6d8d058aa81efa6d6ce795b95888a2542366d0a4175f18819ae1fa534f2c114b6
|
data/Gemfile.lock
CHANGED
data/lib/consumer/version.rb
CHANGED
data/lib/consumer.rb
CHANGED
@@ -8,7 +8,13 @@ module Consumer
|
|
8
8
|
def self.get(url)
|
9
9
|
json = open(url).read
|
10
10
|
hash = JSON.parse(json)
|
11
|
-
|
11
|
+
|
12
|
+
build(hash)
|
12
13
|
end
|
13
14
|
|
15
|
+
def self.build(hash)
|
16
|
+
hash.is_a?(Array) ?
|
17
|
+
hash.map { |h| Consumer::Proxy.new(h)} :
|
18
|
+
Consumer::Proxy.new(hash)
|
19
|
+
end
|
14
20
|
end
|
data/spec/consumer_spec.rb
CHANGED
@@ -105,4 +105,22 @@ describe Consumer do
|
|
105
105
|
it { expect(subject.link("externo")).to be_nil }
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
context "when first node is an array" do
|
110
|
+
let(:url) { "http://mock.url/feed_test" }
|
111
|
+
before { register_uri(:get, url, body: fixture("array.json")) }
|
112
|
+
subject { described_class.get(url) }
|
113
|
+
|
114
|
+
it { expect(subject).to be_instance_of Array }
|
115
|
+
its(:size) { should eq 10 }
|
116
|
+
|
117
|
+
context "#first" do
|
118
|
+
def subject; super.first; end;
|
119
|
+
|
120
|
+
its(:id) { should eq "http://localhost:3000/users/1" }
|
121
|
+
its(:name) { should eq "Tester" }
|
122
|
+
its(:email) { should eq "test@gmail.com" }
|
123
|
+
its(:posts) { should eq [] }
|
124
|
+
end
|
125
|
+
end
|
108
126
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "http://localhost:3000/users/1",
|
4
|
+
"name": "Tester",
|
5
|
+
"email": "test@gmail.com",
|
6
|
+
"posts": [
|
7
|
+
|
8
|
+
]
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"id": "http://localhost:3000/users/2",
|
12
|
+
"name": "Tester",
|
13
|
+
"email": "sylvan@veumsatterfield.com",
|
14
|
+
"posts": [
|
15
|
+
|
16
|
+
]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"id": "http://localhost:3000/users/3",
|
20
|
+
"name": "Tester",
|
21
|
+
"email": "dell@huel.biz",
|
22
|
+
"posts": [
|
23
|
+
|
24
|
+
]
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"id": "http://localhost:3000/users/4",
|
28
|
+
"name": "Tester",
|
29
|
+
"email": "hayden_dach@collins.biz",
|
30
|
+
"posts": [
|
31
|
+
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": "http://localhost:3000/users/5",
|
36
|
+
"name": "Tester",
|
37
|
+
"email": "jovanny.anderson@batz.net",
|
38
|
+
"posts": [
|
39
|
+
|
40
|
+
]
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"id": "http://localhost:3000/users/6",
|
44
|
+
"name": "Tester",
|
45
|
+
"email": "caden_bauch@parisian.name",
|
46
|
+
"posts": [
|
47
|
+
|
48
|
+
]
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"id": "http://localhost:3000/users/7",
|
52
|
+
"name": "Tester",
|
53
|
+
"email": "gordon@metzhoeger.info",
|
54
|
+
"posts": [
|
55
|
+
|
56
|
+
]
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"id": "http://localhost:3000/users/8",
|
60
|
+
"name": "Tester",
|
61
|
+
"email": "sharon@mueller.info",
|
62
|
+
"posts": [
|
63
|
+
|
64
|
+
]
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"id": "http://localhost:3000/users/9",
|
68
|
+
"name": "Tester",
|
69
|
+
"email": "haskell_kirlin@stamm.com",
|
70
|
+
"posts": [
|
71
|
+
|
72
|
+
]
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"id": "http://localhost:3000/users/10",
|
76
|
+
"name": "Tester",
|
77
|
+
"email": "rosalyn@kiehn.biz",
|
78
|
+
"posts": [
|
79
|
+
|
80
|
+
]
|
81
|
+
}
|
82
|
+
]
|
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/consumer/proxy.rb
|
115
115
|
- lib/consumer/version.rb
|
116
116
|
- spec/consumer_spec.rb
|
117
|
+
- spec/fixtures/array.json
|
117
118
|
- spec/fixtures/example.json
|
118
119
|
- spec/fixtures/link.json
|
119
120
|
- spec/spec_helper.rb
|
@@ -137,12 +138,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.4.5
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: Simple gem to consume json api
|
144
145
|
test_files:
|
145
146
|
- spec/consumer_spec.rb
|
147
|
+
- spec/fixtures/array.json
|
146
148
|
- spec/fixtures/example.json
|
147
149
|
- spec/fixtures/link.json
|
148
150
|
- spec/spec_helper.rb
|