viki 1.0.0 → 1.0.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.
- data/README.md +13 -2
- data/lib/viki/request.rb +10 -0
- data/lib/viki/version.rb +1 -1
- data/spec/lib/request_spec.rb +15 -8
- metadata +1 -1
data/README.md
CHANGED
@@ -22,8 +22,8 @@ Client is a `Viki::Client` object. When you make a method call, for example `cli
|
|
22
22
|
viki = client.movies #returns a Viki::Request object
|
23
23
|
results = viki.get #hits the API and returns a Viki::APIObject
|
24
24
|
|
25
|
-
APIObject Methods
|
26
|
-
|
25
|
+
Viki::APIObject Methods
|
26
|
+
-----------------------
|
27
27
|
|
28
28
|
Responses will be returned in a `Viki::APIObject`. See below
|
29
29
|
|
@@ -40,6 +40,17 @@ For results that are paginated, you may use the `APIObject`'s `next` and `prev`
|
|
40
40
|
movies = movies2.prev #prev 25 records
|
41
41
|
```
|
42
42
|
|
43
|
+
Viki::Request Methods
|
44
|
+
---------------------
|
45
|
+
|
46
|
+
Requests are made with the `Viki::Request` object.
|
47
|
+
|
48
|
+
```
|
49
|
+
viki = client.movies #returns a Viki::Request
|
50
|
+
|
51
|
+
viki.get #hits the API
|
52
|
+
viki.url #returns the url
|
53
|
+
```
|
43
54
|
|
44
55
|
Examples
|
45
56
|
----------
|
data/lib/viki/request.rb
CHANGED
@@ -22,6 +22,16 @@ module Viki
|
|
22
22
|
@access_token = auth_request(@client_id, @client_secret)
|
23
23
|
end
|
24
24
|
|
25
|
+
def url
|
26
|
+
path, params = build_url(@call_chain)
|
27
|
+
params.delete(:access_token)
|
28
|
+
|
29
|
+
url_params = ""
|
30
|
+
params.keys.each { |key| url_params += "#{key}=#{params[key]}" }
|
31
|
+
|
32
|
+
"#{path.chop}?#{url_params}"
|
33
|
+
end
|
34
|
+
|
25
35
|
private
|
26
36
|
def method_missing(name, *args)
|
27
37
|
build_call_chain(name, *args)
|
data/lib/viki/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Viki::Request do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Viki::Request.any_instance.stub(:request) { Viki::APIObject }
|
8
|
-
end
|
4
|
+
before do
|
5
|
+
Viki::Client.any_instance.stub(:auth_request)
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def client
|
9
|
+
Viki.new('chickenrice', 'soronerychickenrice')
|
10
|
+
end
|
13
11
|
|
12
|
+
describe "#get" do
|
14
13
|
it "should perform a request to the right url given a call chain" do
|
15
14
|
req = client.movies(1234).subtitles('en')
|
16
15
|
req.should_receive(:request).with([{ :name => :movies, :resource => 1234 },
|
@@ -28,4 +27,12 @@ describe Viki::Request do
|
|
28
27
|
expect { client.methodwrong.subtitles('en') }.to raise_error(NoMethodError)
|
29
28
|
end
|
30
29
|
end
|
30
|
+
|
31
|
+
describe "#url" do
|
32
|
+
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"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
31
38
|
end
|