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
@@ -0,0 +1,55 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Channel < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Adds a video to a channel.
|
6
|
+
create_api_method :add_video,
|
7
|
+
"vimeo.channels.addVideo",
|
8
|
+
:required => [:channel_id, :video_id]
|
9
|
+
|
10
|
+
# Returns a list of all channels.
|
11
|
+
create_api_method :get_all,
|
12
|
+
"vimeo.channels.getAll",
|
13
|
+
:optional => [:page, :per_page, :sort, :user_id]
|
14
|
+
|
15
|
+
# Returns information about a channel.
|
16
|
+
create_api_method :get_info,
|
17
|
+
"vimeo.channels.getInfo",
|
18
|
+
:required => [:channel_id]
|
19
|
+
|
20
|
+
# Returns a list of the moderators of a channel.
|
21
|
+
create_api_method :get_moderators,
|
22
|
+
"vimeo.channels.getModerators",
|
23
|
+
:required => [:channel_id],
|
24
|
+
:optional => [:page, :per_page]
|
25
|
+
|
26
|
+
# Returns a list of the subscribers of a channel.
|
27
|
+
create_api_method :get_subscribers,
|
28
|
+
"vimeo.channels.getSubscribers",
|
29
|
+
:required => [:channel_id],
|
30
|
+
:optional => [:page, :per_page]
|
31
|
+
|
32
|
+
# Returns a list of the videos in a channel.
|
33
|
+
create_api_method :get_videos,
|
34
|
+
"vimeo.channels.getVideos",
|
35
|
+
:required => [:channel_id],
|
36
|
+
:optional => [:page, :per_page, :full_response]
|
37
|
+
|
38
|
+
# Removes a video from a channel.
|
39
|
+
create_api_method :remove_video,
|
40
|
+
"vimeo.channels.removeVideo",
|
41
|
+
:required => [:channel_id, :video_id]
|
42
|
+
|
43
|
+
# Subscribes to a channel
|
44
|
+
create_api_method :subscribe,
|
45
|
+
"vimeo.channels.subscribe",
|
46
|
+
:required => [:channel_id]
|
47
|
+
|
48
|
+
# Unsubscribes from a channel
|
49
|
+
create_api_method :unsubscribe,
|
50
|
+
"vimeo.channels.unsubscribe",
|
51
|
+
:required => [:channel_id]
|
52
|
+
|
53
|
+
end # Channel
|
54
|
+
end # Advanced
|
55
|
+
end # Vimeo
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Contact < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Returns a list of a user's contacts.
|
6
|
+
create_api_method :get_all,
|
7
|
+
"vimeo.contacts.getAll",
|
8
|
+
:required => [:user_id],
|
9
|
+
:optional => [:page, :per_page, :sort]
|
10
|
+
|
11
|
+
# Returns a list of your mutual contacts with a user.
|
12
|
+
create_api_method :get_mutual,
|
13
|
+
"vimeo.contacts.getMutual",
|
14
|
+
:required => [:user_id],
|
15
|
+
:optional => [:page, :per_page]
|
16
|
+
|
17
|
+
# Returns a list of your contacts who are online.
|
18
|
+
create_api_method :get_online,
|
19
|
+
"vimeo.contacts.getOnline",
|
20
|
+
:optional => [:page, :per_page]
|
21
|
+
|
22
|
+
# Returns a list of users who added a user as a contact.
|
23
|
+
create_api_method :get_who_added,
|
24
|
+
"vimeo.contacts.getWhoAdded",
|
25
|
+
:required => [:user_id],
|
26
|
+
:optional => [:page, :per_page, :sort]
|
27
|
+
|
28
|
+
end # Contact
|
29
|
+
end # Advanced
|
30
|
+
end # Vimeo
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Group < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Adds a video to a group.
|
6
|
+
create_api_method :add_video,
|
7
|
+
"vimeo.groups.addVideo",
|
8
|
+
:required => [:group_id, :video_id]
|
9
|
+
|
10
|
+
# Returns a list of all groups.
|
11
|
+
create_api_method :get_all,
|
12
|
+
"vimeo.groups.getAll",
|
13
|
+
:optional => [:page, :per_page, :sort, :user_id]
|
14
|
+
|
15
|
+
# Returns a list of a group's files.
|
16
|
+
create_api_method :get_files,
|
17
|
+
"vimeo.groups.getFiles",
|
18
|
+
:required => [:group_id],
|
19
|
+
:optional => [:page, :per_page]
|
20
|
+
|
21
|
+
# Returns information about a group.
|
22
|
+
create_api_method :get_info,
|
23
|
+
"vimeo.groups.getInfo",
|
24
|
+
:required => [:group_id]
|
25
|
+
|
26
|
+
# Returns a list of the members in a group.
|
27
|
+
create_api_method :get_members,
|
28
|
+
"vimeo.groups.getMembers",
|
29
|
+
:required => [:group_id],
|
30
|
+
:optional => [:page, :per_page, :sort]
|
31
|
+
|
32
|
+
# Returns a list of the moderators of a group.
|
33
|
+
create_api_method :get_moderators,
|
34
|
+
"vimeo.groups.getModerators",
|
35
|
+
:required => [:group_id],
|
36
|
+
:optional => [:page, :per_page]
|
37
|
+
|
38
|
+
# Returns a list of the comments on a video in a group.
|
39
|
+
create_api_method :get_video_comments,
|
40
|
+
"vimeo.groups.getVideoComments",
|
41
|
+
:required => [:group_id, :video_id],
|
42
|
+
:optional => [:page, :per_page]
|
43
|
+
|
44
|
+
# Returns a list of the videos in a group.
|
45
|
+
create_api_method :get_videos,
|
46
|
+
"vimeo.groups.getVideos",
|
47
|
+
:required => [:group_id],
|
48
|
+
:optional => [:page, :per_page, :sort, :full_response]
|
49
|
+
|
50
|
+
# Joins a group.
|
51
|
+
create_api_method :join,
|
52
|
+
"vimeo.groups.join",
|
53
|
+
:required => [:group_id]
|
54
|
+
|
55
|
+
# Leaves a group.
|
56
|
+
create_api_method :leave,
|
57
|
+
"vimeo.groups.leave",
|
58
|
+
:required => [:group_id]
|
59
|
+
|
60
|
+
end # Group
|
61
|
+
end # Advanced
|
62
|
+
end # Vimeo
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class GroupEvents < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Returns a list of events from a group for a specific month.
|
6
|
+
create_api_method :get_month,
|
7
|
+
"vimeo.groups.events.getMonth",
|
8
|
+
:required => [:group_id],
|
9
|
+
:optional => [:page, :per_page, :month, :year]
|
10
|
+
|
11
|
+
# Returns a list of all past events from a group.
|
12
|
+
create_api_method :get_past,
|
13
|
+
"vimeo.groups.events.getPast",
|
14
|
+
:required => [:group_id],
|
15
|
+
:optional => [:page, :per_page]
|
16
|
+
|
17
|
+
# Returns a list of all upcoming events from a group.
|
18
|
+
create_api_method :get_upcoming,
|
19
|
+
"vimeo.groups.events.getUpcoming",
|
20
|
+
:required => [:group_id],
|
21
|
+
:optional => [:page, :per_page]
|
22
|
+
|
23
|
+
end # GroupEvents
|
24
|
+
end # Advanced
|
25
|
+
end # Vimeo
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class GroupForums < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Returns a list of comments for a group forum topic.
|
6
|
+
create_api_method :get_topic_comments,
|
7
|
+
"vimeo.groups.forums.getTopicComments",
|
8
|
+
:required => [:group_id, :topic_id],
|
9
|
+
:optional => [:page, :per_page]
|
10
|
+
|
11
|
+
# Returns a list of all group forum topics.
|
12
|
+
create_api_method :get_topics,
|
13
|
+
"vimeo.groups.forums.getTopics",
|
14
|
+
:required => [:group_id],
|
15
|
+
:optional => [:page, :per_page]
|
16
|
+
|
17
|
+
end # GroupForums
|
18
|
+
end # Advanced
|
19
|
+
end # Vimeo
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Person < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Adds a user to your contact list.
|
6
|
+
create_api_method :add_contact,
|
7
|
+
"vimeo.people.addContact",
|
8
|
+
:required => [:user_id]
|
9
|
+
|
10
|
+
# Adds a subscription to your subscriptions.
|
11
|
+
# Types is a comma-delimited string. Valid options: "likes", "appears", "uploads"
|
12
|
+
create_api_method :add_subscription,
|
13
|
+
"vimeo.people.addSubscription",
|
14
|
+
:required => [:user_id, :types]
|
15
|
+
|
16
|
+
# Finds a user by their e-mail.
|
17
|
+
create_api_method :find_by_email,
|
18
|
+
"vimeo.people.findByEmail",
|
19
|
+
:required => [:user_id]
|
20
|
+
|
21
|
+
create_api_method :get_hd_embeds,
|
22
|
+
"vimeo.people.getHDEmbeds"
|
23
|
+
|
24
|
+
# Returns a user's information
|
25
|
+
create_api_method :get_info,
|
26
|
+
"vimeo.people.getInfo",
|
27
|
+
:required => [:user_id]
|
28
|
+
|
29
|
+
# Returns a user's portrait URLs.
|
30
|
+
create_api_method :get_portrait_urls,
|
31
|
+
"vimeo.people.getPortraitUrls",
|
32
|
+
:required => [:user_id]
|
33
|
+
|
34
|
+
# Removes a user from your contact list.
|
35
|
+
create_api_method :remove_contact,
|
36
|
+
"vimeo.people.removeContact",
|
37
|
+
:required => [:user_id]
|
38
|
+
|
39
|
+
# Removes a subscription to your subscriptions.
|
40
|
+
# Types is a comma-delimited string. Valid options: "likes", "appears", "uploads"
|
41
|
+
create_api_method :remove_subscription,
|
42
|
+
"vimeo.people.removeSubscription",
|
43
|
+
:required => [:user_id, :types]
|
44
|
+
|
45
|
+
end # Person
|
46
|
+
end # Advanced
|
47
|
+
end # Vimeo
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
module SimpleUpload
|
4
|
+
class Chunk
|
5
|
+
MULTIPART_BOUNDARY = "-----------RubyMultipartPost"
|
6
|
+
|
7
|
+
attr_reader :id, :index
|
8
|
+
attr_reader :task, :vimeo
|
9
|
+
attr_reader :data, :size
|
10
|
+
|
11
|
+
def initialize(task, data)
|
12
|
+
@task = task
|
13
|
+
@vimeo = task.vimeo
|
14
|
+
@data = data
|
15
|
+
@size = data.size
|
16
|
+
@index = task.chunks.count
|
17
|
+
end
|
18
|
+
|
19
|
+
# Performs the upload via Multipart.
|
20
|
+
def upload
|
21
|
+
endpoint = "#{task.endpoint}&chunk_id=#{index}"
|
22
|
+
|
23
|
+
response = task.oauth_consumer.request(:post, endpoint, vimeo.get_access_token, {}, {}) do |req|
|
24
|
+
req.set_content_type("multipart/form-data", { "boundary" => MULTIPART_BOUNDARY })
|
25
|
+
|
26
|
+
io = StringIO.new(data)
|
27
|
+
io.instance_variable_set :"@original_filename", task.filename
|
28
|
+
def io.original_filename; @original_filename; end
|
29
|
+
def io.content_type; "application/octet-stream"; end
|
30
|
+
|
31
|
+
parts = []
|
32
|
+
parts << Parts::FilePart.new(MULTIPART_BOUNDARY, "file_data", io)
|
33
|
+
parts << Parts::EpiloguePart.new(MULTIPART_BOUNDARY)
|
34
|
+
|
35
|
+
ios = parts.map{|p| p.to_io }
|
36
|
+
req.content_length = parts.inject(0) {|sum,i| sum + i.length }
|
37
|
+
req.body_stream = CompositeReadIO.new(*ios)
|
38
|
+
|
39
|
+
:continue
|
40
|
+
end
|
41
|
+
|
42
|
+
# free memory (for big file uploads)
|
43
|
+
@data = nil
|
44
|
+
|
45
|
+
@id = response.body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
module SimpleUpload
|
4
|
+
class Task
|
5
|
+
CHUNK_SIZE = 2 * 1024 * 1024 # 2 megabytes
|
6
|
+
|
7
|
+
attr_reader :vimeo, :oauth_consumer
|
8
|
+
attr_reader :io, :size, :filename
|
9
|
+
attr_reader :chunks, :endpoint
|
10
|
+
attr_reader :id, :video_id
|
11
|
+
|
12
|
+
def initialize(vimeo, oauth_consumer, io, size, filename)
|
13
|
+
@vimeo, @oauth_consumer = vimeo, oauth_consumer
|
14
|
+
@io, @size, @filename = io, size, filename
|
15
|
+
@chunks = []
|
16
|
+
end
|
17
|
+
|
18
|
+
# Uploads the file to Vimeo and returns the +video_id+ on success.
|
19
|
+
def execute
|
20
|
+
check_quota
|
21
|
+
authorize
|
22
|
+
upload
|
23
|
+
raise UploadError.new, "Validation of chunks failed." unless valid?
|
24
|
+
complete
|
25
|
+
|
26
|
+
return video_id
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# Checks whether the file can be uploaded.
|
32
|
+
def check_quota
|
33
|
+
quota = vimeo.get_quota
|
34
|
+
free = quota["user"]["upload_space"]["free"].to_i
|
35
|
+
|
36
|
+
raise UploadError.new, "file size exceeds quota. required: #{size}, free: #{free}" if size > free
|
37
|
+
end
|
38
|
+
|
39
|
+
# Gets a +ticket_id+ for the upload.
|
40
|
+
def authorize
|
41
|
+
ticket = vimeo.get_ticket
|
42
|
+
|
43
|
+
@id = ticket["ticket"]["id"]
|
44
|
+
@endpoint = ticket["ticket"]["endpoint"]
|
45
|
+
max_file_size = ticket["ticket"]["max_file_size"].to_i
|
46
|
+
|
47
|
+
raise UploadError.new, "file was too big: #{size}, maximum: #{max_file_size}" if size > max_file_size
|
48
|
+
end
|
49
|
+
|
50
|
+
# Performs the upload.
|
51
|
+
def upload
|
52
|
+
while (chunk_data = io.read(CHUNK_SIZE)) do
|
53
|
+
chunk = Chunk.new(self, chunk_data)
|
54
|
+
chunk.upload
|
55
|
+
chunks << chunk
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Tells vimeo that the upload is complete.
|
60
|
+
def complete
|
61
|
+
@video_id = vimeo.complete(id, filename)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Compares Vimeo's chunk list with own chunk list. Returns +true+ if identical.
|
65
|
+
def valid?
|
66
|
+
received, sent = received_chunk_sizes, sent_chunk_sizes
|
67
|
+
sent.all? { |id, size| received[id] == size }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns a hash of the sent chunks and their respective sizes.
|
71
|
+
def sent_chunk_sizes
|
72
|
+
Hash[chunks.map { |chunk| [chunk.id, chunk.size] }]
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a of Vimeo's received chunks and their respective sizes.
|
76
|
+
def received_chunk_sizes
|
77
|
+
verification = vimeo.verify_chunks(id)
|
78
|
+
chunk_list = verification["ticket"]["chunks"]["chunk"]
|
79
|
+
chunk_list = [chunk_list] unless chunk_list.is_a?(Array)
|
80
|
+
Hash[chunk_list.map { |chunk| [chunk["id"], chunk["size"].to_i] }]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
module SimpleUpload
|
4
|
+
class UploadError < RuntimeError; end
|
5
|
+
|
6
|
+
autoload :Task, 'vimeo/advanced/simple_upload/task'
|
7
|
+
autoload :Chunk, 'vimeo/advanced/simple_upload/chunk'
|
8
|
+
|
9
|
+
# Uploads data (IO streams or files) to Vimeo.
|
10
|
+
def upload(uploadable)
|
11
|
+
case uploadable
|
12
|
+
when File
|
13
|
+
upload_file(uploadable)
|
14
|
+
when String
|
15
|
+
upload_file(File.new(uploadable))
|
16
|
+
else
|
17
|
+
upload_io(uploadable)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
# Uploads an IO to Vimeo.
|
24
|
+
def upload_io(io, size, filename = 'io.data')
|
25
|
+
raise "#{io.inspect} must respond to #read" unless io.respond_to?(:read)
|
26
|
+
task = Task.new(self, @oauth_consumer, io, size, filename)
|
27
|
+
task.execute
|
28
|
+
task.video_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# Helper for uploading files to Vimeo.
|
32
|
+
def upload_file(file)
|
33
|
+
file_path = file.path
|
34
|
+
|
35
|
+
size = File.size(file_path)
|
36
|
+
basename = File.basename(file_path)
|
37
|
+
io = File.open(file_path)
|
38
|
+
io.binmode
|
39
|
+
|
40
|
+
upload_io(io, size, basename).tap do
|
41
|
+
io.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Test < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# http://vimeo.com/api/docs/methods/vimeo.test.echo
|
6
|
+
create_api_method :echo,
|
7
|
+
"vimeo.test.echo"
|
8
|
+
|
9
|
+
# http://vimeo.com/api/docs/methods/vimeo.test.login
|
10
|
+
create_api_method :login,
|
11
|
+
"vimeo.test.login"
|
12
|
+
|
13
|
+
# http://vimeo.com/api/docs/methods/vimeo.test.null
|
14
|
+
create_api_method :null,
|
15
|
+
"vimeo.test.null"
|
16
|
+
|
17
|
+
end # Test
|
18
|
+
end # Advanced
|
19
|
+
end # Vimeo
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Vimeo
|
4
|
+
module Advanced
|
5
|
+
|
6
|
+
class Upload < Vimeo::Advanced::Base
|
7
|
+
# Check to make sure an upload ticket is still valid.
|
8
|
+
create_api_method :check_ticket,
|
9
|
+
"vimeo.videos.upload.checkTicket",
|
10
|
+
:required => [:ticket_id]
|
11
|
+
|
12
|
+
# Complete the upload process.
|
13
|
+
create_api_method :complete,
|
14
|
+
"vimeo.videos.upload.complete",
|
15
|
+
:required => [:ticket_id, :filename]
|
16
|
+
|
17
|
+
# Returns an upload ticket.
|
18
|
+
create_api_method :get_ticket,
|
19
|
+
"vimeo.videos.upload.getTicket",
|
20
|
+
:optional => [:video_id]
|
21
|
+
|
22
|
+
# Returns the space and HD uploads left for a user.
|
23
|
+
create_api_method :get_quota,
|
24
|
+
"vimeo.videos.upload.getQuota"
|
25
|
+
|
26
|
+
# Verify that the chunks were uploaded properly.
|
27
|
+
create_api_method :verify_chunks,
|
28
|
+
"vimeo.videos.upload.verifyChunks",
|
29
|
+
:required => [:ticket_id]
|
30
|
+
|
31
|
+
include Vimeo::Advanced::SimpleUpload
|
32
|
+
|
33
|
+
end # Upload
|
34
|
+
end # Advanced
|
35
|
+
end # Vimeo
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class Video < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
create_api_method :add_cast,
|
6
|
+
"vimeo.videos.addCast",
|
7
|
+
:required => [:video_id, :user_id],
|
8
|
+
:optional => [:role]
|
9
|
+
|
10
|
+
create_api_method :add_photos,
|
11
|
+
"vimeo.videos.addPhotos",
|
12
|
+
:required => [:video_id, :photo_urls]
|
13
|
+
|
14
|
+
create_api_method :add_tags,
|
15
|
+
"vimeo.videos.addTags",
|
16
|
+
:required => [:video_id, :tags]
|
17
|
+
|
18
|
+
create_api_method :clear_tags,
|
19
|
+
"vimeo.videos.clearTags",
|
20
|
+
:required => [:video_id]
|
21
|
+
|
22
|
+
create_api_method :delete,
|
23
|
+
"vimeo.videos.delete",
|
24
|
+
:required => [:video_id]
|
25
|
+
|
26
|
+
create_api_method :get_all,
|
27
|
+
"vimeo.videos.getAll",
|
28
|
+
:required => [:user_id],
|
29
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
30
|
+
|
31
|
+
create_api_method :get_appears_in,
|
32
|
+
"vimeo.videos.getAppearsIn",
|
33
|
+
:required => [:user_id],
|
34
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
35
|
+
|
36
|
+
create_api_method :get_by_tag,
|
37
|
+
"vimeo.videos.getByTag",
|
38
|
+
:required => [:tag],
|
39
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
40
|
+
|
41
|
+
create_api_method :get_cast,
|
42
|
+
"vimeo.videos.getCast",
|
43
|
+
:required => [:video_id],
|
44
|
+
:optional => [:page, :per_page]
|
45
|
+
|
46
|
+
create_api_method :get_contacts_liked,
|
47
|
+
"vimeo.videos.getContactsLiked",
|
48
|
+
:required => [:user_id],
|
49
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
50
|
+
|
51
|
+
create_api_method :get_contacts_uploaded,
|
52
|
+
"vimeo.videos.getContactsUploaded",
|
53
|
+
:required => [:user_id],
|
54
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
55
|
+
|
56
|
+
create_api_method :get_info,
|
57
|
+
"vimeo.videos.getInfo",
|
58
|
+
:required => [:video_id]
|
59
|
+
|
60
|
+
create_api_method :get_likes,
|
61
|
+
"vimeo.videos.getLikes",
|
62
|
+
:required => [:user_id],
|
63
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
64
|
+
|
65
|
+
create_api_method :get_subscriptions,
|
66
|
+
"vimeo.videos.getSubscriptions",
|
67
|
+
:required => [:user_id],
|
68
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
69
|
+
|
70
|
+
create_api_method :get_thumbnail_urls,
|
71
|
+
"vimeo.videos.getThumbnailUrls",
|
72
|
+
:required => [:video_id]
|
73
|
+
|
74
|
+
create_api_method :get_uploaded,
|
75
|
+
"vimeo.videos.getUploaded",
|
76
|
+
:required => [:user_id],
|
77
|
+
:optional => [:page, :per_page, :full_response, :sort]
|
78
|
+
|
79
|
+
create_api_method :remove_cast,
|
80
|
+
"vimeo.videos.removeCast",
|
81
|
+
:required => [:video_id, :user_id]
|
82
|
+
|
83
|
+
create_api_method :remove_tag,
|
84
|
+
"vimeo.videos.removeTag",
|
85
|
+
:required => [:video_id, :tag_id]
|
86
|
+
|
87
|
+
create_api_method :search,
|
88
|
+
"vimeo.videos.search",
|
89
|
+
:required => [:query],
|
90
|
+
:optional => [:page, :per_page, :full_response, :sort, :user_id],
|
91
|
+
:authorized => false
|
92
|
+
|
93
|
+
create_api_method :set_description,
|
94
|
+
"vimeo.videos.setDescription",
|
95
|
+
:required => [:video_id, :description]
|
96
|
+
|
97
|
+
create_api_method :set_like,
|
98
|
+
"vimeo.videos.setLike",
|
99
|
+
:required => [:video_id, :like]
|
100
|
+
|
101
|
+
create_api_method :set_privacy,
|
102
|
+
"vimeo.videos.setPrivacy",
|
103
|
+
:required => [:video_id, :privacy],
|
104
|
+
:optional => [:users, :password]
|
105
|
+
|
106
|
+
create_api_method :set_title,
|
107
|
+
"vimeo.videos.setTitle",
|
108
|
+
:required => [:video_id, :title]
|
109
|
+
|
110
|
+
# comments
|
111
|
+
create_api_method :add_comment,
|
112
|
+
"vimeo.videos.comments.addComment",
|
113
|
+
:required => [:video_id, :comment_text],
|
114
|
+
:optional => [:reply_to_comment_id]
|
115
|
+
|
116
|
+
create_api_method :delete_comment,
|
117
|
+
"vimeo.videos.comments.deleteComment",
|
118
|
+
:required => [:video_id, :comment_id]
|
119
|
+
|
120
|
+
create_api_method :edit_comment,
|
121
|
+
"vimeo.videos.comments.editComment",
|
122
|
+
:required => [:video_id, :comment_id, :comment_text]
|
123
|
+
|
124
|
+
create_api_method :get_comments_list,
|
125
|
+
"vimeo.videos.comments.getList",
|
126
|
+
:required => [:video_id],
|
127
|
+
:optional => [:page, :per_page]
|
128
|
+
|
129
|
+
# embed
|
130
|
+
# getPresets has a bug right now: the response is blank http://www.vimeo.com/forums/topic:32411
|
131
|
+
# create_api_method :get_presets,
|
132
|
+
# "vimeo.videos.embed.getPresets",
|
133
|
+
# :optional => [:page, :per_page]
|
134
|
+
|
135
|
+
create_api_method :set_preset,
|
136
|
+
"vimeo.videos.embed.setPreset",
|
137
|
+
:required => [:preset_id, :video_id]
|
138
|
+
|
139
|
+
end # Video
|
140
|
+
end # Advanced
|
141
|
+
end # Vimeo
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Vimeo
|
2
|
+
module Advanced
|
3
|
+
class VideoEmbed < Vimeo::Advanced::Base
|
4
|
+
|
5
|
+
# Returns a list of presets for a video embed.
|
6
|
+
create_api_method :get_presets,
|
7
|
+
"vimeo.videos.embed.getPresets",
|
8
|
+
:optional => [:page, :per_page]
|
9
|
+
|
10
|
+
# Sets a preset for a video embed.
|
11
|
+
create_api_method :set_preset,
|
12
|
+
"vimeo.videos.embed.setPreset",
|
13
|
+
:required => [:video_id, :preset_id]
|
14
|
+
|
15
|
+
end # VideoEmbed
|
16
|
+
end # Advanced
|
17
|
+
end # Vimeo
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'advanced/base'
|
3
|
+
require 'advanced/album'
|
4
|
+
require 'advanced/channel'
|
5
|
+
require 'advanced/contact'
|
6
|
+
require 'advanced/group'
|
7
|
+
require 'advanced/group_events'
|
8
|
+
require 'advanced/group_forums'
|
9
|
+
require 'advanced/person'
|
10
|
+
require 'advanced/simple_upload'
|
11
|
+
require 'advanced/test'
|
12
|
+
require 'advanced/upload'
|
13
|
+
require 'advanced/video'
|
14
|
+
require 'advanced/video_embed'
|
15
|
+
|
16
|
+
module Vimeo
|
17
|
+
module Advanced
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|