supercamp 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dba108960b355a8c635e29d37344a702a874dc0f
4
- data.tar.gz: 103109c66ecc53341bb04cba71cbeee82a9e9260
3
+ metadata.gz: 952fe20db12be83b031aa1bc4edc27720034ae2e
4
+ data.tar.gz: e2f724ad9475b0d9fd82aae23df1a6c226590a76
5
5
  SHA512:
6
- metadata.gz: 36927842aa84a87d326430316d7bd5a67e26d838d4a5d1b684fabe217dca42a8d0a82f8b100381e5a981443d33d0831b09936492c8e276ac3ec049fef9ddb5dd
7
- data.tar.gz: 9627ec1aa2954199a813208e4f4b42099ea07c1104be9ff95cd1edf64895cfdad588de778b81be8f0f2d0057549fea73768a28616768989fcdc4ef3f86681863
6
+ metadata.gz: dc520822f8f1b4b3bf8f003b4bab5f1fffc2696b0f13178f264955ff72fbf2a0d1e4bcb7e9b68571be8530763c552761f385029fc064042e5433be6e737d683e
7
+ data.tar.gz: 2c93851c2139dc2408166e8d4ec94a226f9c5675b1f3c608da2475ac2b96799b9620650b4ce6561e81e06b7422471abe8f8f7275ee7e7e79cf1a8d867dfab0c3
@@ -3,7 +3,8 @@ module Supercamp
3
3
 
4
4
  class Abstract
5
5
 
6
- attr_accessor :options
6
+ attr_reader :options
7
+ attr_writer :response
7
8
 
8
9
  def initialize(&block)
9
10
  @options = {}
@@ -33,18 +34,32 @@ module Supercamp
33
34
  end
34
35
 
35
36
  def response(query=query)
37
+ return @response unless @response.nil?
36
38
  response = query.run
37
39
  if response.code == 200
38
- Supercamp::Response.new response
40
+ @response = Supercamp::Response.new response
41
+ @response.freeze
39
42
  else
40
43
  raise Supercamp::Error.new self, response
41
44
  end
42
45
  end
43
46
 
47
+ def count
48
+ response.count
49
+ end
50
+
51
+ def results
52
+ response.results
53
+ end
54
+
44
55
  private
45
56
 
46
57
  def merge_option(key, value)
47
- @options[key.to_s] = value
58
+ @options.dup.merge({ key.to_s => value }).tap do |opts|
59
+ @options = opts
60
+ @response = nil
61
+ @options.freeze
62
+ end
48
63
  end
49
64
 
50
65
  end
@@ -8,6 +8,8 @@ module Supercamp
8
8
  attr_reader :count
9
9
  attr_reader :entries
10
10
 
11
+ alias_method :results, :entries
12
+
11
13
  def initialize(response)
12
14
  p = parse_response(response.body)
13
15
 
@@ -1,3 +1,3 @@
1
1
  module Supercamp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,11 +19,15 @@ describe Supercamp::Criteria::Abstract do
19
19
  end
20
20
  end
21
21
 
22
- it "please?" do
22
+ it "sets API options hash" do
23
23
  expect(criteria.options).to eq \
24
24
  ({ "pname" => "Camp Cool", "pets" => 3010 })
25
25
  end
26
26
 
27
+ it "freezes :options" do
28
+ expect(criteria.options).to be_frozen
29
+ end
30
+
27
31
  end
28
32
 
29
33
  end
@@ -57,7 +61,7 @@ describe Supercamp::Criteria::Abstract do
57
61
  end
58
62
  end
59
63
 
60
- it "please?" do
64
+ it "sets API :options" do
61
65
  expect(criteria.options).to eq \
62
66
  ({ "pname" => "Camp Cool", "pets" => 3010 })
63
67
  end
@@ -68,6 +72,7 @@ describe Supercamp::Criteria::Abstract do
68
72
 
69
73
  end
70
74
 
75
+
71
76
  describe "#endpoint" do
72
77
  it { expect(subject.endpoint).to eq "http://api.amp.active.com/camping/abstracts" }
73
78
  end
@@ -87,7 +92,7 @@ describe Supercamp::Criteria::Abstract do
87
92
 
88
93
  let :criteria do
89
94
  subject.tap do |s|
90
- s.options = { pname: "Jolly Good" }
95
+ expect(s).to receive(:options).and_return({ pname: "Jolly Good" })
91
96
  end
92
97
  end
93
98
 
@@ -106,7 +111,8 @@ describe Supercamp::Criteria::Abstract do
106
111
 
107
112
  let :criteria do
108
113
  subject.tap do |s|
109
- s.options = { pname: "Jolly Good", amenity: 4001, water: 3007, pets: 3010 }
114
+ expect(s).to receive(:options).and_return \
115
+ ({ pname: "Jolly Good", amenity: 4001, water: 3007, pets: 3010 })
110
116
  end
111
117
  end
112
118
 
@@ -121,7 +127,8 @@ describe Supercamp::Criteria::Abstract do
121
127
 
122
128
  let :criteria do
123
129
  subject.tap do |s|
124
- s.options = { pname: "$$%So**??Bad" }
130
+ expect(s).to receive(:options).and_return \
131
+ ({ pname: "$$%So**??Bad" })
125
132
  end
126
133
  end
127
134
 
@@ -152,6 +159,44 @@ describe Supercamp::Criteria::Abstract do
152
159
  end
153
160
  end
154
161
 
162
+ it "freezes @response" do
163
+ VCR.use_cassette("campground ca tent") do
164
+ expect(subject.response).to be_frozen
165
+ end
166
+ end
167
+
168
+ it "sets :response" do
169
+ VCR.use_cassette("campground ca tent") do
170
+ expect {
171
+ subject.response
172
+ }.to change { subject.instance_variable_get(:@response) }.from(nil)
173
+ end
174
+ end
175
+
176
+ it "is only executed once" do
177
+ VCR.use_cassette("campground ca tent") do
178
+ expect(Supercamp::Response).to receive(:new).once.and_return "response"
179
+ expect(subject.response).to eq "response"
180
+ expect(subject.response).to eq "response"
181
+ end
182
+ end
183
+
184
+ context "w/ criteria changes" do
185
+
186
+ before do
187
+ VCR.use_cassette("campground ca tent") do
188
+ subject.response
189
+ end
190
+ end
191
+
192
+ it "removes the @response" do
193
+ expect {
194
+ subject.name("Randal")
195
+ }.to change { subject.instance_variable_get(:@response) }.to(nil)
196
+ end
197
+
198
+ end
199
+
155
200
  end
156
201
 
157
202
  context "w/ invalid response" do
@@ -174,4 +219,42 @@ describe Supercamp::Criteria::Abstract do
174
219
 
175
220
  end
176
221
 
222
+
223
+ describe "#count" do
224
+
225
+ let :response do
226
+ double(Supercamp::Response).tap do |m|
227
+ expect(m).to receive(:count).and_return 13
228
+ end
229
+ end
230
+
231
+ before do
232
+ expect(subject).to receive(:response).and_return response
233
+ end
234
+
235
+ it "returns :count from Response" do
236
+ expect(subject.count).to eq 13
237
+ end
238
+
239
+ end
240
+
241
+
242
+ describe "#results" do
243
+
244
+ let :response do
245
+ double(Supercamp::Response).tap do |m|
246
+ expect(m).to receive(:results).and_return "the-results"
247
+ end
248
+ end
249
+
250
+ before do
251
+ expect(subject).to receive(:response).and_return response
252
+ end
253
+
254
+ it "returns :results from Response" do
255
+ expect(subject.results).to eq "the-results"
256
+ end
257
+
258
+ end
259
+
177
260
  end
@@ -2,26 +2,26 @@ require "spec_helper"
2
2
 
3
3
  describe Supercamp::Response do
4
4
 
5
- describe ".new" do
6
-
7
- around(:each) do |example|
8
- VCR.use_cassette "response of limited campground search" do
9
- example.run
10
- end
5
+ around(:each) do |example|
6
+ VCR.use_cassette "response of limited campground search" do
7
+ example.run
11
8
  end
9
+ end
12
10
 
13
- let :criteria do
14
- Supercamp.campgrounds.search do
15
- site_type "tent"
16
- state "CA"
17
- amenity "fishing"
18
- has "pets", "waterfront"
19
- end
11
+ let :criteria do
12
+ Supercamp.campgrounds.search do
13
+ site_type "tent"
14
+ state "CA"
15
+ amenity "fishing"
16
+ has "pets", "waterfront"
20
17
  end
18
+ end
21
19
 
22
- subject do
23
- Supercamp::Response.new criteria.query.run
24
- end
20
+ subject do
21
+ Supercamp::Response.new criteria.query.run
22
+ end
23
+
24
+ describe ".new" do
25
25
 
26
26
  it "sets :count" do
27
27
  expect(subject.count).to eq 21
@@ -52,4 +52,13 @@ describe Supercamp::Response do
52
52
 
53
53
  end
54
54
 
55
+
56
+ describe "#results" do
57
+
58
+ it "returns values from :entries" do
59
+ expect(subject.results).to eq subject.entries
60
+ end
61
+
62
+ end
63
+
55
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supercamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Krupinski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus