dailymotion-api-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +2 -0
- data/lib/dailymotion-api/client.rb +15 -2
- data/lib/dailymotion-api/version.rb +1 -1
- data/spec/lib/dailymotion-api/client_spec.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDAzNGY2MTMzN2FiNmU3YjNjODU2ZWE0MDQ1MGY0ZTMyMTNiNDFiNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjBkOWEwYzdkZTcxOTEzMGQ0MTU4NDQwYjFhZTYyNDAxZmMyYzQ3ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzU4MmQyN2E5YzVjMWNkZjJhM2RiMjU5NzQzNjFlNzRlYWY2YTQ2ZDdiZjE5
|
10
|
+
MjQ1YjhhMDcyZDY2NjhhNmUxZDE5ZDM2ZTM0MTVlZDcwODc3NWUyODJjY2I1
|
11
|
+
YWNhNTFkNzM4ZGI0ZTI3NjM4OTljZWJjNjlkNjk0MDc4NjIzNjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDk3ZGEzMjczMDUwYjRiZmMyOWVjNzdjMjQ0YzQ0MjAyZTMyNDllNDZmNTFh
|
14
|
+
MmMyMWFkOGU5ZjQwZjkwNWZjM2QzMzI3MDRmZmRiOGFjYzIyMTMwODhhNGM0
|
15
|
+
Nzc3MTJhMjJjM2RmMWI0MjI4NTkxMzc4YzdkOWFjMTNmNWFlOTg=
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ Or install it yourself as:
|
|
32
32
|
client.create_video
|
33
33
|
# Update video data an publish it
|
34
34
|
client.publish_video(title: "my video", channel: "shortfilms", tags: "my_tag")
|
35
|
+
# Get metadata for a video with a specified id
|
36
|
+
client.get_video("video_id", "url,title")
|
35
37
|
|
36
38
|
## Contributing
|
37
39
|
|
@@ -3,6 +3,8 @@ module DailymotionApi
|
|
3
3
|
class Client
|
4
4
|
API_URL = "https://api.dailymotion.com"
|
5
5
|
|
6
|
+
attr_reader :video_id
|
7
|
+
|
6
8
|
def initialize(params = {})
|
7
9
|
@username = params[:username]
|
8
10
|
@password = params[:password]
|
@@ -22,16 +24,27 @@ module DailymotionApi
|
|
22
24
|
|
23
25
|
def post_video(video)
|
24
26
|
response = HTTMultiParty.post(@upload_url, body: {file: video})
|
25
|
-
@
|
27
|
+
@uploaded_video_url = response.parsed_response["url"]
|
26
28
|
end
|
27
29
|
|
28
30
|
def create_video
|
29
|
-
response = HTTMultiParty.post("#{API_URL}/me/videos", body: {access_token: @access_token, url: @
|
31
|
+
response = HTTMultiParty.post("#{API_URL}/me/videos", body: {access_token: @access_token, url: @uploaded_video_url})
|
30
32
|
@video_id = response.parsed_response["id"]
|
31
33
|
end
|
32
34
|
|
33
35
|
def publish_video(data)
|
34
36
|
HTTMultiParty.post("#{API_URL}/video/#{@video_id}", body: data.merge(access_token: @access_token, published: true))
|
35
37
|
end
|
38
|
+
|
39
|
+
def get_video(video_id, fields = "")
|
40
|
+
return nil unless video_id
|
41
|
+
|
42
|
+
response = HTTMultiParty.get("#{API_URL}/video/#{video_id}?fields=#{fields}")
|
43
|
+
response.parsed_response
|
44
|
+
end
|
45
|
+
|
46
|
+
def video_url
|
47
|
+
@video_url ||= get_video(@video_id, "url")["url"] rescue nil
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
@@ -43,7 +43,7 @@ describe DailymotionApi::Client do
|
|
43
43
|
describe "#create_video" do
|
44
44
|
it "should post the video" do
|
45
45
|
client.instance_variable_set(:@access_token, "token")
|
46
|
-
client.instance_variable_set(:@
|
46
|
+
client.instance_variable_set(:@uploaded_video_url, "video_url")
|
47
47
|
response = stub("response", parsed_response: {"id" => "video_id"})
|
48
48
|
HTTMultiParty.should_receive(:post).with("https://api.dailymotion.com/me/videos", body: {access_token: "token", url: "video_url"}).and_return(response)
|
49
49
|
|
@@ -60,4 +60,32 @@ describe DailymotionApi::Client do
|
|
60
60
|
client.publish_video(title: "video title", channel: "shortfilms", tags: "some_tag")
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
describe "#get_video" do
|
65
|
+
it "should return video metadata" do
|
66
|
+
parsed_response = {"url" => "video_url", "channel" => "video_channel"}
|
67
|
+
response = stub("response", parsed_response: parsed_response)
|
68
|
+
HTTMultiParty.should_receive(:get).with("https://api.dailymotion.com/video/123?fields=url,channel").and_return(response)
|
69
|
+
|
70
|
+
client.get_video("123", "url,channel").should == parsed_response
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#video_url" do
|
75
|
+
context "when video_id is defined" do
|
76
|
+
it "should return the video url" do
|
77
|
+
client.instance_variable_set(:@video_id, "video_id")
|
78
|
+
response = stub("response", parsed_response: {"url" => "url"})
|
79
|
+
HTTMultiParty.should_receive(:get).with("https://api.dailymotion.com/video/video_id?fields=url").and_return(response)
|
80
|
+
|
81
|
+
client.video_url.should == "url"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when video_id isn't defined" do
|
86
|
+
it "should return nil" do
|
87
|
+
client.video_url.should be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
63
91
|
end
|