dailymotion 0.5.0 → 0.6.0
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/.travis.yml +5 -0
- data/LICENSE +2 -2
- data/README.md +13 -2
- data/lib/dailymotion/api.rb +30 -14
- data/lib/dailymotion/version.rb +1 -1
- data/spec/dailymotion/api_spec.rb +25 -4
- metadata +21 -15
data/.travis.yml
ADDED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012
|
1
|
+
Copyright (c) 2012 Nicolas Blanco.
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
# Dailymotion
|
1
|
+
# Dailymotion [][travis] [][gemnasium]
|
2
|
+
[travis]: http://travis-ci.org/slainer68/dailymotion
|
3
|
+
[gemnasium]: https://gemnasium.com/slainer68/dailymotion
|
2
4
|
|
3
5
|
Ruby bindings for the [Dailymotion Graph API](http://www.dailymotion.com/doc/api/graph-api.html).
|
4
6
|
|
7
|
+
Note : this gem is unofficial and is not endorsed in any way by Dailymotion.
|
8
|
+
|
5
9
|
To authenticate your users with Dailymotion, I suggest you to use my [Omniauth Dailymotion Strategy](https://github.com/slainer68/omniauth-dailymotion).
|
6
10
|
|
7
11
|
## Installation
|
@@ -22,7 +26,7 @@ Or install it yourself as:
|
|
22
26
|
|
23
27
|
Get the list of the authenticated user videos:
|
24
28
|
|
25
|
-
daily_api = Dailymotion::API.new("API_TOKEN")
|
29
|
+
daily_api = Dailymotion::API.new(token: "API_TOKEN")
|
26
30
|
resp = daily_api.get_connections("user", "me", "videos")
|
27
31
|
|
28
32
|
resp.body
|
@@ -43,6 +47,13 @@ Then post the video to Dailymotion :
|
|
43
47
|
|
44
48
|
req = daily_api.post_video(uploaded_file_url)
|
45
49
|
|
50
|
+
## Refresh the access token
|
51
|
+
|
52
|
+
NOTE : in order to refresh the access token, you need to initialize or populate the options hash with client_id, client_secret and refresh_token.
|
53
|
+
|
54
|
+
daily_api = Dailymotion::API.new(client_id: "12345678", client_secret: "pipomolo", refresh_token: "blablabla")
|
55
|
+
daily_api.refresh_token!
|
56
|
+
|
46
57
|
## Contributing
|
47
58
|
|
48
59
|
1. Fork it
|
data/lib/dailymotion/api.rb
CHANGED
@@ -1,17 +1,34 @@
|
|
1
1
|
module Dailymotion
|
2
2
|
class API
|
3
|
-
|
3
|
+
API_BASE_URL = 'https://api.dailymotion.com'
|
4
|
+
attr_accessor :options
|
5
|
+
attr_reader :faraday, :faraday_post
|
4
6
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
|
8
|
-
|
7
|
+
def initialize(opts = {})
|
8
|
+
@options = opts
|
9
|
+
|
10
|
+
set_faradays
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_faradays
|
14
|
+
@faraday = Faraday.new(:url => API_BASE_URL) do |builder|
|
15
|
+
builder.use Dailymotion::FaradayMiddleware::OAuth2, @options[:token]
|
9
16
|
builder.use Faraday::Response::Logger
|
10
17
|
builder.adapter Faraday.default_adapter
|
11
18
|
|
12
19
|
builder.use ::FaradayMiddleware::Mashify
|
13
20
|
builder.use ::FaradayMiddleware::ParseJson
|
14
21
|
end
|
22
|
+
|
23
|
+
@faraday_post = Faraday.new do |builder|
|
24
|
+
builder.use Faraday::Request::Multipart
|
25
|
+
builder.use Faraday::Request::UrlEncoded
|
26
|
+
|
27
|
+
builder.adapter Faraday.default_adapter
|
28
|
+
|
29
|
+
builder.use ::FaradayMiddleware::Mashify
|
30
|
+
builder.use ::FaradayMiddleware::ParseJson
|
31
|
+
end
|
15
32
|
end
|
16
33
|
|
17
34
|
def get_object(object, id, params = {})
|
@@ -41,19 +58,18 @@ module Dailymotion
|
|
41
58
|
end
|
42
59
|
|
43
60
|
def upload_file(filepath, url)
|
44
|
-
|
45
|
-
builder.use Faraday::Request::Multipart
|
46
|
-
builder.use Faraday::Request::UrlEncoded
|
61
|
+
payload = { :file => Faraday::UploadIO.new(filepath, "application/octet-stream") }
|
47
62
|
|
48
|
-
|
63
|
+
@faraday_post.post url, payload
|
64
|
+
end
|
49
65
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
66
|
+
def refresh_token!
|
67
|
+
raise StandardError, "client_id, client_secret and refresh_token in options hash are mandatory" unless options[:client_id] && options[:client_secret] && options[:refresh_token]
|
53
68
|
|
54
|
-
|
69
|
+
refresh_request = @faraday_post.post "#{API_BASE_URL}/oauth/token", { grant_type: "refresh_token", client_id: @options[:client_id], client_secret: @options[:client_secret], refresh_token: @options[:refresh_token] }
|
70
|
+
@options[:token] = refresh_request.body.access_token
|
55
71
|
|
56
|
-
|
72
|
+
set_faradays
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|
data/lib/dailymotion/version.rb
CHANGED
@@ -3,14 +3,14 @@ require "dailymotion"
|
|
3
3
|
require "pry"
|
4
4
|
|
5
5
|
describe Dailymotion::API do
|
6
|
-
it "should be initialized with
|
7
|
-
@api = Dailymotion::API.new("ABCD")
|
6
|
+
it "should be initialized with an options hash" do
|
7
|
+
@api = Dailymotion::API.new(token: "ABCD")
|
8
8
|
|
9
|
-
@api.token.should eq("ABCD")
|
9
|
+
@api.options[:token].should eq("ABCD")
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "with a token" do
|
13
|
-
subject { Dailymotion::API.new("ABCD") }
|
13
|
+
subject { Dailymotion::API.new(token: "ABCD") }
|
14
14
|
|
15
15
|
describe "#get_object" do
|
16
16
|
it "should get object" do
|
@@ -63,4 +63,25 @@ describe Dailymotion::API do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
describe "#refresh_token!" do
|
68
|
+
it "should fail if client_id, client_secret or refresh_token are not set" do
|
69
|
+
@api = Dailymotion::API.new(token: "ABCD")
|
70
|
+
|
71
|
+
expect { @api.refresh_token! }.to raise_error(StandardError)
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "with all options" do
|
75
|
+
it "should refresh the token" do
|
76
|
+
@api = Dailymotion::API.new(client_id: "pipo", client_secret: "molo", refresh_token: "ahah")
|
77
|
+
|
78
|
+
response_mock = mock(:faraday, body: Hashie::Mash.new(access_token: "new_token"))
|
79
|
+
@api.faraday_post.should_receive(:post).and_return(response_mock)
|
80
|
+
@api.should_receive(:set_faradays).once
|
81
|
+
|
82
|
+
@api.refresh_token!
|
83
|
+
@api.options[:token].should eq("new_token")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
66
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dailymotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70181320256340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70181320256340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &70181320255920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70181320255920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: faraday_middleware
|
38
|
-
requirement: &
|
38
|
+
requirement: &70181320271820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70181320271820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
requirement: &
|
49
|
+
requirement: &70181320271400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70181320271400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70181320270980 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70181320270980
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70181320270480 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 2.10.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70181320270480
|
80
80
|
description: Dailymotion Open Graph API for Ruby
|
81
81
|
email:
|
82
82
|
- slainer68@gmail.com
|
@@ -85,6 +85,7 @@ extensions: []
|
|
85
85
|
extra_rdoc_files: []
|
86
86
|
files:
|
87
87
|
- .gitignore
|
88
|
+
- .travis.yml
|
88
89
|
- Gemfile
|
89
90
|
- LICENSE
|
90
91
|
- README.md
|
@@ -108,12 +109,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
109
|
- - ! '>='
|
109
110
|
- !ruby/object:Gem::Version
|
110
111
|
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: 981270364239254124
|
111
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
116
|
none: false
|
113
117
|
requirements:
|
114
118
|
- - ! '>='
|
115
119
|
- !ruby/object:Gem::Version
|
116
120
|
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: 981270364239254124
|
117
124
|
requirements: []
|
118
125
|
rubyforge_project:
|
119
126
|
rubygems_version: 1.8.11
|
@@ -123,4 +130,3 @@ summary: Dailymotion Open Graph API for Ruby
|
|
123
130
|
test_files:
|
124
131
|
- spec/dailymotion/api_spec.rb
|
125
132
|
- spec/spec_helper.rb
|
126
|
-
has_rdoc:
|