natedaiger-youtube-g 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +3 -0
- data/Rakefile +18 -17
- data/lib/youtube_g/model/comment.rb +20 -0
- data/lib/youtube_g/request/comments_search.rb +41 -0
- data/lib/youtube_g/response/comments_search.rb +41 -0
- data/lib/youtube_g/version.rb +1 -1
- metadata +28 -12
data/Manifest.txt
CHANGED
@@ -8,6 +8,7 @@ lib/youtube_g/chain_io.rb
|
|
8
8
|
lib/youtube_g/client.rb
|
9
9
|
lib/youtube_g/model/author.rb
|
10
10
|
lib/youtube_g/model/category.rb
|
11
|
+
lib/youtube_g/model/comment.rb
|
11
12
|
lib/youtube_g/model/contact.rb
|
12
13
|
lib/youtube_g/model/content.rb
|
13
14
|
lib/youtube_g/model/playlist.rb
|
@@ -18,10 +19,12 @@ lib/youtube_g/model/video.rb
|
|
18
19
|
lib/youtube_g/parser.rb
|
19
20
|
lib/youtube_g/record.rb
|
20
21
|
lib/youtube_g/request/base_search.rb
|
22
|
+
lib/youtube_g/request/comments_search.rb
|
21
23
|
lib/youtube_g/request/standard_search.rb
|
22
24
|
lib/youtube_g/request/user_search.rb
|
23
25
|
lib/youtube_g/request/video_search.rb
|
24
26
|
lib/youtube_g/request/video_upload.rb
|
27
|
+
lib/youtube_g/response/comments_search.rb
|
25
28
|
lib/youtube_g/response/video_search.rb
|
26
29
|
lib/youtube_g/version.rb
|
27
30
|
test/helper.rb
|
data/Rakefile
CHANGED
@@ -2,23 +2,24 @@ require 'rubygems'
|
|
2
2
|
require 'hoe'
|
3
3
|
require 'lib/youtube_g/version'
|
4
4
|
|
5
|
-
Hoe.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
Hoe.spec 'natedaiger-youtube-g' do
|
6
|
+
version = YouTubeG::VERSION
|
7
|
+
rubyforge_name = 'natedaiger-youtube-g'
|
8
|
+
author = ["Shane Vitarana", "Walter Korman", "Aman Gupta", "Filip H.F. Slagter", "msp"]
|
9
|
+
email = 'shanev@gmail.com'
|
10
|
+
summary = 'Ruby client for the YouTube GData API'
|
11
|
+
url = 'http://rubyforge.org/projects/youtube-g/'
|
12
|
+
extra_deps << ['builder', '>= 0']
|
13
|
+
remote_rdoc_dir = ''
|
13
14
|
end
|
14
15
|
|
15
|
-
desc 'Tag release'
|
16
|
-
task :tag do
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
# desc 'Tag release'
|
17
|
+
# task :tag do
|
18
|
+
# svn_root = 'svn+ssh://drummr77@rubyforge.org/var/svn/youtube-g'
|
19
|
+
# sh %(svn cp #{svn_root}/trunk #{svn_root}/tags/release-#{YouTubeG::VERSION} -m "Tag YouTubeG release #{YouTubeG::VERSION}")
|
20
|
+
# end
|
20
21
|
|
21
|
-
desc 'Load the library in an IRB session'
|
22
|
-
task :console do
|
23
|
-
|
24
|
-
end
|
22
|
+
# desc 'Load the library in an IRB session'
|
23
|
+
# task :console do
|
24
|
+
# sh %(irb -r lib/youtube_g.rb)
|
25
|
+
# end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class YouTubeG
|
2
|
+
module Model
|
3
|
+
class Comment < YouTubeG::Record
|
4
|
+
# *Time*:: When the video was published on Youtube.
|
5
|
+
attr_reader :published_at
|
6
|
+
|
7
|
+
# *Time*:: When the video's data was last updated.
|
8
|
+
attr_reader :updated_at
|
9
|
+
|
10
|
+
# *String*:: Title for the video.
|
11
|
+
attr_reader :title
|
12
|
+
|
13
|
+
# *String*:: Description of the video.
|
14
|
+
attr_reader :content
|
15
|
+
|
16
|
+
# YouTubeG::Model::Author:: Information about the YouTube user who owns a piece of video content.
|
17
|
+
attr_reader :author
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class YouTubeG
|
2
|
+
module Request #:nodoc:
|
3
|
+
class CommentsSearch < BaseSearch #:nodoc:
|
4
|
+
attr_reader :max_results # max_results
|
5
|
+
attr_reader :offset # start-index
|
6
|
+
|
7
|
+
def initialize(video_id, options={})
|
8
|
+
@max_results, @order_by, @offset = nil
|
9
|
+
@url = base_url
|
10
|
+
|
11
|
+
@url << "videos/#{video_id}/comments"
|
12
|
+
set_instance_variables(options)
|
13
|
+
|
14
|
+
if options.has_key?(:per_page)
|
15
|
+
@max_results = options[:per_page]
|
16
|
+
end
|
17
|
+
|
18
|
+
if options.has_key?(:page)
|
19
|
+
per_page = @max_results || 25
|
20
|
+
@offset = calculate_offset(options[:page], per_page)
|
21
|
+
end
|
22
|
+
|
23
|
+
@url << build_query_params(to_youtube_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def to_youtube_params
|
29
|
+
{
|
30
|
+
'max-results' => @max_results,
|
31
|
+
'start-index' => @offset
|
32
|
+
}
|
33
|
+
end
|
34
|
+
private
|
35
|
+
def calculate_offset(page, per_page)
|
36
|
+
page == 1 ? 1 : ((per_page * page) - per_page + 1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class YouTubeG
|
2
|
+
module Response
|
3
|
+
class CommentsSearch < YouTubeG::Record
|
4
|
+
# *String*:: Unique feed identifying url.
|
5
|
+
attr_reader :feed_id
|
6
|
+
|
7
|
+
# *Fixnum*:: Number of results per page.
|
8
|
+
attr_reader :max_result_count
|
9
|
+
|
10
|
+
# *Fixnum*:: 1-based offset index into the full result set.
|
11
|
+
attr_reader :offset
|
12
|
+
|
13
|
+
# *Fixnum*:: Total number of results available for the original request.
|
14
|
+
attr_reader :total_result_count
|
15
|
+
|
16
|
+
# *Time*:: Date and time at which the feed was last updated
|
17
|
+
attr_reader :updated_at
|
18
|
+
|
19
|
+
# *Array*:: Array of YouTubeG::Model::Video records
|
20
|
+
attr_reader :comments
|
21
|
+
|
22
|
+
def current_page
|
23
|
+
((offset - 1) / max_result_count) + 1
|
24
|
+
end
|
25
|
+
|
26
|
+
# current_page + 1 or nil if there is no next page
|
27
|
+
def next_page
|
28
|
+
current_page < total_pages ? (current_page + 1) : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# current_page - 1 or nil if there is no previous page
|
32
|
+
def previous_page
|
33
|
+
current_page > 1 ? (current_page - 1) : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def total_pages
|
37
|
+
(total_result_count / max_result_count.to_f).ceil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/youtube_g/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natedaiger-youtube-g
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 1
|
9
|
+
version: 0.6.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Shane Vitarana
|
@@ -18,24 +23,30 @@ default_executable:
|
|
18
23
|
dependencies:
|
19
24
|
- !ruby/object:Gem::Dependency
|
20
25
|
name: builder
|
21
|
-
|
22
|
-
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
28
|
requirements:
|
25
29
|
- - ">="
|
26
30
|
- !ruby/object:Gem::Version
|
31
|
+
segments:
|
32
|
+
- 0
|
27
33
|
version: "0"
|
28
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
29
36
|
- !ruby/object:Gem::Dependency
|
30
37
|
name: hoe
|
31
|
-
|
32
|
-
|
33
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
34
40
|
requirements:
|
35
41
|
- - ">="
|
36
42
|
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 8
|
46
|
+
- 3
|
37
47
|
version: 1.8.3
|
38
|
-
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
39
50
|
description: "youtube-g is a pure Ruby client for the YouTube GData API. It provides an easy way to access the latest YouTube video search results from your own programs. In comparison with the earlier Youtube search interfaces, this new API and library offers much-improved flexibility around executing complex search queries to obtain well-targeted video search results. More detail on the underlying source Google-provided API is available at: http://code.google.com/apis/youtube/overview.html"
|
40
51
|
email: shanev@gmail.com
|
41
52
|
executables: []
|
@@ -79,6 +90,9 @@ files:
|
|
79
90
|
- test/test_client.rb
|
80
91
|
- test/test_video.rb
|
81
92
|
- test/test_video_search.rb
|
93
|
+
- lib/youtube_g/model/comment.rb
|
94
|
+
- lib/youtube_g/request/comments_search.rb
|
95
|
+
- lib/youtube_g/response/comments_search.rb
|
82
96
|
has_rdoc: true
|
83
97
|
homepage: http://rubyforge.org/projects/youtube-g/
|
84
98
|
licenses: []
|
@@ -93,18 +107,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
107
|
requirements:
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
96
112
|
version: "0"
|
97
|
-
version:
|
98
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
114
|
requirements:
|
100
115
|
- - ">="
|
101
116
|
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
102
119
|
version: "0"
|
103
|
-
version:
|
104
120
|
requirements: []
|
105
121
|
|
106
122
|
rubyforge_project: youtube-g
|
107
|
-
rubygems_version: 1.3.
|
123
|
+
rubygems_version: 1.3.6
|
108
124
|
signing_key:
|
109
125
|
specification_version: 2
|
110
126
|
summary: Ruby client for the YouTube GData API
|