dailymotion 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dailymotion.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 slainer68
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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.
@@ -0,0 +1,52 @@
1
+ # Dailymotion
2
+
3
+ Ruby bindings for the [Dailymotion Graph API](http://www.dailymotion.com/doc/api/graph-api.html).
4
+
5
+ To authenticate your users with Dailymotion, I suggest you to use my [Omniauth Dailymotion Strategy](https://github.com/slainer68/omniauth-dailymotion).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'dailymotion'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dailymotion
20
+
21
+ ## Usage
22
+
23
+ Get the list of the authenticated user videos:
24
+
25
+ daily_api = Dailymotion::API.new("API_TOKEN")
26
+ resp = daily_api.get_connections("user", "me", "videos")
27
+
28
+ resp.body
29
+
30
+ ## Upload a video
31
+
32
+ First obtain an 'upload' URL :
33
+
34
+ req = daily_api.get_object "file", "upload"
35
+ url = req.body.upload_url
36
+
37
+ Then send a file to this URL, for example:
38
+
39
+ req = daily_api.upload_file "video.m4v", url
40
+ uploaded_file_url = req.body.url
41
+
42
+ Then post the video to Dailymotion :
43
+
44
+ req = daily_api.post_video(uploaded_file_url)
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dailymotion/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["slainer68"]
6
+ gem.email = ["slainer68@gmail.com"]
7
+ gem.description = %q{Dailymotion Open Graph API for Ruby}
8
+ gem.summary = %q{Dailymotion Open Graph API for Ruby}
9
+ gem.homepage = "https://github.com/slainer68/dailymotion"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "dailymotion"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Dailymotion::VERSION
17
+
18
+ gem.add_runtime_dependency "faraday"
19
+ gem.add_runtime_dependency "hashie"
20
+ gem.add_runtime_dependency "faraday_middleware"
21
+
22
+ gem.add_development_dependency 'pry'
23
+ gem.add_development_dependency 'rake'
24
+ gem.add_development_dependency 'rspec', '~> 2.10.0'
25
+ end
@@ -0,0 +1,5 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "dailymotion/version"
4
+ require "dailymotion/faraday_middleware/oauth2"
5
+ require "dailymotion/api"
@@ -0,0 +1,59 @@
1
+ module Dailymotion
2
+ class API
3
+ attr_accessor :token, :faraday
4
+
5
+ def initialize(token)
6
+ @token = token
7
+ @faraday = Faraday.new(:url => 'https://api.dailymotion.com') do |builder|
8
+ builder.use Dailymotion::FaradayMiddleware::OAuth2, @token
9
+ builder.use Faraday::Response::Logger
10
+ builder.adapter Faraday.default_adapter
11
+
12
+ builder.use ::FaradayMiddleware::Mashify
13
+ builder.use ::FaradayMiddleware::ParseJson
14
+ end
15
+ end
16
+
17
+ def get_object(object, id, params = {})
18
+ @faraday.get do |req|
19
+ req.url "/#{object}/#{id}"
20
+ req.params = params
21
+ end
22
+ end
23
+
24
+ def get_connection(object, id, connection, params = {})
25
+ @faraday.get do |req|
26
+ req.url "/#{object}/#{id}/#{connection}"
27
+ req.params = params
28
+ end
29
+ end
30
+ alias_method :get_connections, :get_connection
31
+
32
+ def post_object(object, id, params = {})
33
+ @faraday.post do |req|
34
+ req.url "/#{object}/#{id}"
35
+ req.params = params
36
+ end
37
+ end
38
+
39
+ def post_video(url)
40
+ post_object("me", "videos", :url => url)
41
+ end
42
+
43
+ def upload_file(filepath, url)
44
+ faraday = Faraday.new do |builder|
45
+ builder.use Faraday::Request::Multipart
46
+ builder.use Faraday::Request::UrlEncoded
47
+
48
+ builder.adapter Faraday.default_adapter
49
+
50
+ builder.use ::FaradayMiddleware::Mashify
51
+ builder.use ::FaradayMiddleware::ParseJson
52
+ end
53
+
54
+ payload = { :file => Faraday::UploadIO.new(filepath, "application/octet-stream") }
55
+
56
+ faraday.post url, payload
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ module Dailymotion
2
+ module FaradayMiddleware
3
+ class OAuth2 < Faraday::Middleware
4
+ def call(env)
5
+ env[:request_headers]['Authorization'] = "OAuth #{@access_token}"
6
+
7
+ @app.call(env)
8
+ end
9
+
10
+ def initialize(app, access_token)
11
+ @app, @access_token = app, access_token
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Dailymotion
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+ require "dailymotion"
3
+ require "pry"
4
+
5
+ describe Dailymotion::API do
6
+ it "should be initialized with a token" do
7
+ @api = Dailymotion::API.new("ABCD")
8
+
9
+ @api.token.should eq("ABCD")
10
+ end
11
+
12
+ describe "with a token" do
13
+ subject { Dailymotion::API.new("ABCD") }
14
+
15
+ describe "#get_object" do
16
+ it "should get object" do
17
+ subject.faraday.should_receive(:get).and_return({})
18
+
19
+ subject.get_object("video", "1234")
20
+ end
21
+ end
22
+
23
+ describe "#get_connections" do
24
+ it "should get connections" do
25
+ subject.faraday.should_receive(:get).and_return({})
26
+
27
+ subject.get_connections("user", "1234", "videos")
28
+ end
29
+ end
30
+
31
+ describe "#get_connection" do
32
+ it "should get connection" do
33
+ subject.faraday.should_receive(:get).and_return({})
34
+
35
+ subject.get_connection("user", "1234", "videos")
36
+ end
37
+ end
38
+
39
+ describe "#post_video" do
40
+ it "should post video" do
41
+ subject.should_receive(:post_object).and_return({})
42
+
43
+ subject.post_video("http://myvideo")
44
+ end
45
+ end
46
+
47
+ describe "#post_object" do
48
+ it "should post object" do
49
+ subject.faraday.should_receive(:post).and_return({})
50
+
51
+ subject.post_object("video", "1234", { :title => "hello world" })
52
+ end
53
+ end
54
+
55
+ describe "#upload_file" do
56
+ it "should upload file" do
57
+ faraday_mock = mock(:faraday)
58
+ Faraday.should_receive(:new).twice.and_return(faraday_mock)
59
+ Faraday::UploadIO.should_receive(:new).and_return({})
60
+ faraday_mock.should_receive(:post).and_return({})
61
+
62
+ subject.upload_file("pipomolo.m4v", "http://pipomolo.com")
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dailymotion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - slainer68
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70301321405600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70301321405600
25
+ - !ruby/object:Gem::Dependency
26
+ name: hashie
27
+ requirement: &70301321386620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70301321386620
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday_middleware
38
+ requirement: &70301321380480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70301321380480
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: &70301321375040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70301321375040
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70301321369620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70301321369620
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70301321358420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.10.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70301321358420
80
+ description: Dailymotion Open Graph API for Ruby
81
+ email:
82
+ - slainer68@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - dailymotion.gemspec
93
+ - lib/dailymotion.rb
94
+ - lib/dailymotion/api.rb
95
+ - lib/dailymotion/faraday_middleware/oauth2.rb
96
+ - lib/dailymotion/version.rb
97
+ - spec/dailymotion/api_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/slainer68/dailymotion
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.11
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Dailymotion Open Graph API for Ruby
123
+ test_files:
124
+ - spec/dailymotion/api_spec.rb
125
+ - spec/spec_helper.rb
126
+ has_rdoc: