slainer68_vimeo 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +24 -0
- data/LICENSE +20 -0
- data/README.markdown +330 -0
- data/Rakefile +100 -0
- data/VERSION.yml +5 -0
- data/init.rb +2 -0
- data/lib/vimeo/advanced/album.rb +55 -0
- data/lib/vimeo/advanced/base.rb +126 -0
- data/lib/vimeo/advanced/channel.rb +55 -0
- data/lib/vimeo/advanced/contact.rb +30 -0
- data/lib/vimeo/advanced/group.rb +62 -0
- data/lib/vimeo/advanced/group_events.rb +25 -0
- data/lib/vimeo/advanced/group_forums.rb +19 -0
- data/lib/vimeo/advanced/person.rb +47 -0
- data/lib/vimeo/advanced/simple_upload/chunk.rb +50 -0
- data/lib/vimeo/advanced/simple_upload/task.rb +85 -0
- data/lib/vimeo/advanced/simple_upload.rb +46 -0
- data/lib/vimeo/advanced/test.rb +19 -0
- data/lib/vimeo/advanced/upload.rb +35 -0
- data/lib/vimeo/advanced/video.rb +141 -0
- data/lib/vimeo/advanced/video_embed.rb +17 -0
- data/lib/vimeo/advanced.rb +20 -0
- data/lib/vimeo/simple/activity.rb +42 -0
- data/lib/vimeo/simple/album.rb +21 -0
- data/lib/vimeo/simple/base.rb +10 -0
- data/lib/vimeo/simple/channel.rb +21 -0
- data/lib/vimeo/simple/group.rb +28 -0
- data/lib/vimeo/simple/user.rb +89 -0
- data/lib/vimeo/simple/video.rb +14 -0
- data/lib/vimeo/simple.rb +14 -0
- data/lib/vimeo.rb +12 -0
- data/slainer68_vimeo.gemspec +227 -0
- data/test/fixtures/advanced/album/add_video.json +4 -0
- data/test/fixtures/advanced/album/create.json +7 -0
- data/test/fixtures/advanced/album/delete.json +4 -0
- data/test/fixtures/advanced/album/get_all.json +111 -0
- data/test/fixtures/advanced/album/get_videos.json +30 -0
- data/test/fixtures/advanced/album/remove_video.json +4 -0
- data/test/fixtures/advanced/album/set_description.json +4 -0
- data/test/fixtures/advanced/album/set_password.json +4 -0
- data/test/fixtures/advanced/album/set_title.json +4 -0
- data/test/fixtures/advanced/auth/access_token.txt +1 -0
- data/test/fixtures/advanced/auth/check_access_token.json +9 -0
- data/test/fixtures/advanced/auth/check_token.json +13 -0
- data/test/fixtures/advanced/auth/get_frob.json +5 -0
- data/test/fixtures/advanced/auth/get_token.json +13 -0
- data/test/fixtures/advanced/auth/request_token.txt +1 -0
- data/test/fixtures/advanced/channel/add_video.json +4 -0
- data/test/fixtures/advanced/channel/get_all.json +1357 -0
- data/test/fixtures/advanced/channel/get_info.json +55 -0
- data/test/fixtures/advanced/channel/get_moderators.json +45 -0
- data/test/fixtures/advanced/channel/get_subscribers.json +44 -0
- data/test/fixtures/advanced/channel/get_videos.json +19 -0
- data/test/fixtures/advanced/channel/remove_video.json +4 -0
- data/test/fixtures/advanced/channel/subscribe.json +4 -0
- data/test/fixtures/advanced/channel/unsubscribe.json +4 -0
- data/test/fixtures/advanced/contact/get_all.json +117 -0
- data/test/fixtures/advanced/contact/get_mutual.json +80 -0
- data/test/fixtures/advanced/contact/get_online.json +47 -0
- data/test/fixtures/advanced/contact/get_who_added.json +117 -0
- data/test/fixtures/advanced/group/add_video.json +4 -0
- data/test/fixtures/advanced/group/get_all.json +1532 -0
- data/test/fixtures/advanced/group/get_files.json +255 -0
- data/test/fixtures/advanced/group/get_info.json +72 -0
- data/test/fixtures/advanced/group/get_members.json +862 -0
- data/test/fixtures/advanced/group/get_moderators.json +44 -0
- data/test/fixtures/advanced/group/get_video_comments.json +96 -0
- data/test/fixtures/advanced/group/get_videos.json +102 -0
- data/test/fixtures/advanced/group/join.json +4 -0
- data/test/fixtures/advanced/group/leave.json +4 -0
- data/test/fixtures/advanced/group_events/get_month.json +141 -0
- data/test/fixtures/advanced/group_events/get_past.json +141 -0
- data/test/fixtures/advanced/group_events/get_upcoming.json +141 -0
- data/test/fixtures/advanced/group_forums/get_topic_comments.json +222 -0
- data/test/fixtures/advanced/group_forums/get_topics.json +504 -0
- data/test/fixtures/advanced/person/add_contact.json +4 -0
- data/test/fixtures/advanced/person/add_subscription.json +4 -0
- data/test/fixtures/advanced/person/find_by_email.json +9 -0
- data/test/fixtures/advanced/person/get_hd_embeds.json +8 -0
- data/test/fixtures/advanced/person/get_info.json +20 -0
- data/test/fixtures/advanced/person/get_portrait_urls.json +28 -0
- data/test/fixtures/advanced/person/remove_contact.json +4 -0
- data/test/fixtures/advanced/person/remove_subscription.json +4 -0
- data/test/fixtures/advanced/test/echo.json +8 -0
- data/test/fixtures/advanced/test/login.json +8 -0
- data/test/fixtures/advanced/test/null.json +4 -0
- data/test/fixtures/advanced/upload/get_quota.json +16 -0
- data/test/fixtures/advanced/upload/get_ticket.json +8 -0
- data/test/fixtures/advanced/upload/sample_iTunes.mov +0 -0
- data/test/fixtures/advanced/video/add_cast.json +4 -0
- data/test/fixtures/advanced/video/add_comment.json +7 -0
- data/test/fixtures/advanced/video/add_photos.json +4 -0
- data/test/fixtures/advanced/video/add_tags.json +4 -0
- data/test/fixtures/advanced/video/clear_tags.json +4 -0
- data/test/fixtures/advanced/video/delete.json +4 -0
- data/test/fixtures/advanced/video/delete_comment.json +4 -0
- data/test/fixtures/advanced/video/edit_comment.json +4 -0
- data/test/fixtures/advanced/video/get_all.json +30 -0
- data/test/fixtures/advanced/video/get_appears_in.json +10 -0
- data/test/fixtures/advanced/video/get_by_tag.json +237 -0
- data/test/fixtures/advanced/video/get_cast.json +42 -0
- data/test/fixtures/advanced/video/get_comments_list.json +52 -0
- data/test/fixtures/advanced/video/get_contacts_liked.json +48 -0
- data/test/fixtures/advanced/video/get_contacts_uploaded.json +237 -0
- data/test/fixtures/advanced/video/get_info.json +246 -0
- data/test/fixtures/advanced/video/get_likes.json +32 -0
- data/test/fixtures/advanced/video/get_subscriptions.json +237 -0
- data/test/fixtures/advanced/video/get_thumbnail_urls.json +28 -0
- data/test/fixtures/advanced/video/get_uploaded.json +30 -0
- data/test/fixtures/advanced/video/remove_cast.json +4 -0
- data/test/fixtures/advanced/video/remove_tag.json +4 -0
- data/test/fixtures/advanced/video/search.json +237 -0
- data/test/fixtures/advanced/video/set_description.json +4 -0
- data/test/fixtures/advanced/video/set_like.json +4 -0
- data/test/fixtures/advanced/video/set_preset.json +4 -0
- data/test/fixtures/advanced/video/set_privacy.json +4 -0
- data/test/fixtures/advanced/video/set_title.json +4 -0
- data/test/fixtures/advanced/video_embed/get_presets.json +8 -0
- data/test/fixtures/advanced/video_embed/set_preset.json +4 -0
- data/test/fixtures/simple/activity/contacts_did.json +1 -0
- data/test/fixtures/simple/activity/everyone_did.json +1 -0
- data/test/fixtures/simple/activity/happened_to_contacts.json +1 -0
- data/test/fixtures/simple/activity/happened_to_user.json +1 -0
- data/test/fixtures/simple/activity/user_did.json +1 -0
- data/test/fixtures/simple/album/info.json +1 -0
- data/test/fixtures/simple/album/videos.json +1 -0
- data/test/fixtures/simple/channel/info.json +1 -0
- data/test/fixtures/simple/channel/videos.json +1 -0
- data/test/fixtures/simple/group/info.json +1 -0
- data/test/fixtures/simple/group/users.json +1 -0
- data/test/fixtures/simple/group/videos.json +1 -0
- data/test/fixtures/simple/user/albums.json +1 -0
- data/test/fixtures/simple/user/all_videos.json +1 -0
- data/test/fixtures/simple/user/appears_in.json +1 -0
- data/test/fixtures/simple/user/channels.json +1 -0
- data/test/fixtures/simple/user/contacts_like.json +1 -0
- data/test/fixtures/simple/user/contacts_videos.json +1 -0
- data/test/fixtures/simple/user/groups.json +1 -0
- data/test/fixtures/simple/user/info.json +1 -0
- data/test/fixtures/simple/user/likes.json +1 -0
- data/test/fixtures/simple/user/subscriptions.json +1 -0
- data/test/fixtures/simple/user/videos.json +1 -0
- data/test/fixtures/simple/video/info.json +1 -0
- data/test/test_helper.rb +64 -0
- data/test/vimeo/advanced/album_test.rb +75 -0
- data/test/vimeo/advanced/auth_test.rb +30 -0
- data/test/vimeo/advanced/base_test.rb +21 -0
- data/test/vimeo/advanced/channels_test.rb +79 -0
- data/test/vimeo/advanced/contacts_test.rb +40 -0
- data/test/vimeo/advanced/group_events_test.rb +33 -0
- data/test/vimeo/advanced/group_forums_test.rb +26 -0
- data/test/vimeo/advanced/groups_test.rb +82 -0
- data/test/vimeo/advanced/person_test.rb +69 -0
- data/test/vimeo/advanced/test_test.rb +33 -0
- data/test/vimeo/advanced/upload_test.rb +25 -0
- data/test/vimeo/advanced/videos_embed_test.rb +27 -0
- data/test/vimeo/advanced/videos_test.rb +212 -0
- data/test/vimeo/advanced_test.rb +0 -0
- data/test/vimeo/simple/activity_test.rb +60 -0
- data/test/vimeo/simple/album_test.rb +31 -0
- data/test/vimeo/simple/channel_test.rb +31 -0
- data/test/vimeo/simple/group_test.rb +41 -0
- data/test/vimeo/simple/user_test.rb +112 -0
- data/test/vimeo/simple/video_test.rb +22 -0
- data/test/vimeo/simple_test.rb +0 -0
- data/test/vimeo_test.rb +0 -0
- metadata +304 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
== 1.0.0, released 2009-09-28
|
2
|
+
|
3
|
+
* Upgraded to v2 of the API.
|
4
|
+
* Added some upload helpers.
|
5
|
+
* Huge refactor for the Advanced API making it easier to add/modify method calls.
|
6
|
+
|
7
|
+
== 0.2.2, released 2009-04-21
|
8
|
+
|
9
|
+
* Removed CGI escapes. Vimeo should be handling them on their end.
|
10
|
+
|
11
|
+
== 0.2.1, released 2009-01-06
|
12
|
+
|
13
|
+
* Last version was missing files.
|
14
|
+
|
15
|
+
== 0.2.0, released 2009-01-06
|
16
|
+
|
17
|
+
* Major re-factor of each request method.
|
18
|
+
* Separated the simple and advanced APIs into their own modules.
|
19
|
+
* Added some documentation.
|
20
|
+
* Updated the README.
|
21
|
+
|
22
|
+
== 0.1.2, released 2008-10-26
|
23
|
+
|
24
|
+
* Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Matt Hooks
|
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,330 @@
|
|
1
|
+
# Vimeo API Gem
|
2
|
+
|
3
|
+
This gem implements a full-featured Ruby interface for the Vimeo API v2.
|
4
|
+
|
5
|
+
For a more in depth look at the API check out [Vimeo's Simple API Documentation](http://www.vimeo.com/api/docs/simple-api) or [Vimeo's Advanced API Documentation](http://www.vimeo.com/api/docs/advanced-api). I would also recommend checking out the [API Forums](http://www.vimeo.com/forum:api) if things aren't working as they should.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
First, install [Gemcutter](http://gemcutter.org), then:
|
10
|
+
|
11
|
+
sudo gem install vimeo
|
12
|
+
|
13
|
+
If you're using Rails, add the following to your environment.rb file:
|
14
|
+
|
15
|
+
config.gem "vimeo"
|
16
|
+
|
17
|
+
Or for bundler:
|
18
|
+
|
19
|
+
gem 'vimeo'
|
20
|
+
|
21
|
+
## How to Use
|
22
|
+
|
23
|
+
There are two modules:
|
24
|
+
|
25
|
+
Vimeo::Simple
|
26
|
+
Vimeo::Advanced
|
27
|
+
|
28
|
+
## Simple API
|
29
|
+
|
30
|
+
Let's look at the [Simple API](http://www.vimeo.com/api/docs/simple-api) first.
|
31
|
+
|
32
|
+
The wrapper for the Simple API consists of several classes. To use the Simple API, just call one of the class methods. For example:
|
33
|
+
|
34
|
+
user_info = Vimeo::Simple::User.info("matthooks")
|
35
|
+
# =>
|
36
|
+
# {
|
37
|
+
# "id":"888046",
|
38
|
+
# "display_name":"Matt Hooks",
|
39
|
+
# "created_on":"2008-10-30 14:17:32",
|
40
|
+
# "is_staff":"0",
|
41
|
+
# "is_plus":"0",
|
42
|
+
# "location":"Chicago, IL",
|
43
|
+
# "url":"http:\/\/blackholeinthemidwest.com\/",
|
44
|
+
# "bio":"",
|
45
|
+
# "profile_url":"http:\/\/vimeo.com\/matthooks",
|
46
|
+
# "videos_url":"http:\/\/vimeo.com\/matthooks\/videos",
|
47
|
+
# "total_videos_appears_ined":2,
|
48
|
+
# "total_videos_appears_in":0,
|
49
|
+
# "total_videos_liked":2,
|
50
|
+
# "total_contacts":3,
|
51
|
+
# "total_albums":0,
|
52
|
+
# "total_channels":1,
|
53
|
+
# "portrait_small":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_30.jpg",
|
54
|
+
# "portrait_medium":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_75.jpg",
|
55
|
+
# "portrait_large":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_100.jpg",
|
56
|
+
# "portrait_huge":"http:\/\/images.vimeo.com\/11\/42\/16\/114216178\/114216178_300.jpg"
|
57
|
+
# }
|
58
|
+
|
59
|
+
Thanks to HTTParty, the data is parsed and ready to use.
|
60
|
+
|
61
|
+
user_info["location"]
|
62
|
+
# => "Chicago, IL"
|
63
|
+
|
64
|
+
## Overview of the Simple API
|
65
|
+
|
66
|
+
### Vimeo::Simple::Activity
|
67
|
+
|
68
|
+
Vimeo::Simple::Activity.user_did("username")
|
69
|
+
Vimeo::Simple::Activity.happened_to_user("username")
|
70
|
+
Vimeo::Simple::Activity.contacts_did("username")
|
71
|
+
Vimeo::Simple::Activity.happened_to_contacts("username")
|
72
|
+
Vimeo::Simple::Activity.everyone_did("username")
|
73
|
+
|
74
|
+
### Vimeo::Simple::Album
|
75
|
+
|
76
|
+
Vimeo::Simple::Album.videos("album_id")
|
77
|
+
Vimeo::Simple::Album.info("album_id")
|
78
|
+
|
79
|
+
### Vimeo::Simple::Channel
|
80
|
+
|
81
|
+
Vimeo::Simple::Channel.videos("channelname")
|
82
|
+
Vimeo::Simple::Channel.info("channelname")
|
83
|
+
|
84
|
+
### Vimeo::Simple::Group
|
85
|
+
|
86
|
+
Vimeo::Simple::Group.videos("groupname")
|
87
|
+
Vimeo::Simple::Group.users("groupname")
|
88
|
+
Vimeo::Simple::Group.info("groupname")
|
89
|
+
|
90
|
+
### Vimeo::Simple::User
|
91
|
+
|
92
|
+
Vimeo::Simple::User.info("username")
|
93
|
+
Vimeo::Simple::User.videos("username")
|
94
|
+
Vimeo::Simple::User.likes("username")
|
95
|
+
Vimeo::Simple::User.appears_in("username")
|
96
|
+
Vimeo::Simple::User.all_videos("username")
|
97
|
+
Vimeo::Simple::User.subscriptions("username")
|
98
|
+
Vimeo::Simple::User.albums("username")
|
99
|
+
Vimeo::Simple::User.channels("username")
|
100
|
+
Vimeo::Simple::User.groups("username")
|
101
|
+
Vimeo::Simple::User.contacts_videos("username")
|
102
|
+
Vimeo::Simple::User.contacts_like("username")
|
103
|
+
|
104
|
+
### Vimeo::Simple::Video
|
105
|
+
|
106
|
+
Vimeo::Simple::Video.info("video_id")
|
107
|
+
|
108
|
+
## Advanced API
|
109
|
+
|
110
|
+
To use the [Advanced API](http://www.vimeo.com/api/docs/advanced-api), first you must authenticate your user using OAuth.
|
111
|
+
|
112
|
+
### Authentication Example using Rails
|
113
|
+
|
114
|
+
First, instantiate the Base class:
|
115
|
+
|
116
|
+
base = Vimeo::Advanced::Base.new("consumer_key", "consumer_secret")
|
117
|
+
|
118
|
+
Get a request token, and save the token secret in the session hash.
|
119
|
+
|
120
|
+
request_token = base.get_request_token
|
121
|
+
session[:oauth_secret] = request_token.secret
|
122
|
+
|
123
|
+
Then, send your user to the authorization URL:
|
124
|
+
|
125
|
+
redirect_to base.authorize_url
|
126
|
+
|
127
|
+
Once the user has allowed your application to access their account, they will be redirected to the callback URL you set up for your application. You will be given two parameters `oauth_token` and `oauth_verifier`. Re-instantiate your Base class, then get an access token.
|
128
|
+
|
129
|
+
base = Vimeo::Advanced::Base.new("consumer_key", "consumer_secret")
|
130
|
+
access_token = base.get_access_token(params[:oauth_token], session[:oauth_secret], params[:oauth_verifier])
|
131
|
+
# You'll want to hold on to the user's access token and secret. I'll save it to the database.
|
132
|
+
user.token = access_token.token
|
133
|
+
user.secret = access_token.secret
|
134
|
+
user.save
|
135
|
+
|
136
|
+
Now you've got everything you need to use the Advanced API. Let's get a user's videos:
|
137
|
+
|
138
|
+
video = Vimeo::Advanced::Video.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
139
|
+
video.get_videos("matthooks")
|
140
|
+
|
141
|
+
# => {"videos"=> { ... }, "stat"=>"ok", "generated_in"=>"0.5753"}
|
142
|
+
|
143
|
+
Piece of cake.
|
144
|
+
|
145
|
+
Some methods have optional variables. Pass these as a hash at the end of a call.
|
146
|
+
|
147
|
+
video.get_all("matthooks", :page => "2", :per_page => "50")
|
148
|
+
|
149
|
+
## Overview of the Advanced API
|
150
|
+
|
151
|
+
### Vimeo::Advanced::Album
|
152
|
+
|
153
|
+
album = Vimeo::Advanced::Album.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
154
|
+
|
155
|
+
album.add_video("album_id", "video_id")
|
156
|
+
album.create("title", "video_id", { :description => "description", "videos" => "123,124,125" })
|
157
|
+
album.delete("album_id")
|
158
|
+
album.get_all("user_id", { :page => "1", :per_page => "25", :sort => "newest" })
|
159
|
+
album.get_videos("album_id", { :page => "1", :per_page => "25", :full_response => "0", :password => nil })
|
160
|
+
album.remove_video("album_id", "video_id")
|
161
|
+
album.set_description("album_id", "description")
|
162
|
+
album.get_password("album_id", "password")
|
163
|
+
album.get_title("album_id", "title")
|
164
|
+
|
165
|
+
### Vimeo::Advanced::Base
|
166
|
+
|
167
|
+
base = Vimeo::Advanced::Base.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
168
|
+
|
169
|
+
base.check_access_token
|
170
|
+
|
171
|
+
### Vimeo::Advanced::Channel
|
172
|
+
|
173
|
+
channel = Vimeo::Advanced::Channel.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
174
|
+
|
175
|
+
channel.add_video("channel_id", "video_id")
|
176
|
+
channel.get_all({ :page => "1", :per_page => "25", :sort => "newest", :user_id => "user_id" })
|
177
|
+
channel.get_info(channel_id)
|
178
|
+
channel.get_moderators(channel_id, { :page => "1", :per_page => "25" })
|
179
|
+
channel.get_subscribers(channel_id, { :page => "1", :per_page => "25" })
|
180
|
+
channel.get_videos(channel_id, { :page => "1", :per_page => "25", :full_response => "0" })
|
181
|
+
channel.remove_video("channel_id", "video_id")
|
182
|
+
channel.subscribe("channel_id")
|
183
|
+
channel.unsubscribe("channel_id")
|
184
|
+
|
185
|
+
### Vimeo::Advanced::Contact
|
186
|
+
|
187
|
+
contact = Vimeo::Advanced::Contact.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
188
|
+
|
189
|
+
contact.get_all(user_id, { :page => "1", :per_page => "25", :sort => "newest" })
|
190
|
+
contact.get_mutual(user_id, { :page => "1", :per_page => "25" })
|
191
|
+
contact.get_online({ :page => "1", :per_page => "25" })
|
192
|
+
contact.get_who_added(user_id, { :page => "1", :per_page => "25", :sort => "newest" })
|
193
|
+
|
194
|
+
### Vimeo::Advanced::Group
|
195
|
+
|
196
|
+
group = Vimeo::Advanced::Group.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
197
|
+
|
198
|
+
group.add_video("group_id", "video_id")
|
199
|
+
group.get_all({ :page => "1", :per_page => "25", :sort => "newest", :user_id => "user_id" })
|
200
|
+
group.get_files("group_id", { :page => "1", :per_page => "25" })
|
201
|
+
group.get_info("group_id")
|
202
|
+
group.get_members("group_id", { :page => "1", :per_page => "25", :sort => "newest" })
|
203
|
+
group.get_moderators("group_id", { :page => "1", :per_page => "25" })
|
204
|
+
group.get_video_comments("group_id", "video_id", { :page => "1", :per_page => "25" })
|
205
|
+
group.get_videos("group_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
206
|
+
group.join("group_id")
|
207
|
+
group.leave("group_id")
|
208
|
+
|
209
|
+
### Vimeo::Advanced::GroupEvents
|
210
|
+
|
211
|
+
group_events = Vimeo::Advanced::GroupEvents.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
212
|
+
|
213
|
+
group_events.get_month("group_id", { :page => "1", :per_page => "25", :month => nil, :year => nil })
|
214
|
+
group_events.get_past("group_id", { :page => "1", :per_page => "25" })
|
215
|
+
group_events.get_year("group_id", { :page => "1", :per_page => "25" })
|
216
|
+
|
217
|
+
### Vimeo::Advanced::GroupForums
|
218
|
+
|
219
|
+
group_forums = Vimeo::Advanced::GroupForums.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
220
|
+
|
221
|
+
group_forums.get_topic_comments("group_id", "topic_id", { :page => "1", :per_page => "25" })
|
222
|
+
group_forums.get_topics("group_id", { :page => "1", :per_page => "25" })
|
223
|
+
|
224
|
+
### Vimeo::Advanced::Person
|
225
|
+
|
226
|
+
person = Vimeo::Advanced::Person.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
227
|
+
|
228
|
+
person.add_contact("user_id")
|
229
|
+
person.add_subscription("user_id", "types") # Types is a comma-delimited string. Valid: "likes", "appears", "uploads"
|
230
|
+
person.find_by_email("user_id")
|
231
|
+
person.get_hd_embeds
|
232
|
+
person.get_info("user_id")
|
233
|
+
person.get_portrait_urls("user_id")
|
234
|
+
person.remove_contact("user_id")
|
235
|
+
person.remove_subscription("user_id", "types") # Types is a comma-delimited string. Valid: "likes", "appears", "uploads"
|
236
|
+
|
237
|
+
### Vimeo::Advanced::Test
|
238
|
+
|
239
|
+
test = Vimeo::Advanced::Test.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
240
|
+
|
241
|
+
test.echo
|
242
|
+
test.null
|
243
|
+
test.login
|
244
|
+
|
245
|
+
### Vimeo::Advanced::Upload
|
246
|
+
|
247
|
+
upload = Vimeo::Advanced::Upload.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
248
|
+
|
249
|
+
# Other than get_quota, none of these methods should be called directly. The 'upload' method uses these internally.
|
250
|
+
upload.check_ticket("ticket_id")
|
251
|
+
upload.complete("ticket_id", "filename")
|
252
|
+
upload.get_ticket
|
253
|
+
upload.get_quota
|
254
|
+
upload.verify_chunks("ticket_id")
|
255
|
+
|
256
|
+
# all-in-one solution, supports File, String (a file path), #read
|
257
|
+
video_id = upload.upload("movie.mp4")
|
258
|
+
|
259
|
+
### Vimeo::Advanced::Video
|
260
|
+
|
261
|
+
video = Vimeo::Advanced::Video.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
262
|
+
|
263
|
+
video.add_cast("video_id", "user_id", { :role => nil })
|
264
|
+
video.add_photos("video_id", "photo_urls")
|
265
|
+
video.add_tags("video_id", "tags")
|
266
|
+
video.clear_tags("video_id")
|
267
|
+
video.delete("video_id")
|
268
|
+
video.get_all("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
269
|
+
video.get_appears_in("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
270
|
+
video.get_by_tag("tag", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
271
|
+
video.get_cast("video_id", { :page => "1", :per_page => "25" })
|
272
|
+
video.get_contacts_liked("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
273
|
+
video.get_contacts_uploaded("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
274
|
+
video.get_info("video_id")
|
275
|
+
video.get_likes("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
276
|
+
video.get_subscriptions("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
277
|
+
video.get_thumbnail_urls("video_id")
|
278
|
+
video.get_uploaded("user_id", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest" })
|
279
|
+
video.remove_cast("video_id", "user_id")
|
280
|
+
video.remove_tag("video_id", "tag_id")
|
281
|
+
video.search("query", { :page => "1", :per_page => "25", :full_response => "0", :sort => "newest", :user_id => nil })
|
282
|
+
video.set_description("video_id", "description")
|
283
|
+
video.set_like("video_id", "like")
|
284
|
+
video.set_privacy("video_id", "privacy", { :users => nil, :password => nil })
|
285
|
+
video.set_title("video_id", "title")
|
286
|
+
|
287
|
+
# comments
|
288
|
+
video.add_comment("video_id", "comment_text", { :reply_to_comment_id => nil })
|
289
|
+
video.delete_comment("video_id", "comment_id")
|
290
|
+
video.edit_comment("video_id", "comment_id", "comment_text")
|
291
|
+
video.get_comments_list("video_id", { :page => "1", :per_page => "25" })
|
292
|
+
|
293
|
+
### Vimeo::Advanced::VideoEmbed
|
294
|
+
|
295
|
+
video_embed = Vimeo::Advanced::VideoEmbed.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
296
|
+
|
297
|
+
video_embed.get_presets({ :page => "1", :per_page => "25" })
|
298
|
+
video_embed.set_preset("video_id", "preset_id")
|
299
|
+
|
300
|
+
## Uploads
|
301
|
+
|
302
|
+
Uploads are working! In order to upload a file, create your upload object, like so:
|
303
|
+
|
304
|
+
upload = Vimeo::Advanced::Upload.new("consumer_key", "consumer_secret", :token => user.token, :secret => user.secret)
|
305
|
+
|
306
|
+
Then call the upload method:
|
307
|
+
|
308
|
+
upload.upload("/path/to/file") # You can also pass a File object or any IO.
|
309
|
+
|
310
|
+
The upload method will automatically get an upload ticket, perform the multipart POST, verify the file chunks and then complete the upload.
|
311
|
+
|
312
|
+
## Todo
|
313
|
+
|
314
|
+
* Fix tests that cannot be stubbed because of OAuth nonce.
|
315
|
+
* Better structure. There's too many classes. Is there a way to simplify the Advanced API?
|
316
|
+
* Better error handling.
|
317
|
+
* More re-factoring.
|
318
|
+
* Make tests more robust and faster. If anyone has any ideas let me know.
|
319
|
+
|
320
|
+
## Contributors
|
321
|
+
|
322
|
+
* [matthooks](http://github.com/matthooks)
|
323
|
+
* [sirlantis](http://github.com/sirlantis)
|
324
|
+
|
325
|
+
## Thanks to
|
326
|
+
|
327
|
+
* [HTTParty](http://github.com/jnunemaker/httparty): Easily one of the best tools I have used since I started using Ruby.
|
328
|
+
* [Jeweler](http://github.com/technicalpickles/jeweler): Great tool for creating gems for Github.
|
329
|
+
|
330
|
+
### Copyright (c) 2009-2010 Matt Hooks. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "slainer68_vimeo"
|
8
|
+
gem.summary = %Q{A full featured Ruby implementation of the Vimeo API.}
|
9
|
+
gem.description = %Q{A full featured Ruby implementation of the Vimeo API.}
|
10
|
+
gem.email = "matthooks@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/matthooks/vimeo"
|
12
|
+
gem.authors = ["Matt Hooks"]
|
13
|
+
gem.rubyforge_project = "vimeo"
|
14
|
+
gem.add_development_dependency "shoulda", ">= 2.11.3"
|
15
|
+
gem.add_development_dependency "fakeweb", ">= 1.2.6"
|
16
|
+
gem.add_development_dependency "ruby-prof", ">= 0.9.2"
|
17
|
+
|
18
|
+
gem.has_rdoc = true
|
19
|
+
|
20
|
+
gem.rdoc_options = ['--main', 'README.rdoc', '--inline-source', '--charset=UTF-8']
|
21
|
+
gem.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'CHANGELOG.rdoc']
|
22
|
+
|
23
|
+
gem.add_dependency "multi_json", ">= 1.0.4"
|
24
|
+
gem.add_dependency "httparty", ">= 0.4.5"
|
25
|
+
gem.add_dependency "oauth", ">= 0.4.3"
|
26
|
+
gem.add_dependency "httpclient", ">= 2.1.5.2"
|
27
|
+
gem.add_dependency "multipart-post", ">= 1.0.1"
|
28
|
+
end
|
29
|
+
Jeweler::GemcutterTasks.new
|
30
|
+
rescue LoadError
|
31
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'rake/testtask'
|
35
|
+
Rake::TestTask.new(:test) do |test|
|
36
|
+
test.libs << 'lib' << 'test'
|
37
|
+
test.pattern = 'test/**/*_test.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
require 'rcov/rcovtask'
|
43
|
+
Rcov::RcovTask.new do |test|
|
44
|
+
test.libs << 'test'
|
45
|
+
test.pattern = 'test/**/*_test.rb'
|
46
|
+
test.verbose = true
|
47
|
+
end
|
48
|
+
rescue LoadError
|
49
|
+
task :rcov do
|
50
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
task :test => :check_dependencies
|
55
|
+
|
56
|
+
task :default => :test
|
57
|
+
|
58
|
+
namespace :vimeo do
|
59
|
+
desc "Multi-step wizard to acquire an access_token. CONSUMER_KEY and CONSUMER_SECRET required."
|
60
|
+
task :auth do
|
61
|
+
require 'vimeo'
|
62
|
+
|
63
|
+
def ask(message)
|
64
|
+
print message
|
65
|
+
STDOUT.flush
|
66
|
+
STDIN.gets.chomp
|
67
|
+
end
|
68
|
+
|
69
|
+
consumer_key = ENV['CONSUMER_KEY']
|
70
|
+
consumer_secret = ENV['CONSUMER_SECRET']
|
71
|
+
base = Vimeo::Advanced::Base.new(consumer_key, consumer_secret)
|
72
|
+
|
73
|
+
request_token = base.get_request_token
|
74
|
+
oauth_secret = request_token.secret
|
75
|
+
|
76
|
+
puts "Please visit: #{base.authorize_url}"
|
77
|
+
|
78
|
+
oauth_token = ask("oauth_token=")
|
79
|
+
oauth_verifier = ask("oauth_verifier=")
|
80
|
+
|
81
|
+
access_token = base.get_access_token(oauth_token, oauth_secret, oauth_verifier)
|
82
|
+
|
83
|
+
puts "token: #{access_token.token}"
|
84
|
+
puts "secret: #{access_token.secret}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
require 'rake/rdoctask'
|
89
|
+
Rake::RDocTask.new do |rdoc|
|
90
|
+
if File.exist?('VERSION')
|
91
|
+
version = File.read('VERSION')
|
92
|
+
else
|
93
|
+
version = ""
|
94
|
+
end
|
95
|
+
|
96
|
+
rdoc.rdoc_dir = 'rdoc'
|
97
|
+
rdoc.title = "vimeo #{version}"
|
98
|
+
rdoc.rdoc_files.include('README*')
|
99
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
100
|
+
end
|
data/VERSION.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Album < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Adds a video to an album.
|
6
|
+
create_api_method :add_video,
|
7
|
+
"vimeo.albums.addVideo",
|
8
|
+
:required => [:album_id, :video_id]
|
9
|
+
|
10
|
+
# Creates an album.
|
11
|
+
create_api_method :create,
|
12
|
+
"vimeo.albums.create",
|
13
|
+
:required => [:title, :video_id],
|
14
|
+
:optional => [:description, :videos]
|
15
|
+
|
16
|
+
# Deletes an album.
|
17
|
+
create_api_method :delete,
|
18
|
+
"vimeo.albums.delete",
|
19
|
+
:required => [:album_id]
|
20
|
+
|
21
|
+
# Returns a list of a user's albums.
|
22
|
+
create_api_method :get_all,
|
23
|
+
"vimeo.albums.getAll",
|
24
|
+
:required => [:user_id],
|
25
|
+
:optional => [:page, :per_page, :sort]
|
26
|
+
|
27
|
+
# Returns a list of the videos in an album.
|
28
|
+
create_api_method :get_videos,
|
29
|
+
"vimeo.albums.getVideos",
|
30
|
+
:required => [:album_id],
|
31
|
+
:optional => [:page, :per_page, :full_response, :password]
|
32
|
+
|
33
|
+
# Removes a video from an album.
|
34
|
+
create_api_method :remove_video,
|
35
|
+
"vimeo.albums.removeVideo",
|
36
|
+
:required => [:album_id, :video_id]
|
37
|
+
|
38
|
+
# Sets the description of an album.
|
39
|
+
create_api_method :set_description,
|
40
|
+
"vimeo.albums.setDescription",
|
41
|
+
:required => [:album_id, :description]
|
42
|
+
|
43
|
+
# Sets the password of an album.
|
44
|
+
create_api_method :set_password,
|
45
|
+
"vimeo.albums.setPassword",
|
46
|
+
:required => [:album_id, :password]
|
47
|
+
|
48
|
+
# Sets the title of an album.
|
49
|
+
create_api_method :set_title,
|
50
|
+
"vimeo.albums.setTitle",
|
51
|
+
:required => [:album_id, :title]
|
52
|
+
|
53
|
+
end # Album
|
54
|
+
end # Advanced
|
55
|
+
end # Vimeo
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
|
3
|
+
module CreateApiMethod
|
4
|
+
|
5
|
+
# Creates a method that calls a Vimeo Method through the Advanced API.
|
6
|
+
#
|
7
|
+
# @param [String] method The name of the method being created.
|
8
|
+
# @param [String] vimeo_method The name of the advanced API Method the function should call.
|
9
|
+
# @param [Hash] options Some optional parameters.
|
10
|
+
# @option options [Array] :required An array of required parameters.
|
11
|
+
# @option options [Array] :optional An array of optional parameters.
|
12
|
+
def create_api_method(method, vimeo_method, options={})
|
13
|
+
options = { :required => [], :optional => [] }.merge(options)
|
14
|
+
|
15
|
+
method = method.to_s
|
16
|
+
camelized_method = camelize(method, false)
|
17
|
+
|
18
|
+
raise ArgumentError, 'Required parameters must be an array.' unless options[:required].is_a? Array
|
19
|
+
raise ArgumentError, 'Optional parameters must be an array.' unless options[:optional].is_a? Array
|
20
|
+
|
21
|
+
required = options[:required].map { |r| r.to_s }.join(",")
|
22
|
+
optional = options[:optional].map { |o| ":#{o} => nil" }.join(",")
|
23
|
+
authorized = options.fetch(:authorized, true)
|
24
|
+
|
25
|
+
parameters = "(#{required unless required.empty?}#{',' unless required.empty?}options={#{optional}})"
|
26
|
+
|
27
|
+
method_string = <<-method
|
28
|
+
|
29
|
+
def #{method}#{parameters}
|
30
|
+
raise ArgumentError, 'Options must be a hash.' unless options.is_a? Hash
|
31
|
+
|
32
|
+
sig_options = {
|
33
|
+
:method => "#{vimeo_method}",
|
34
|
+
:format => "json"
|
35
|
+
}
|
36
|
+
|
37
|
+
#{ options[:required].map { |r| "sig_options.merge! :#{r} => #{r}"}.join("\n") }
|
38
|
+
#{ options[:optional].map { |o| "sig_options.merge! :#{o} => options[:#{o}] unless options[:#{o}].nil?" }.join("\n") }
|
39
|
+
|
40
|
+
make_request sig_options, #{authorized ? "true" : "false"}
|
41
|
+
end
|
42
|
+
|
43
|
+
alias #{camelized_method} #{method}
|
44
|
+
|
45
|
+
method
|
46
|
+
|
47
|
+
class_eval method_string
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
# taken from ActiveSupport-2.3.4, activesupport/lib/active_support/inflector.rb, line 178
|
53
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
54
|
+
if first_letter_in_uppercase
|
55
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
56
|
+
else
|
57
|
+
lower_case_and_underscored_word[0..0].downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module Vimeo
|
63
|
+
module Advanced
|
64
|
+
|
65
|
+
class RequestFailed < StandardError; end
|
66
|
+
|
67
|
+
class Base
|
68
|
+
extend CreateApiMethod
|
69
|
+
|
70
|
+
ENDPOINT = "http://vimeo.com/api/rest/v2"
|
71
|
+
|
72
|
+
def initialize(consumer_key, consumer_secret, options = {})
|
73
|
+
@oauth_consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://vimeo.com', :http_method => :get, :scheme => :header)
|
74
|
+
unless options[:token].nil? && options[:secret].nil?
|
75
|
+
@access_token = OAuth::AccessToken.new(@oauth_consumer, options[:token], options[:secret])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def authorize_url(permission = "delete")
|
80
|
+
get_request_token.authorize_url :permission => permission
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_request_token
|
84
|
+
@request_token ||= @oauth_consumer.get_request_token :scheme => :header
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_access_token(oauth_token=nil, oauth_secret=nil, oauth_verifier=nil)
|
88
|
+
@access_token ||= OAuth::RequestToken.new(@oauth_consumer, oauth_token, oauth_secret).get_access_token :oauth_verifier => oauth_verifier
|
89
|
+
end
|
90
|
+
|
91
|
+
# TODO: Move this to OAuth
|
92
|
+
create_api_method :check_access_token,
|
93
|
+
"vimeo.oauth.checkAccessToken"
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def make_request(options, authorized)
|
98
|
+
if authorized
|
99
|
+
raw_response = @oauth_consumer.request(:post, Vimeo::Advanced::Base::ENDPOINT, get_access_token, {}, options).body
|
100
|
+
else
|
101
|
+
raw_response = @oauth_consumer.request(:post, Vimeo::Advanced::Base::ENDPOINT, nil, {}, options).body
|
102
|
+
end
|
103
|
+
|
104
|
+
response = MultiJson.decode(raw_response)
|
105
|
+
validate_response! response
|
106
|
+
response
|
107
|
+
end
|
108
|
+
|
109
|
+
# Raises an exception if the response does contain a +stat+ different from "ok"
|
110
|
+
def validate_response!(response)
|
111
|
+
raise "empty response" unless response
|
112
|
+
|
113
|
+
status = response["stat"]
|
114
|
+
if status and status != "ok"
|
115
|
+
error = response["err"]
|
116
|
+
if error
|
117
|
+
raise RequestFailed, "#{error["code"]}: #{error["msg"]}, explanation: #{error["expl"]}"
|
118
|
+
else
|
119
|
+
raise RequestFailed, "Error: #{status}, no error message"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end # Base
|
125
|
+
end # Advanced
|
126
|
+
end # Vimeo
|