dailymotion-api-client 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/dailymotion-api-client.gemspec +23 -0
- data/lib/dailymotion-api-client.rb +8 -0
- data/lib/dailymotion-api/client.rb +37 -0
- data/lib/dailymotion-api/version.rb +4 -0
- data/spec/lib/dailymotion-api/client_spec.rb +63 -0
- data/spec/spec_helper.rb +7 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODM3YjRiMDkzMjBjNzU0ZDhlNDJiYzU1M2VmOWFiNmQ1NjE3NDA2Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmQ3MGRhNmI4M2ZmODRjYWI4YTI0ZDEwMGFjNjU3ZTUwMTMxNDliZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjA1ZjRiNWY4NzY2MzAzM2E3MjVlYjc4YjJjYmIzNmQ4YjRmY2UwZTM1MDVj
|
10
|
+
MzlhY2QxYmNmYjg3NDdjMTcyNThjODY1NDEwY2JkNjNhMmNmMDQ5ZjIzZTI0
|
11
|
+
MjU5NWNlN2NmYTE2ZDhlMzc5ZjE3N2U2NmEwZDBkNjk0ZjdmNzM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWQ2NGVlOGQ3ZWMyMGY4ZDFjM2YzYzcwM2RiYTk0N2RiOWQ3NmEzYWU5OTcy
|
14
|
+
MDQyMjllZDFkYWNmNzdkMjY0YzhlY2VkNWI3YzM0MjI3ZjE3NTE2OTIwYzZh
|
15
|
+
ZTc1NGNlOGJlYmZiNWQyNmU1NzAxNTViNDY5MzYzY2UwMTI0NTM=
|
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3-p194@dailymotion-api-client
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dailymotion-api-client (0.1.0)
|
5
|
+
httmultiparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.1)
|
11
|
+
httmultiparty (0.3.8)
|
12
|
+
httparty (>= 0.7.3)
|
13
|
+
multipart-post
|
14
|
+
httparty (0.10.2)
|
15
|
+
multi_json (~> 1.0)
|
16
|
+
multi_xml (>= 0.5.2)
|
17
|
+
multi_json (1.6.1)
|
18
|
+
multi_xml (0.5.3)
|
19
|
+
multipart-post (1.2.0)
|
20
|
+
rspec (2.13.0)
|
21
|
+
rspec-core (~> 2.13.0)
|
22
|
+
rspec-expectations (~> 2.13.0)
|
23
|
+
rspec-mocks (~> 2.13.0)
|
24
|
+
rspec-core (2.13.0)
|
25
|
+
rspec-expectations (2.13.0)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.13.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
dailymotion-api-client!
|
34
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# DailyMotion API Ruby Client
|
2
|
+
|
3
|
+
Client for DailyMotion API (http://www.dailymotion.com/doc/api/graph-api.html) written in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dailymotion-api-client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dailymotion-api-client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Publishing a video
|
22
|
+
|
23
|
+
# Create an instance of DailymotionApi::Client
|
24
|
+
client = DailymotionApi::Client.new(username: "username", password: "password", api_key: "key", api_secret: "secret")
|
25
|
+
# Request an access token
|
26
|
+
client.request_access_token
|
27
|
+
# Request an upload url
|
28
|
+
client.get_upload_url
|
29
|
+
# Post your video
|
30
|
+
client.post_video(File.new("my_video.mp4"))
|
31
|
+
# Create a video
|
32
|
+
client.create_video
|
33
|
+
# Update video data an publish it
|
34
|
+
client.publish_video(title: "my video", channel: "shortfilms", tags: "my_tag")
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dailymotion-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "dailymotion-api-client"
|
8
|
+
gem.version = DailymotionApi::VERSION
|
9
|
+
gem.authors = ["Guilherme Garnier"]
|
10
|
+
gem.email = ["guilherme.garnier@gmail.com"]
|
11
|
+
gem.description = %q{DailyMotion API Ruby client}
|
12
|
+
gem.summary = %q{DailyMotion API Ruby client}
|
13
|
+
gem.homepage = "http://github.com/ggarnier/dailymotion-api-client"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "httmultiparty"
|
21
|
+
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module DailymotionApi
|
3
|
+
class Client
|
4
|
+
API_URL = "https://api.dailymotion.com"
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@username = params[:username]
|
8
|
+
@password = params[:password]
|
9
|
+
@api_key = params[:api_key]
|
10
|
+
@api_secret = params[:api_secret]
|
11
|
+
end
|
12
|
+
|
13
|
+
def request_access_token
|
14
|
+
response = HTTMultiParty.post("#{API_URL}/oauth/token", body: {grant_type: "password", client_id: @api_key, client_secret: @api_secret, username: @username, password: @password})
|
15
|
+
@access_token = response.parsed_response["access_token"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_upload_url
|
19
|
+
response = HTTMultiParty.get("#{API_URL}/file/upload?access_token=#{@access_token}")
|
20
|
+
@upload_url = response.parsed_response["upload_url"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_video(video)
|
24
|
+
response = HTTMultiParty.post(@upload_url, body: {file: video})
|
25
|
+
@video_url = response.parsed_response["url"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_video
|
29
|
+
response = HTTMultiParty.post("#{API_URL}/me/videos", body: {access_token: @access_token, url: @video_url})
|
30
|
+
@video_id = response.parsed_response["id"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def publish_video(data)
|
34
|
+
HTTMultiParty.post("#{API_URL}/video/#{@video_id}", body: data.merge(access_token: @access_token, published: true))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe DailymotionApi::Client do
|
5
|
+
before do
|
6
|
+
HTTMultiParty.stub(:get)
|
7
|
+
HTTMultiParty.stub(:post)
|
8
|
+
end
|
9
|
+
|
10
|
+
let! :client do
|
11
|
+
DailymotionApi::Client.new(username: "test", password: "12345", api_key: "key", api_secret: "secret")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#request_access_token" do
|
15
|
+
it "should do a request for an access token" do
|
16
|
+
response = stub("response", parsed_response: {"access_token" => "token"})
|
17
|
+
HTTMultiParty.should_receive(:post).with("https://api.dailymotion.com/oauth/token", body: {grant_type: "password", client_id: "key", client_secret: "secret", username: "test", password: "12345"}).and_return(response)
|
18
|
+
|
19
|
+
client.request_access_token.should == "token"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#get_upload_url" do
|
24
|
+
it "should request an upload url" do
|
25
|
+
client.instance_variable_set(:@access_token, "token")
|
26
|
+
response = stub("response", parsed_response: {"upload_url" => "upload_url"})
|
27
|
+
HTTMultiParty.should_receive(:get).with("https://api.dailymotion.com/file/upload?access_token=token").and_return(response)
|
28
|
+
|
29
|
+
client.get_upload_url.should == "upload_url"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#post_video" do
|
34
|
+
it "should post the video" do
|
35
|
+
client.instance_variable_set(:@upload_url, "upload_url")
|
36
|
+
response = stub("response", parsed_response: {"url" => "video_url"})
|
37
|
+
HTTMultiParty.should_receive(:post).with("upload_url", body: {file: "video_data"}).and_return(response)
|
38
|
+
|
39
|
+
client.post_video("video_data").should == "video_url"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#create_video" do
|
44
|
+
it "should post the video" do
|
45
|
+
client.instance_variable_set(:@access_token, "token")
|
46
|
+
client.instance_variable_set(:@video_url, "video_url")
|
47
|
+
response = stub("response", parsed_response: {"id" => "video_id"})
|
48
|
+
HTTMultiParty.should_receive(:post).with("https://api.dailymotion.com/me/videos", body: {access_token: "token", url: "video_url"}).and_return(response)
|
49
|
+
|
50
|
+
client.create_video.should == "video_id"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#publish_video" do
|
55
|
+
it "should publish the video" do
|
56
|
+
client.instance_variable_set(:@access_token, "token")
|
57
|
+
client.instance_variable_set(:@video_id, "video_id")
|
58
|
+
HTTMultiParty.should_receive(:post).with("https://api.dailymotion.com/video/video_id", body: {access_token: "token", published: true, title: "video title", channel: "shortfilms", tags: "some_tag"})
|
59
|
+
|
60
|
+
client.publish_video(title: "video title", channel: "shortfilms", tags: "some_tag")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dailymotion-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guilherme Garnier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httmultiparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: DailyMotion API Ruby client
|
42
|
+
email:
|
43
|
+
- guilherme.garnier@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .rspec
|
49
|
+
- .rvmrc
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- dailymotion-api-client.gemspec
|
55
|
+
- lib/dailymotion-api-client.rb
|
56
|
+
- lib/dailymotion-api/client.rb
|
57
|
+
- lib/dailymotion-api/version.rb
|
58
|
+
- spec/lib/dailymotion-api/client_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
homepage: http://github.com/ggarnier/dailymotion-api-client
|
61
|
+
licenses: []
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: DailyMotion API Ruby client
|
83
|
+
test_files:
|
84
|
+
- spec/lib/dailymotion-api/client_spec.rb
|
85
|
+
- spec/spec_helper.rb
|