youtube 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/dirtywork.rb +1 -4
- data/youtube.rb +65 -16
- metadata +1 -1
data/dirtywork.rb
CHANGED
@@ -39,7 +39,6 @@ module DirtyWork
|
|
39
39
|
# the remote method API name based on the ruby method name.
|
40
40
|
private
|
41
41
|
def method_missing(method_id, *params)
|
42
|
-
# params[0] is the argument to the YouTube API
|
43
42
|
request(method_id.to_s.sub('_', '.'), *params)
|
44
43
|
end
|
45
44
|
|
@@ -53,9 +52,7 @@ module DirtyWork
|
|
53
52
|
private
|
54
53
|
def request_url(method, *params)
|
55
54
|
param_list = String.new
|
56
|
-
params[0].each_pair
|
57
|
-
param_list << "&"+k.to_s+"="+v.to_s
|
58
|
-
end
|
55
|
+
params[0].each_pair { |k,v| param_list << "&"+k.to_s+"="+v.to_s } if !params.empty?
|
59
56
|
url = "#{HOST}#{API}?method=youtube."+method+"&dev_id="+@dev_id+param_list
|
60
57
|
end
|
61
58
|
|
data/youtube.rb
CHANGED
@@ -21,22 +21,10 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
# USAGE:
|
25
|
-
# require 'youtube'
|
26
|
-
# youtube = YouTube.new 'your dev id'
|
27
|
-
# profile = youtube.profile 'username'
|
28
|
-
# profile.age
|
29
|
-
# ...
|
30
|
-
# videos = youtube.videos_by_tag('malsky')
|
31
|
-
# video = video[0]
|
32
|
-
# video.title
|
33
|
-
# ...
|
34
|
-
# details = video.details
|
35
|
-
# details.channel_list
|
36
|
-
|
37
24
|
require 'dirtywork'
|
38
25
|
|
39
|
-
# YouTube client class. Requires a
|
26
|
+
# YouTube client class. Requires a Developer ID.
|
27
|
+
# Get one here: <http://youtube.com/my_profile_dev>.
|
40
28
|
|
41
29
|
class YouTube
|
42
30
|
include DirtyWork
|
@@ -51,18 +39,79 @@ class YouTube
|
|
51
39
|
Profile.new response['user_profile']
|
52
40
|
end
|
53
41
|
|
42
|
+
# username = the user to get favorite videos for
|
43
|
+
def favorite_videos(username)
|
44
|
+
videos = Array.new
|
45
|
+
response = users_list_favorite_videos(:user => username)
|
46
|
+
if !response['video_list'].empty?
|
47
|
+
response['video_list']['video'].each do |video|
|
48
|
+
videos << Video.new(video, @dev_id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
videos
|
52
|
+
end
|
53
|
+
|
54
|
+
#username = the user to get list of friends from
|
55
|
+
def friends(username)
|
56
|
+
friends = Array.new
|
57
|
+
response = users_list_friends(:user => username)
|
58
|
+
if !response['friend_list'].empty?
|
59
|
+
response['friend_list'].each do |friend|
|
60
|
+
friends << Friend.new(friend[1])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
friends
|
64
|
+
end
|
65
|
+
|
54
66
|
# tag = the tag to search for, must be one word
|
55
67
|
# optional: page = the "page" of results to retrieve (e.g. 1, 2, 3)
|
56
68
|
# optional: per_page = the number of results per page (default: 20, max 100)
|
57
69
|
def videos_by_tag(tag, page=1, per_page=20)
|
58
70
|
videos = Array.new
|
59
71
|
response = videos_list_by_tag(:tag => tag, :page => page, :per_page => per_page)
|
60
|
-
response['video_list']
|
61
|
-
|
72
|
+
if !response['video_list'].empty?
|
73
|
+
response['video_list']['video'].each do |video|
|
74
|
+
videos << Video.new(video, @dev_id)
|
75
|
+
end
|
62
76
|
end
|
63
77
|
videos
|
64
78
|
end
|
65
79
|
|
80
|
+
# username = the user to get videos for
|
81
|
+
def videos_by_user(username)
|
82
|
+
videos = Array.new
|
83
|
+
response = videos_list_by_user(:user => username)
|
84
|
+
if !response['video_list'].empty?
|
85
|
+
response['video_list']['video'].each do |video|
|
86
|
+
videos << Video.new(video, @dev_id)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
videos
|
90
|
+
end
|
91
|
+
|
92
|
+
# this method takes no arguments
|
93
|
+
def featured_videos
|
94
|
+
videos = Array.new
|
95
|
+
response = videos_list_featured
|
96
|
+
if !response['video_list'].empty?
|
97
|
+
response['video_list']['video'].each do |video|
|
98
|
+
videos << Video.new(video, @dev_id)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
videos
|
102
|
+
end
|
103
|
+
|
104
|
+
class Friend
|
105
|
+
attr_reader :user, :video_upload_count, :favorite_count, :friend_count
|
106
|
+
|
107
|
+
def initialize(friend)
|
108
|
+
@user = friend['user']
|
109
|
+
@video_upload_count = friend['video_upload_count']
|
110
|
+
@favorite_count = friend['favorite_count']
|
111
|
+
@friend_count = friend['friend_count']
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
66
115
|
class Profile
|
67
116
|
attr_reader :first_name, :last_name, :about_me, :age, :video_upload_count,
|
68
117
|
:video_watch_count, :homepage, :hometown, :gender, :occupations,
|
metadata
CHANGED