viki 1.0.1 → 1.0.2
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.
- data/lib/viki/api_object.rb +8 -0
- data/lib/viki/request.rb +2 -3
- data/lib/viki/version.rb +1 -1
- data/spec/lib/request_spec.rb +9 -3
- data/spec/requests/request_integration_spec.rb +38 -4
- metadata +2 -2
data/lib/viki/api_object.rb
CHANGED
data/lib/viki/request.rb
CHANGED
@@ -14,7 +14,6 @@ module Viki
|
|
14
14
|
|
15
15
|
def get
|
16
16
|
current_chain = @call_chain
|
17
|
-
@call_chain = []
|
18
17
|
request(current_chain)
|
19
18
|
end
|
20
19
|
|
@@ -27,9 +26,9 @@ module Viki
|
|
27
26
|
params.delete(:access_token)
|
28
27
|
|
29
28
|
url_params = ""
|
30
|
-
params.keys.each { |key| url_params += "#{key}=#{params[key]}" }
|
29
|
+
params.keys.each { |key| url_params += "#{key}=#{params[key]}&" }
|
31
30
|
|
32
|
-
"#{path.chop}?#{url_params}"
|
31
|
+
"#{path.chop}?#{url_params.chop}"
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
data/lib/viki/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -23,6 +23,13 @@ describe Viki::Request do
|
|
23
23
|
req.get
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should not clear the call_chain after .get is called" do
|
27
|
+
req = client.movies(1234, { genre: 2 })
|
28
|
+
req.should_receive(:request)
|
29
|
+
req.get
|
30
|
+
req.instance_variable_get(:@call_chain).should_not == []
|
31
|
+
end
|
32
|
+
|
26
33
|
it "should raise NoMethodError error if part of the call chain is not part of the URL_NAMESPACES list" do
|
27
34
|
expect { client.methodwrong.subtitles('en') }.to raise_error(NoMethodError)
|
28
35
|
end
|
@@ -30,9 +37,8 @@ describe Viki::Request do
|
|
30
37
|
|
31
38
|
describe "#url" do
|
32
39
|
it "should return the right url for the method call" do
|
33
|
-
req = client.movies(1234, { genre: 2 })
|
34
|
-
req.url.should == "movies/1234?genre=2"
|
40
|
+
req = client.movies(1234, { genre: 2, per_page: 3 })
|
41
|
+
req.url.should == "movies/1234?genre=2&per_page=3"
|
35
42
|
end
|
36
|
-
|
37
43
|
end
|
38
44
|
end
|
@@ -141,7 +141,7 @@ describe "Viki" do
|
|
141
141
|
|
142
142
|
describe ".next" do
|
143
143
|
it "should invoke direct_request with a next_url" do
|
144
|
-
VCR.use_cassette("movies/list/pg2"
|
144
|
+
VCR.use_cassette("movies/list/pg2") do
|
145
145
|
movies = client.movies.get
|
146
146
|
next_url = movies.instance_variable_get(:@next_url)
|
147
147
|
movies.should_receive(:direct_request).with(next_url)
|
@@ -152,7 +152,7 @@ describe "Viki" do
|
|
152
152
|
|
153
153
|
describe ".prev" do
|
154
154
|
it "should invoke direct_request with previous_url" do
|
155
|
-
VCR.use_cassette("movies/list/pg2"
|
155
|
+
VCR.use_cassette("movies/list/pg2") do
|
156
156
|
movies_pg1 = client.movies.get
|
157
157
|
movies_pg2 = movies_pg1.next
|
158
158
|
previous_url = movies_pg2.instance_variable_get(:@previous_url)
|
@@ -162,6 +162,40 @@ describe "Viki" do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
describe ".next?" do
|
166
|
+
it "should return true when url is available" do
|
167
|
+
VCR.use_cassette("movies/list/pg2") do
|
168
|
+
movies = client.movies.get
|
169
|
+
movies.next?.should == true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return false when not next url not available" do
|
174
|
+
VCR.use_cassette("movies/list/pg2") do
|
175
|
+
response = client.movies.get
|
176
|
+
response.instance_variable_set(:@next_url, nil)
|
177
|
+
response.next?.should == false
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe ".prev?" do
|
183
|
+
it "should return false when not next url not available" do
|
184
|
+
VCR.use_cassette("movies/list/pg2") do
|
185
|
+
response = client.movies.get
|
186
|
+
response.instance_variable_set(:@previous_url, "www.google.com")
|
187
|
+
response.prev?.should == true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should return true when url is available" do
|
192
|
+
VCR.use_cassette("movies/list/pg2") do
|
193
|
+
movies = client.movies.get
|
194
|
+
movies.prev?.should == false
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
165
199
|
describe "Errors" do
|
166
200
|
it "should raise NoMethodError if a method that is not on the whitelist is called" do
|
167
201
|
expect { client.does_not_exist }.should raise_error(NoMethodError)
|
@@ -172,8 +206,8 @@ describe "Viki" do
|
|
172
206
|
lambda { client.movies(50).get }.should raise_error(Viki::Error, "The resource couldn't be found")
|
173
207
|
end
|
174
208
|
|
175
|
-
|
176
|
-
|
209
|
+
results = client.movies.get
|
210
|
+
results.should be_instance_of(Viki::APIObject)
|
177
211
|
end
|
178
212
|
end
|
179
213
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-07-
|
14
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|