vidly 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.markdown +18 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/changelog.markdown +5 -0
- data/examples/upload.rb +13 -0
- data/lib/vidly.rb +117 -0
- data/test/fixtures/Schwarzenegger.json +159 -0
- data/test/fixtures/import.json +8 -0
- data/test/fixtures/meta.json +11 -0
- data/test/fixtures/status.json +15 -0
- data/test/fixtures/test.m4v +0 -0
- data/test/fixtures/upload.json +8 -0
- data/test/helper.rb +54 -0
- data/test/test_vidly.rb +64 -0
- metadata +133 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
.autotest
|
23
|
+
.document
|
24
|
+
examples/wynn.rb
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wynn Netherland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# vidly
|
2
|
+
|
3
|
+
Upload and share videos to Twitter with Vid.ly
|
4
|
+
|
5
|
+
## Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
## Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 [Wynn Netherland](http://wynnnetherland.com). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "vidly"
|
8
|
+
gem.summary = %Q{Ruby wrapper for the Vid.ly API}
|
9
|
+
gem.description = %Q{Post your videos to Twitter with Vid.ly}
|
10
|
+
gem.email = "wynn.netherland@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/pengwynn/vidly"
|
12
|
+
gem.authors = ["Wynn Netherland"]
|
13
|
+
|
14
|
+
gem.add_dependency('hashie', '~> 0.1.3')
|
15
|
+
gem.add_dependency('httparty', '~> 0.4.5')
|
16
|
+
|
17
|
+
gem.add_development_dependency('thoughtbot-shoulda', '>= 2.10.1')
|
18
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
19
|
+
gem.add_development_dependency('mocha', '0.9.4')
|
20
|
+
gem.add_development_dependency('fakeweb', '>= 1.2.5')
|
21
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :test => :check_dependencies
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
Rake::RDocTask.new do |rdoc|
|
54
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "vidly #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/changelog.markdown
ADDED
data/examples/upload.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'lib/vidly'
|
2
|
+
|
3
|
+
# create a client
|
4
|
+
vidly = Vidly.new('twitter_user', 'twitter_pass')
|
5
|
+
|
6
|
+
# upload a file
|
7
|
+
vidly.upload("path/to/file.m4v", :status => "Testing from the ruby gem")
|
8
|
+
|
9
|
+
# check the status of a previous upload
|
10
|
+
vidly.status('bHXX')
|
11
|
+
|
12
|
+
# get all the videos for a user
|
13
|
+
Vidly.videos("pengwynn")
|
data/lib/vidly.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'hashie', '~> 0.1.3'
|
4
|
+
require 'hashie'
|
5
|
+
|
6
|
+
gem 'httparty', '~> 0.4.3'
|
7
|
+
require 'httparty'
|
8
|
+
|
9
|
+
require 'cgi'
|
10
|
+
|
11
|
+
class Vidly
|
12
|
+
include HTTParty
|
13
|
+
base_uri 'api.vidly.com/0.1'
|
14
|
+
format :json
|
15
|
+
|
16
|
+
def initialize(username, password)
|
17
|
+
@auth = {:username => username, :password => password}
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload(file, options={})
|
21
|
+
upload_file("/upload.json", file, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def upload_and_post(file, options={})
|
25
|
+
upload_file("/uploadAndPost.json", file, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def import(url, options={})
|
29
|
+
self.class.mashup(self.class.post("/import.json", {:basic_auth => @auth, :body => default_video_options.merge(options.merge({:url => url})) }))
|
30
|
+
end
|
31
|
+
|
32
|
+
def import_and_post(url, options={})
|
33
|
+
self.class.mashup(self.class.post("/importAndPost.json", {:basic_auth => @auth, :body => default_video_options.merge(options.merge({:url => url})) }))
|
34
|
+
end
|
35
|
+
|
36
|
+
def status(id)
|
37
|
+
info = self.class.mashup(self.class.post("/status.json", {:basic_auth => @auth, :body => {:id => id}}))
|
38
|
+
%w(views retweets likes).each do |key|
|
39
|
+
info.meta[key] = info.meta[key].to_i
|
40
|
+
end
|
41
|
+
info
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.videos(username)
|
45
|
+
mashup(get("/videos/#{username}.json"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.meta(url)
|
49
|
+
mashup(get("/import/meta.json", :query => {:url => url}))
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.url(id)
|
53
|
+
"http://vid.ly/#{id}"
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def default_video_options
|
60
|
+
{:source => "Ruby gem"}
|
61
|
+
end
|
62
|
+
|
63
|
+
# yerked from Twitter gem
|
64
|
+
|
65
|
+
def self.mime_type(file)
|
66
|
+
case
|
67
|
+
when file =~ /\.jpg/ then 'image/jpg'
|
68
|
+
when file =~ /\.gif$/ then 'image/gif'
|
69
|
+
when file =~ /\.png$/ then 'image/png'
|
70
|
+
else 'application/octet-stream'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
def mime_type(f) self.class.mime_type(f) end
|
74
|
+
|
75
|
+
CRLF = "\r\n"
|
76
|
+
def self.build_multipart_bodies(parts)
|
77
|
+
boundary = Time.now.to_i.to_s(16)
|
78
|
+
body = ""
|
79
|
+
parts.each do |key, value|
|
80
|
+
esc_key = CGI.escape(key.to_s)
|
81
|
+
body << "--#{boundary}#{CRLF}"
|
82
|
+
if value.respond_to?(:read)
|
83
|
+
body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}"
|
84
|
+
body << "Content-Type: #{mime_type(value.path)}#{CRLF*2}"
|
85
|
+
body << value.read
|
86
|
+
else
|
87
|
+
body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
|
88
|
+
end
|
89
|
+
body << CRLF
|
90
|
+
end
|
91
|
+
body << "--#{boundary}--#{CRLF*2}"
|
92
|
+
{
|
93
|
+
:body => body,
|
94
|
+
:headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_multipart_bodies(parts) self.class.build_multipart_bodies(parts) end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def self.raise_errors(data)
|
103
|
+
raise(StandardError.new(data), data.inspect) if data.keys.include?('code')
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.mashup(data)
|
107
|
+
raise_errors(data)
|
108
|
+
Hashie::Mash.new(data['response'])
|
109
|
+
end
|
110
|
+
|
111
|
+
def upload_file(path, file, options={})
|
112
|
+
file = File.new(file) if file.is_a?(String)
|
113
|
+
body_options = default_video_options.merge(options).merge({:media => file})
|
114
|
+
opts = build_multipart_bodies(body_options).merge({:basic_auth => @auth})
|
115
|
+
self.class.mashup(self.class.post(path, opts))
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
{
|
2
|
+
"status": "ok",
|
3
|
+
"response": {
|
4
|
+
"videos": [{
|
5
|
+
"title": "Speaking to the troops in Baghdad. What a fantastic trip.",
|
6
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/2kglrTg4-large-1.jpg",
|
7
|
+
"id": "bH7u",
|
8
|
+
"entered": "2009-11-19 15:10:18",
|
9
|
+
"since": "1 week ago",
|
10
|
+
"views": false
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"title": "in case you missed it, here is a clip from our water press conf. That's what I call bipartisan.",
|
14
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/Il1GChVs-large-1.jpg",
|
15
|
+
"id": "afSs",
|
16
|
+
"entered": "2009-11-04 14:51:14",
|
17
|
+
"since": "3 weeks ago",
|
18
|
+
"views": false
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"title": "At the grand opening of a great new green car plant in Stockton.",
|
22
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/fa4HUdc6-large-1.jpg",
|
23
|
+
"id": "afSo",
|
24
|
+
"entered": "2009-11-04 14:26:06",
|
25
|
+
"since": "3 weeks ago",
|
26
|
+
"views": false
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"title": "Just now answering questions after restoring funding to keep domestic violence shelters open",
|
30
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/G5MwMfPJ-large-1.jpg",
|
31
|
+
"id": "af4L",
|
32
|
+
"entered": "2009-10-21 16:07:24",
|
33
|
+
"since": "1 month ago",
|
34
|
+
"views": false
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"title": "Signed a memorandum of understanding with Gov Osuna frm Baja",
|
38
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/xFmWa5dY-large-1.jpg",
|
39
|
+
"id": "af2W",
|
40
|
+
"entered": "2009-10-20 15:45:55",
|
41
|
+
"since": "1 month ago",
|
42
|
+
"views": false
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"title": "Checking out the hydrogen fuel cell electric truck",
|
46
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/sRQW5ciO-large-1.jpg",
|
47
|
+
"id": "af2F",
|
48
|
+
"entered": "2009-10-20 12:14:36",
|
49
|
+
"since": "1 month ago",
|
50
|
+
"views": false
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"title": "Signing bills to fight drunk driving just now",
|
54
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/dTzvaPKC-large-1.jpg",
|
55
|
+
"id": "aer4",
|
56
|
+
"entered": "2009-10-13 14:11:22",
|
57
|
+
"since": "1 month ago",
|
58
|
+
"views": false
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"title": "Video of my closing remarks at the #climate summit \u2013 thanks to so many fantastic people for making the summit a success!",
|
62
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/O71Hfcl4-large-1.jpg",
|
63
|
+
"id": "aeVz",
|
64
|
+
"entered": "2009-10-02 19:02:32",
|
65
|
+
"since": "1 month ago",
|
66
|
+
"views": false
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"title": "Check out the video of the port we visited yesterday to announce millions for cleaner technology to create a healthier CA",
|
70
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/mUiTK8Zp-large-1.jpg",
|
71
|
+
"id": "aeVV",
|
72
|
+
"entered": "2009-10-02 15:09:05",
|
73
|
+
"since": "1 month ago",
|
74
|
+
"views": false
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"title": "Surprised @edbegleyjr w\/ a special award - he's the king of practicing what he preaches about going green",
|
78
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/1gUl2Z0Z-large-1.jpg",
|
79
|
+
"id": "aeRK",
|
80
|
+
"entered": "2009-09-30 22:31:23",
|
81
|
+
"since": "1 month ago",
|
82
|
+
"views": false
|
83
|
+
},
|
84
|
+
{
|
85
|
+
"title": "Here's a short clip of an interview I just did with Judy Woodruff abt our regional approach to climate change.",
|
86
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/QXZdcFAp-large-1.jpg",
|
87
|
+
"id": "aeQu",
|
88
|
+
"entered": "2009-09-30 18:47:04",
|
89
|
+
"since": "2 months ago",
|
90
|
+
"views": false
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"title": "Video abt my Exec. Order requiring 33% of CA energy to come from renewable sources by 2020. This is for a cleaner world.",
|
94
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/gfUqZNFJ-large-1.jpg",
|
95
|
+
"id": "adU8",
|
96
|
+
"entered": "2009-09-18 17:55:07",
|
97
|
+
"since": "2 months ago",
|
98
|
+
"views": false
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"title": "Happy Birthday Patrick",
|
102
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/mLddaOei-large-1.jpg",
|
103
|
+
"id": "adSm",
|
104
|
+
"entered": "2009-09-18 14:00:08",
|
105
|
+
"since": "2 months ago",
|
106
|
+
"views": false
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"title": "Join me & serve your community. If you already volunteer, inspire others & tweet what you do, use #volunteer.",
|
110
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/588WINUW-large-1.jpg",
|
111
|
+
"id": "ad4A",
|
112
|
+
"entered": "2009-09-13 01:13:07",
|
113
|
+
"since": "2 months ago",
|
114
|
+
"views": false
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"title": "A video message to our brave firefighters \u2013 thank you for keeping us safe.",
|
118
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/qRuIzyip-large-1.jpg",
|
119
|
+
"id": "actM",
|
120
|
+
"entered": "2009-09-04 18:39:34",
|
121
|
+
"since": "2 months ago",
|
122
|
+
"views": false
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"title": "Here's a video of my tour with @biz and @ev at Twitter HQ today.",
|
126
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/CWgCvW3K-large-1.jpg",
|
127
|
+
"id": "acgO",
|
128
|
+
"entered": "2009-08-26 20:41:26",
|
129
|
+
"since": "3 months ago",
|
130
|
+
"views": false
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"title": "Check out my weekly video address about fundamentally reforming & fixing the California education system.",
|
134
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/TUW9HpNv-large-1.jpg",
|
135
|
+
"id": "acat",
|
136
|
+
"entered": "2009-08-21 19:17:02",
|
137
|
+
"since": "3 months ago",
|
138
|
+
"views": false
|
139
|
+
},
|
140
|
+
{
|
141
|
+
"title": "Here I am updating the press about the budget today.",
|
142
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/iaXQTEX9-large-1.jpg",
|
143
|
+
"id": "abwf",
|
144
|
+
"entered": "2009-07-22 16:37:35",
|
145
|
+
"since": "4 months ago",
|
146
|
+
"views": false
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"title": "Here\u2019s a video I just shot for my twitter followers.",
|
150
|
+
"image": "http:\/\/imgs.vidly-cdn.com\/7WVfIq5a-large-1.jpg",
|
151
|
+
"id": "abv1",
|
152
|
+
"entered": "2009-07-21 14:19:36",
|
153
|
+
"since": "4 months ago",
|
154
|
+
"views": false
|
155
|
+
}],
|
156
|
+
"real_name": "Gov. Schwarzenegger",
|
157
|
+
"total": "19"
|
158
|
+
}
|
159
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"status": "ok",
|
3
|
+
"response": {
|
4
|
+
"title": "Evolution of Dance",
|
5
|
+
"description": "The funniest 6 minutes you will ever see! Remember how many of these you have done! Follow @ http:\/\/www.twitter.com\/judsonlaipply Check my book out at http:\/\/www.mightaswelldance.com \nhttp:\/\/www.theevolutionofdance.com -\nfor more info including song list!",
|
6
|
+
"keywords": ["Dancing, comedy"],
|
7
|
+
"url": "http:\/\/www.youtube.com\/watch?v=dMH0bHeiRNg&feature=youtube_gdata",
|
8
|
+
"thumbnails": ["http:\/\/i.ytimg.com\/vi\/dMH0bHeiRNg\/default.jpg", "http:\/\/i.ytimg.com\/vi\/dMH0bHeiRNg\/2.jpg", "http:\/\/i.ytimg.com\/vi\/dMH0bHeiRNg\/1.jpg", "http:\/\/i.ytimg.com\/vi\/dMH0bHeiRNg\/3.jpg", "http:\/\/i.ytimg.com\/vi\/dMH0bHeiRNg\/hqdefault.jpg"],
|
9
|
+
"source": "youtube"
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"status": "ok",
|
3
|
+
"response": {
|
4
|
+
"twitter_status": "Test video",
|
5
|
+
"state": "ready",
|
6
|
+
"meta": {
|
7
|
+
"views": "399293",
|
8
|
+
"retweets": "1323",
|
9
|
+
"likes": "1423"
|
10
|
+
},
|
11
|
+
"id": "bHXX",
|
12
|
+
"url": "http:\/\/vid.ly\/bHXX",
|
13
|
+
"image": "http:\/\/vim.gs\/bHXX-large-1.jpg"
|
14
|
+
}
|
15
|
+
}
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
gem 'thoughtbot-shoulda', '>= 2.10.1'
|
6
|
+
gem 'jnunemaker-matchy', '0.4.0'
|
7
|
+
gem 'mocha', '0.9.4'
|
8
|
+
gem 'fakeweb', '>= 1.2.5'
|
9
|
+
|
10
|
+
require 'shoulda'
|
11
|
+
require 'matchy'
|
12
|
+
require 'mocha'
|
13
|
+
require 'fakeweb'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'vidly'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
21
|
+
|
22
|
+
FakeWeb.allow_net_connect = false
|
23
|
+
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
end
|
27
|
+
|
28
|
+
def binary_file_fixture(filename)
|
29
|
+
File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
30
|
+
end
|
31
|
+
|
32
|
+
def fixture_file(filename)
|
33
|
+
return '' if filename == ''
|
34
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
35
|
+
File.read(file_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def vidly_url(url)
|
39
|
+
url =~ /^http/ ? url : "http://vidly.com:80#{url}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def stub_post(url, filename, status=nil)
|
43
|
+
options = {:body => fixture_file(filename)}
|
44
|
+
options.merge!({:status => status}) unless status.nil?
|
45
|
+
|
46
|
+
FakeWeb.register_uri(:post, vidly_url(url), options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_get(url, filename, status=nil)
|
50
|
+
options = {:body => fixture_file(filename)}
|
51
|
+
options.merge!({:status => status}) unless status.nil?
|
52
|
+
|
53
|
+
FakeWeb.register_uri(:get, vidly_url(url), options)
|
54
|
+
end
|
data/test/test_vidly.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestVidly < Test::Unit::TestCase
|
4
|
+
context "When hitting the Vid.ly API" do
|
5
|
+
|
6
|
+
should "return a Vid.ly url based on video id" do
|
7
|
+
Vidly.url('af2W').should == 'http://vid.ly/af2W'
|
8
|
+
end
|
9
|
+
|
10
|
+
should "should retrieve the videos for a user" do
|
11
|
+
stub_get 'http://api.vidly.com/0.1/videos/Schwarzenegger.json', 'Schwarzenegger.json'
|
12
|
+
results = Vidly.videos('Schwarzenegger')
|
13
|
+
results.videos.size.should == 19
|
14
|
+
results.videos.last.image.should == 'http://imgs.vidly-cdn.com/7WVfIq5a-large-1.jpg'
|
15
|
+
results.real_name.should == 'Gov. Schwarzenegger'
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
should "import the meta information of videos from external services" do
|
20
|
+
stub_get 'http://api.vidly.com/0.1/import/meta.json?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdMH0bHeiRNg', 'meta.json'
|
21
|
+
results = Vidly.meta('http://www.youtube.com/watch?v=dMH0bHeiRNg')
|
22
|
+
results.title.should == 'Evolution of Dance'
|
23
|
+
results.source.should == 'youtube'
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when authenticated" do
|
27
|
+
setup do
|
28
|
+
@vidly = Vidly.new('myuser', 'mypass')
|
29
|
+
end
|
30
|
+
|
31
|
+
should "upload a file" do
|
32
|
+
stub_post "http://myuser:mypass@api.vidly.com/0.1/upload.json", "upload.json"
|
33
|
+
result = @vidly.upload(File.new(binary_file_fixture('test.m4v')), {:source => 'ruby gem', :status => 'Test video'})
|
34
|
+
result.url.should == 'http://vid.ly/bHXN'
|
35
|
+
end
|
36
|
+
|
37
|
+
should "upload a file and update twitter status" do
|
38
|
+
stub_post "http://myuser:mypass@api.vidly.com/0.1/uploadAndPost.json", "upload.json"
|
39
|
+
result = @vidly.upload_and_post(File.new(binary_file_fixture('test.m4v')), {:source => 'ruby gem', :status => 'Test video'})
|
40
|
+
result.url.should == 'http://vid.ly/bHXN'
|
41
|
+
end
|
42
|
+
|
43
|
+
should "import a video from a url" do
|
44
|
+
stub_post "http://myuser:mypass@api.vidly.com/0.1/import.json", "import.json"
|
45
|
+
result = @vidly.import("http://www.youtube.com/watch?v=dMH0bHeiRNg", :source => 'ruby gem', :status => "Evolution of dance")
|
46
|
+
result.url.should == "http://vid.ly/bHXp"
|
47
|
+
end
|
48
|
+
|
49
|
+
should "import a video from a url and update twitter status" do
|
50
|
+
stub_post "http://myuser:mypass@api.vidly.com/0.1/importAndPost.json", "import.json"
|
51
|
+
result = @vidly.import_and_post("http://www.youtube.com/watch?v=dMH0bHeiRNg", :source => 'ruby gem', :status => "Evolution of dance")
|
52
|
+
result.url.should == "http://vid.ly/bHXp"
|
53
|
+
end
|
54
|
+
|
55
|
+
should "get the current status of a video" do
|
56
|
+
stub_post "http://myuser:mypass@api.vidly.com/0.1/status.json", "status.json"
|
57
|
+
result = @vidly.status("bHXX")
|
58
|
+
result.meta.retweets.should == 1323
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vidly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wynn Netherland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-30 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hashie
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thoughtbot-shoulda
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.10.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: jnunemaker-matchy
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.4.0
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.9.4
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: fakeweb
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.2.5
|
74
|
+
version:
|
75
|
+
description: Post your videos to Twitter with Vid.ly
|
76
|
+
email: wynn.netherland@gmail.com
|
77
|
+
executables: []
|
78
|
+
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files:
|
82
|
+
- LICENSE
|
83
|
+
- README.markdown
|
84
|
+
files:
|
85
|
+
- .document
|
86
|
+
- .gitignore
|
87
|
+
- LICENSE
|
88
|
+
- README.markdown
|
89
|
+
- Rakefile
|
90
|
+
- VERSION
|
91
|
+
- changelog.markdown
|
92
|
+
- examples/upload.rb
|
93
|
+
- lib/vidly.rb
|
94
|
+
- test/fixtures/Schwarzenegger.json
|
95
|
+
- test/fixtures/import.json
|
96
|
+
- test/fixtures/meta.json
|
97
|
+
- test/fixtures/status.json
|
98
|
+
- test/fixtures/test.m4v
|
99
|
+
- test/fixtures/upload.json
|
100
|
+
- test/helper.rb
|
101
|
+
- test/test_vidly.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: http://github.com/pengwynn/vidly
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
version:
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
version:
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.3.5
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Ruby wrapper for the Vid.ly API
|
130
|
+
test_files:
|
131
|
+
- test/helper.rb
|
132
|
+
- test/test_vidly.rb
|
133
|
+
- examples/upload.rb
|