yourub 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -17
- data/config/yourub.yml +1 -1
- data/lib/yourub/client.rb +14 -180
- data/lib/yourub/config.rb +1 -1
- data/lib/yourub/count_filter.rb +1 -1
- data/lib/yourub/reader.rb +2 -2
- data/lib/yourub/rest/api.rb +12 -0
- data/lib/yourub/rest/request.rb +30 -0
- data/lib/yourub/rest/search.rb +159 -0
- data/lib/yourub/validator.rb +2 -2
- data/lib/yourub/version.rb +1 -1
- data/lib/yourub.rb +2 -1
- data/spec/fixtures/categories.json +0 -0
- data/spec/fixtures/category.json +0 -0
- data/spec/helper.rb +26 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/{client_spec.rb → yourub/client_spec.rb} +5 -4
- data/spec/{count_filter_spec.rb → yourub/count_filter_spec.rb} +0 -0
- data/spec/{validator_spec.rb → yourub/validator_spec.rb} +0 -0
- data/yourub.gemspec +1 -0
- metadata +19 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4ebd119d0c0ca1c91826ac02c6fd172fc0f9119
|
4
|
+
data.tar.gz: 5c4ceed6b992398e35b173e44a3b29f31b065ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a460508012396828652e043c2f2bc5f90c61651145a78117e2f962b3a6ad545fe79722c188037f8430802eaa4209f99543b932db574c669aa5b931eb72f31a7
|
7
|
+
data.tar.gz: 947f855feac11c2ce095c102dbd01a42898750dae9f3411afb0c2fbf354928c6c5a073b41c5b1b0911c38cd9eebcc1595ca21193cb7251bb4a27d0e213f9a280
|
data/README.md
CHANGED
@@ -73,39 +73,33 @@ client = Yourub::Client.new
|
|
73
73
|
client.search(query: "aliens")
|
74
74
|
client.videos
|
75
75
|
```
|
76
|
-
|
77
|
-
### Extend Info
|
78
|
-
As default Yourub will give you back few values, example:
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
client = Yourub::Client.new
|
82
|
-
client.search(id: "mN0Dbj-xHY0")
|
83
|
-
```
|
84
|
-
will report id, title, the default thumb, and the url where you can watch the video
|
76
|
+
that is the content of the response:
|
85
77
|
```
|
86
|
-
[{"id"=>"
|
78
|
+
[{"kind"=>"youtube#video", "etag"=>"\"N5Eg36Gl054SUNiWWc-Su3t5O-k/U6AzLXvcnZt2WFqpnq9_dksV7DA\"", "id"=>"NisCkxU544c", "snippet"=>{"publishedAt"=>"2009-04-05T05:20:10.000Z", "channelId"=>"UCCHcEUksSVKsRDH86j77Ntg", "title"=>"Like A Boss (ft. Seth Rogen) - Uncensored Version", "description"=>"http://www.itunes.com/thelonelyisland\r\n\r\nThe new single from The Lonely Island's debut album \"INCREDIBAD\" In stores now!\r\n\r\nFeaturing Seth Rogen.\r\n\r\nThe Lonely Island is Andy Samberg, Akiva Schaffer & Jorma Taccone.", "thumbnails"=>{"default"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/default.jpg", "width"=>120, "height"=>90}, "medium"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/mqdefault.jpg", "width"=>320, "height"=>180}, "high"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/hqdefault.jpg", "width"=>480, "height"=>360}, "standard"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/sddefault.jpg", "width"=>640, "height"=>480}, "maxres"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/maxresdefault.jpg", "width"=>1280, "height"=>720}}, "channelTitle"=>"thelonelyisland", "categoryId"=>"23", "liveBroadcastContent"=>"none"}, "statistics"=>{"viewCount"=>"120176425", "likeCount"=>"594592", "dislikeCount"=>"15121", "favoriteCount"=>"0", "commentCount"=>"208109"}}]
|
87
79
|
```
|
88
80
|
|
89
|
-
|
81
|
+
### Methods
|
82
|
+
`search`, search youtube videos for the given parameters
|
90
83
|
```ruby
|
91
84
|
client = Yourub::Client.new
|
92
|
-
client.extended_info = true
|
93
85
|
client.search(id: "NisCkxU544c")
|
94
86
|
```
|
95
|
-
It will give you much more information
|
96
|
-
```
|
97
|
-
[{"kind"=>"youtube#video", "etag"=>"\"N5Eg36Gl054SUNiWWc-Su3t5O-k/U6AzLXvcnZt2WFqpnq9_dksV7DA\"", "id"=>"NisCkxU544c", "snippet"=>{"publishedAt"=>"2009-04-05T05:20:10.000Z", "channelId"=>"UCCHcEUksSVKsRDH86j77Ntg", "title"=>"Like A Boss (ft. Seth Rogen) - Uncensored Version", "description"=>"http://www.itunes.com/thelonelyisland\r\n\r\nThe new single from The Lonely Island's debut album \"INCREDIBAD\" In stores now!\r\n\r\nFeaturing Seth Rogen.\r\n\r\nThe Lonely Island is Andy Samberg, Akiva Schaffer & Jorma Taccone.", "thumbnails"=>{"default"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/default.jpg", "width"=>120, "height"=>90}, "medium"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/mqdefault.jpg", "width"=>320, "height"=>180}, "high"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/hqdefault.jpg", "width"=>480, "height"=>360}, "standard"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/sddefault.jpg", "width"=>640, "height"=>480}, "maxres"=>{"url"=>"https://i1.ytimg.com/vi/NisCkxU544c/maxresdefault.jpg", "width"=>1280, "height"=>720}}, "channelTitle"=>"thelonelyisland", "categoryId"=>"23", "liveBroadcastContent"=>"none"}, "statistics"=>{"viewCount"=>"120176425", "likeCount"=>"594592", "dislikeCount"=>"15121", "favoriteCount"=>"0", "commentCount"=>"208109"}}]
|
98
|
-
```
|
99
87
|
|
100
|
-
|
88
|
+
`get_views`
|
89
|
+
retrieves the number of views for the given videos id
|
101
90
|
```ruby
|
102
91
|
client = Yourub::Client.new
|
103
92
|
client.get_views("G2b0OIkTraI")
|
104
93
|
```
|
105
94
|
|
95
|
+
|
96
|
+
To have more values back, use the option `extended_info`
|
106
97
|
##TODO
|
107
98
|
|
108
99
|
1. adding a CLI
|
100
|
+
2. the result should be yield, and not saved in an instance variable
|
101
|
+
3. replace GoogleApiClient
|
102
|
+
4. Implementing playlist
|
109
103
|
|
110
104
|
## Contributing
|
111
105
|
|
data/config/yourub.yml
CHANGED
data/lib/yourub/client.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
require 'yourub/rest/api'
|
2
|
+
require 'google/api_client'
|
3
|
+
|
1
4
|
module Yourub
|
2
|
-
class Client
|
5
|
+
class Client < Google::APIClient
|
6
|
+
include Yourub::REST::API
|
3
7
|
|
4
8
|
attr_reader :videos
|
5
|
-
attr_accessor :config
|
9
|
+
attr_accessor :config
|
6
10
|
|
7
11
|
def initialize()
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:
|
13
|
-
:type => 'video',
|
14
|
-
:order => 'relevance',
|
15
|
-
:safeSearch => 'none',
|
12
|
+
args = {
|
13
|
+
:key => config.developer_key,
|
14
|
+
:application_name => config.application_name,
|
15
|
+
:application_version => config.application_version,
|
16
|
+
:authorization => nil
|
16
17
|
}
|
18
|
+
super(args)
|
17
19
|
end
|
18
20
|
|
19
21
|
def config
|
@@ -24,178 +26,10 @@ module Yourub
|
|
24
26
|
Yourub::Validator.available_countries
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
28
|
-
@
|
29
|
-
:key => config.developer_key,
|
30
|
-
:application_name => config.application_name,
|
31
|
-
:application_version => config.application_version,
|
32
|
-
:authorization => nil,
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def youtube
|
37
|
-
@youtube ||= client.discovered_api(config.youtube_api_service_name,
|
29
|
+
def youtube_api
|
30
|
+
@youtube_api ||= self.discovered_api(config.youtube_api_service_name,
|
38
31
|
config.youtube_api_version)
|
39
32
|
end
|
40
33
|
|
41
|
-
def search(criteria)
|
42
|
-
begin
|
43
|
-
@videos = []
|
44
|
-
@criteria = Yourub::Validator.confirm(criteria)
|
45
|
-
search_by_criteria
|
46
|
-
rescue ArgumentError => e
|
47
|
-
Yourub.logger.error "#{e}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def search_by_criteria
|
52
|
-
if @criteria.has_key? :id
|
53
|
-
search_by_id
|
54
|
-
else
|
55
|
-
merge_criteria_with_api_options
|
56
|
-
retrieve_categories
|
57
|
-
retrieve_videos
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def search_by_id
|
62
|
-
params = {
|
63
|
-
:id => @criteria[:id],
|
64
|
-
:part => 'snippet,statistics',
|
65
|
-
}
|
66
|
-
video_response = client.execute!(
|
67
|
-
:api_method => youtube.videos.list,
|
68
|
-
:parameters => params
|
69
|
-
)
|
70
|
-
entry = Yourub::Reader.parse_videos(video_response)
|
71
|
-
add_video_to_search_result(entry.first) unless entry.nil?
|
72
|
-
end
|
73
|
-
|
74
|
-
def merge_criteria_with_api_options
|
75
|
-
mappings = {query: :q, max_results: :maxResults, country: :regionCode}
|
76
|
-
@api_options.merge! @criteria
|
77
|
-
@api_options.keys.each do |k|
|
78
|
-
@api_options[ mappings[k] ] = @api_options.delete(k) if mappings[k]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def retrieve_categories
|
83
|
-
if @criteria.has_key? :category
|
84
|
-
get_categories_for_country(@criteria[:country])
|
85
|
-
@categories = Yourub::Validator.valid_category(@categories, @criteria[:category])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_categories_for_country(country)
|
90
|
-
categories_list = video_categories_list_request(country)
|
91
|
-
categories_list.data.items.each do |cat_result|
|
92
|
-
category_name = parse_name(cat_result["snippet"]["title"])
|
93
|
-
@categories.push(cat_result["id"] => category_name)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def retrieve_videos
|
98
|
-
consume_criteria do |criteria|
|
99
|
-
begin
|
100
|
-
req = search_list_request(criteria)
|
101
|
-
if @extended_info || Yourub::CountFilter.filter
|
102
|
-
get_details_and_store req
|
103
|
-
else
|
104
|
-
videos = Yourub::Reader.parse_videos(req)
|
105
|
-
videos.each{ |v| add_video_to_search_result(v) }
|
106
|
-
end
|
107
|
-
rescue StandardError => e
|
108
|
-
Yourub.logger.error "Error #{e} retrieving videos for the criteria: #{criteria.to_s}"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def consume_criteria
|
114
|
-
to_consume = @api_options
|
115
|
-
if @criteria[:country]
|
116
|
-
@criteria[:country].each do |country|
|
117
|
-
to_consume[:regionCode] = country
|
118
|
-
consume_categories(to_consume) do |cat|
|
119
|
-
yield cat
|
120
|
-
end
|
121
|
-
end
|
122
|
-
else
|
123
|
-
yield to_consume
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def consume_categories(to_consume)
|
128
|
-
if @categories.size > 0
|
129
|
-
@categories.each do |cat|
|
130
|
-
to_consume[:videoCategoryId] = cat.keys[0].to_i
|
131
|
-
yield to_consume
|
132
|
-
end
|
133
|
-
else
|
134
|
-
yield to_consume
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def get_details_and_store(video_list)
|
139
|
-
video_list.data.items.each do |video_item|
|
140
|
-
v = videos_list_request video_item.id.videoId
|
141
|
-
v = Yourub::Reader.parse_videos(v)
|
142
|
-
add_video_to_search_result(v.first) if v
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def search_list_request(options)
|
147
|
-
search_response = client.execute!(
|
148
|
-
:api_method => youtube.search.list,
|
149
|
-
:parameters => options
|
150
|
-
)
|
151
|
-
end
|
152
|
-
|
153
|
-
def videos_list_request(result_video_id)
|
154
|
-
params = video_params(result_video_id)
|
155
|
-
video_response = client.execute!(
|
156
|
-
:api_method => youtube.videos.list,
|
157
|
-
:parameters => params
|
158
|
-
)
|
159
|
-
end
|
160
|
-
|
161
|
-
def video_categories_list_request(country)
|
162
|
-
categories_list = client.execute!(
|
163
|
-
:api_method => youtube.video_categories.list,
|
164
|
-
:parameters => {"part" => "snippet","regionCode" => country }
|
165
|
-
)
|
166
|
-
end
|
167
|
-
|
168
|
-
def video_params(result_video_id)
|
169
|
-
parameters = {
|
170
|
-
:id => result_video_id,
|
171
|
-
:part => 'snippet,statistics,id',
|
172
|
-
}
|
173
|
-
unless @extended_info
|
174
|
-
fields = 'items(id,snippet(title,thumbnails),statistics(viewCount))'
|
175
|
-
parameters[:fields] = URI::encode(fields)
|
176
|
-
end
|
177
|
-
return parameters
|
178
|
-
end
|
179
|
-
|
180
|
-
def add_video_to_search_result(entry)
|
181
|
-
video = @extended_info ? entry : Yourub::Reader.parse_entry(entry)
|
182
|
-
if Yourub::CountFilter.accept?(entry)
|
183
|
-
@videos.push(video)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def parse_name(name)
|
188
|
-
return name.gsub("/", "-").downcase.gsub(/\s+/, "")
|
189
|
-
end
|
190
|
-
|
191
|
-
def get_views(id)
|
192
|
-
request = client.execute!(
|
193
|
-
:api_method => youtube.videos.list,
|
194
|
-
:parameters => {:id => id, :part => 'statistics'}
|
195
|
-
)
|
196
|
-
v = Yourub::Reader.parse_videos(request)
|
197
|
-
v ? Yourub::CountFilter.get_views_count(v.first) : nil
|
198
|
-
end
|
199
|
-
|
200
34
|
end
|
201
35
|
end
|
data/lib/yourub/config.rb
CHANGED
data/lib/yourub/count_filter.rb
CHANGED
data/lib/yourub/reader.rb
CHANGED
@@ -9,7 +9,7 @@ module Yourub
|
|
9
9
|
|
10
10
|
def parse_entry(entry)
|
11
11
|
video_id = entry["id"]["videoId"] || entry['id']
|
12
|
-
|
12
|
+
{
|
13
13
|
'id' => video_id,
|
14
14
|
'title' => entry['snippet']['title'],
|
15
15
|
'thumb' => entry['snippet']['thumbnails']['default']['url'],
|
@@ -18,4 +18,4 @@ module Yourub
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'yourub/rest/search'
|
2
|
+
|
3
|
+
module Yourub
|
4
|
+
module REST
|
5
|
+
# @note WIP, the modules will follow the same grouping used in https://developers.google.com/youtube/v3/docs/.
|
6
|
+
module API
|
7
|
+
# include Yourub::REST::Playlists
|
8
|
+
# include Yourub::REST::Channels
|
9
|
+
include Yourub::REST::Search
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Yourub
|
2
|
+
module REST
|
3
|
+
class Request
|
4
|
+
attr_reader :data, :status
|
5
|
+
|
6
|
+
# @param client [Yourub::Client]
|
7
|
+
# @param resource_type [String]
|
8
|
+
# @param method [String]
|
9
|
+
# @param params [Hash]
|
10
|
+
# @return [Youtube::Request]
|
11
|
+
def initialize(client, resource_type, method, params)
|
12
|
+
@client = client
|
13
|
+
@resource_type = resource_type
|
14
|
+
@method = method
|
15
|
+
@params = params
|
16
|
+
perform
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
r = @client.execute!(
|
21
|
+
:api_method => @client.youtube_api.send(@resource_type.to_sym).send(@method.to_sym),
|
22
|
+
:parameters => @params
|
23
|
+
)
|
24
|
+
@data = r.data
|
25
|
+
@status = r.status
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'yourub/rest/request'
|
2
|
+
|
3
|
+
module Yourub
|
4
|
+
module REST
|
5
|
+
module Search
|
6
|
+
|
7
|
+
def search(criteria)
|
8
|
+
begin
|
9
|
+
@api_options= {
|
10
|
+
:part => 'snippet',
|
11
|
+
:type => 'video',
|
12
|
+
:order => 'relevance',
|
13
|
+
:safeSearch => 'none',
|
14
|
+
}
|
15
|
+
|
16
|
+
@categories, @videos = [], []
|
17
|
+
@count_filter = {}
|
18
|
+
@criteria = Yourub::Validator.confirm(criteria)
|
19
|
+
search_by_criteria
|
20
|
+
rescue ArgumentError => e
|
21
|
+
Yourub.logger.error "#{e}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def search_by_criteria
|
26
|
+
if @criteria.has_key? :id
|
27
|
+
search_by_id
|
28
|
+
else
|
29
|
+
merge_criteria_with_api_options
|
30
|
+
retrieve_categories
|
31
|
+
retrieve_videos
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def search_by_id
|
36
|
+
params = {
|
37
|
+
:id => @criteria[:id],
|
38
|
+
:part => 'snippet,statistics',
|
39
|
+
}
|
40
|
+
video_response = videos_list_request(params)
|
41
|
+
entry = Yourub::Reader.parse_videos(video_response)
|
42
|
+
add_video_to_search_result(entry.first) unless entry.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def merge_criteria_with_api_options
|
46
|
+
mappings = {query: :q, max_results: :maxResults, country: :regionCode}
|
47
|
+
@api_options.merge! @criteria
|
48
|
+
@api_options.keys.each do |k|
|
49
|
+
@api_options[ mappings[k] ] = @api_options.delete(k) if mappings[k]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def retrieve_categories
|
54
|
+
if @criteria.has_key? :category
|
55
|
+
get_categories_for_country(@criteria[:country])
|
56
|
+
@categories = Yourub::Validator.valid_category(@categories, @criteria[:category])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_categories_for_country(country)
|
61
|
+
param = {"part" => "snippet","regionCode" => country }
|
62
|
+
categories_list = video_categories_list_request(param)
|
63
|
+
categories_list.data.items.each do |cat_result|
|
64
|
+
category_name = parse_name(cat_result["snippet"]["title"])
|
65
|
+
@categories.push(cat_result["id"] => category_name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def retrieve_videos
|
70
|
+
consume_criteria do |criteria|
|
71
|
+
begin
|
72
|
+
req = search_list_request(criteria)
|
73
|
+
get_details_and_store req
|
74
|
+
rescue StandardError => e
|
75
|
+
Yourub.logger.error "Error #{e} retrieving videos for the criteria: #{criteria.to_s}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def consume_criteria
|
81
|
+
to_consume = @api_options
|
82
|
+
if @criteria[:country]
|
83
|
+
@criteria[:country].each do |country|
|
84
|
+
to_consume[:regionCode] = country
|
85
|
+
consume_categories(to_consume) do |cat|
|
86
|
+
yield cat
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
yield to_consume
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def consume_categories(to_consume)
|
95
|
+
if @categories.size > 0
|
96
|
+
@categories.each do |cat|
|
97
|
+
to_consume[:videoCategoryId] = cat.keys[0].to_i
|
98
|
+
yield to_consume
|
99
|
+
end
|
100
|
+
else
|
101
|
+
yield to_consume
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_details_and_store(video_list)
|
106
|
+
video_list.data.items.each do |video_item|
|
107
|
+
params = video_params(video_item.id.videoId)
|
108
|
+
v = videos_list_request(params)
|
109
|
+
v = Yourub::Reader.parse_videos(v)
|
110
|
+
add_video_to_search_result(v.first) if v
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def search_list_request(params)
|
115
|
+
send_request("search", "list", params)
|
116
|
+
end
|
117
|
+
|
118
|
+
def videos_list_request(params)
|
119
|
+
send_request("videos", "list", params)
|
120
|
+
end
|
121
|
+
|
122
|
+
def video_categories_list_request(params)
|
123
|
+
send_request("video_categories", "list", params)
|
124
|
+
end
|
125
|
+
|
126
|
+
def send_request(resource_type, method, params)
|
127
|
+
#byebug
|
128
|
+
Yourub::REST::Request.new(self, resource_type, method, params)
|
129
|
+
end
|
130
|
+
|
131
|
+
def video_params(result_video_id)
|
132
|
+
fields = URI::encode(
|
133
|
+
'items(id,snippet(title,thumbnails),statistics(viewCount))'
|
134
|
+
)
|
135
|
+
{ :id => result_video_id,
|
136
|
+
:part => 'snippet,statistics,id',
|
137
|
+
:fields => fields }
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_video_to_search_result(entry)
|
141
|
+
if Yourub::CountFilter.accept?(entry)
|
142
|
+
@videos.push(entry)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def parse_name(name)
|
147
|
+
return name.gsub("/", "-").downcase.gsub(/\s+/, "")
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_views(id)
|
151
|
+
params = {:id => id, :part => 'statistics'}
|
152
|
+
request = videos_list_request(params)
|
153
|
+
v = Yourub::Reader.parse_videos(request)
|
154
|
+
v ? Yourub::CountFilter.get_views_count(v.first) : nil
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/yourub/validator.rb
CHANGED
@@ -7,7 +7,7 @@ module Yourub
|
|
7
7
|
'HU','IN','IE','IL','IT','JP','JO','MY','MX','MA','NL','NZ','PE','PH',
|
8
8
|
'PL','RU','SA','SG','ZA','KR','ES','SE','CH','TW','AE','US']
|
9
9
|
ORDERS = ['date', 'rating', 'relevance', 'title', 'videoCount', 'viewCount']
|
10
|
-
VALID_PARAMS = [:country, :category, :query, :id, :max_results, :count_filter, :order]
|
10
|
+
VALID_PARAMS = [:country, :category, :query, :id, :max_results, :count_filter, :order ]
|
11
11
|
MINIMUM_PARAMS = [:country, :category, :query, :id]
|
12
12
|
|
13
13
|
def confirm(criteria)
|
@@ -43,7 +43,7 @@ module Yourub
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def remove_empty_and_non_valid_params
|
46
|
-
@criteria.keep_if{|k,v| ( (VALID_PARAMS.include? k) &&
|
46
|
+
@criteria.keep_if{|k,v| ( (VALID_PARAMS.include? k) && v.size > 0) }
|
47
47
|
end
|
48
48
|
|
49
49
|
def keep_only_the_id_if_present
|
data/lib/yourub/version.rb
CHANGED
data/lib/yourub.rb
CHANGED
@@ -2,10 +2,11 @@ require 'json'
|
|
2
2
|
require 'logger'
|
3
3
|
require 'net/https'
|
4
4
|
require 'open-uri'
|
5
|
-
require 'google/api_client'
|
6
5
|
|
7
6
|
require 'yourub/config'
|
8
7
|
require 'yourub/client'
|
8
|
+
#require 'yourub/search'
|
9
|
+
#require 'yourub/request'
|
9
10
|
require 'yourub/version'
|
10
11
|
require 'yourub/logger'
|
11
12
|
require 'yourub/count_filter'
|
File without changes
|
File without changes
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#require 'webmock/rspec'
|
2
|
+
|
3
|
+
#WebMock.disable_net_connect!(allow_localhost: true)
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.filter_run_including :focus => true
|
6
|
+
end
|
7
|
+
|
8
|
+
def a_get(path)
|
9
|
+
a_request(:get, Yourub::REST::Request::BASE_URL + path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_get(path)
|
13
|
+
stub_request(:get, Yourub::REST::Request::BASE_URL + path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def capture_warning
|
17
|
+
begin
|
18
|
+
old_stderr = $stderr
|
19
|
+
$stderr = StringIO.new
|
20
|
+
yield
|
21
|
+
result = $stderr.string
|
22
|
+
ensure
|
23
|
+
$stderr = old_stderr
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#WebMock.disable_net_connect!(allow_localhost: true)
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.filter_run_including :focus => true
|
6
|
+
end
|
7
|
+
|
8
|
+
def a_get(path)
|
9
|
+
a_request(:get, Yourub::REST::Request::BASE_URL + path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_get(path)
|
13
|
+
stub_request(:get, Yourub::REST::Request::BASE_URL + path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def capture_warning
|
17
|
+
begin
|
18
|
+
old_stderr = $stderr
|
19
|
+
$stderr = StringIO.new
|
20
|
+
yield
|
21
|
+
result = $stderr.string
|
22
|
+
ensure
|
23
|
+
$stderr = old_stderr
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'yourub'
|
2
|
+
#require 'byebug'
|
3
|
+
#require_relative '../spec_helper'
|
2
4
|
|
3
5
|
describe Yourub::Client do
|
4
6
|
|
@@ -14,10 +16,9 @@ describe Yourub::Client do
|
|
14
16
|
expect(subject.countries).to be_a_kind_of(Array)
|
15
17
|
end
|
16
18
|
|
17
|
-
it "retrieves more infos with the option
|
19
|
+
it "retrieves more infos with the option" do
|
18
20
|
filter = {views: ">= 100"}
|
19
|
-
subject.extended_info
|
20
|
-
subject.search(country: "US", category: "Sports", count_filter: filter)
|
21
|
+
subject.search(country: "US", category: "Sports", count_filter: filter, extended_info: true)
|
21
22
|
expect(subject.videos.first.has_key? "statistics").to be_true
|
22
23
|
end
|
23
24
|
|
@@ -77,4 +78,4 @@ describe Yourub::Client do
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
end
|
81
|
+
end
|
File without changes
|
File without changes
|
data/yourub.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yourub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Prati
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -118,11 +118,18 @@ files:
|
|
118
118
|
- lib/yourub/logger.rb
|
119
119
|
- lib/yourub/railtie.rb
|
120
120
|
- lib/yourub/reader.rb
|
121
|
+
- lib/yourub/rest/api.rb
|
122
|
+
- lib/yourub/rest/request.rb
|
123
|
+
- lib/yourub/rest/search.rb
|
121
124
|
- lib/yourub/validator.rb
|
122
125
|
- lib/yourub/version.rb
|
123
|
-
- spec/
|
124
|
-
- spec/
|
125
|
-
- spec/
|
126
|
+
- spec/fixtures/categories.json
|
127
|
+
- spec/fixtures/category.json
|
128
|
+
- spec/helper.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/yourub/client_spec.rb
|
131
|
+
- spec/yourub/count_filter_spec.rb
|
132
|
+
- spec/yourub/validator_spec.rb
|
126
133
|
- yourub.gemspec
|
127
134
|
- yourub.sublime-project
|
128
135
|
homepage: https://github.com/edap/yourub
|
@@ -150,6 +157,10 @@ signing_key:
|
|
150
157
|
specification_version: 4
|
151
158
|
summary: Yourub is a gem that search videos on youtebe using the YouTube API v3
|
152
159
|
test_files:
|
153
|
-
- spec/
|
154
|
-
- spec/
|
155
|
-
- spec/
|
160
|
+
- spec/fixtures/categories.json
|
161
|
+
- spec/fixtures/category.json
|
162
|
+
- spec/helper.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- spec/yourub/client_spec.rb
|
165
|
+
- spec/yourub/count_filter_spec.rb
|
166
|
+
- spec/yourub/validator_spec.rb
|