yourub 2.0.2 → 3.0.0

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.
@@ -5,49 +5,107 @@ describe Yourub::MetaSearch do
5
5
  context 'Initialize the Request class if the given parameter are valid' do
6
6
 
7
7
  let(:client) { Yourub::Client.new() }
8
- # let(:discovered_api) { double("youtube_api")}
9
- #let(:discovered_api) { double("youtube_api")}
10
- let(:response) {OpenStruct.new(data: {items: [{"statistics" => {"viewCount" => 2}}]}, status: 200)}
11
- let(:videos_list_response) { fixture("videos_list.json")}
12
- let(:search_list_response) { fixture("search_list.json")}
13
- let(:categories_formatted) { fixture("categories_list_formatted.json") }
14
- let(:single_video_response) { fixture("video_with_200_views.json") }
8
+ let(:videos_list_items) do
9
+ raw = fixture("videos_list.json")
10
+ raw.is_a?(Hash) && raw["items"] ? raw["items"] : raw
11
+ end
12
+ let(:videos_list_request) do
13
+ OpenStruct.new(status: 200, data: OpenStruct.new(items: videos_list_items))
14
+ end
15
+ let(:search_list_response) do
16
+ raw = fixture("search_list.json")
17
+ raw.is_a?(Hash) && raw["items"] ? raw["items"] : raw
18
+ end
15
19
  let(:result){ double }
16
20
 
17
21
  before do
18
- # discovered_api.stub_chain(:data, :items).and_return(categories)
19
- # discovered_api.stub_chain(:search, :list).and_return("search.list")
20
- # discovered_api.stub_chain(:video_categories, :list).and_return("video_categories.list")
21
- # allow(client).to receive(:youtube_api).and_return(discovered_api)
22
- #allow(client).to receive(:execute!).and_return(response)
23
- #allow(Yourub::REST::Request).to receive(:new).and_return(response)
22
+ allow(Yourub::Config).to receive(:developer_key).and_return('secret')
23
+ allow(Yourub::Config).to receive(:application_name).and_return('yourub')
24
+ allow(Yourub::Config).to receive(:application_version).and_return('1.0')
24
25
  allow(result).to receive(:status).and_return(200)
25
26
  end
26
27
 
27
28
  describe '#search' do
28
- context 'forward the parameters to the request' do
29
+ context 'search.list for query nasa' do
29
30
  include_context "search list result load fixture", "search_list.json"
31
+
30
32
  before do
31
- allow(Yourub::REST::Categories).to receive(
32
- :for_country).and_return(categories_formatted)
33
- allow(Yourub::REST::Videos).to receive(:list).and_return(response)
33
+ allow(Yourub::REST::Videos).to receive(:list).and_return(videos_list_request)
34
+ end
35
+
36
+ it 'calls Search.list with snippet video search and q' do
37
+ expect(Yourub::REST::Search).to receive(:list).with(
38
+ client,
39
+ {
40
+ part: "snippet",
41
+ type: "video",
42
+ order: "relevance",
43
+ safeSearch: "none",
44
+ q: "nasa",
45
+ maxResults: 5
46
+ }
47
+ )
48
+ client.search(query: "nasa", max_results: 5) { |_v| }
49
+ end
50
+ end
51
+
52
+ context 'category name resolves via list_video_categories' do
53
+ let(:de_category_response) do
54
+ items = fixture("categories_list.json").fetch("items").map do |h|
55
+ OpenStruct.new(
56
+ id: h["id"],
57
+ snippet: OpenStruct.new(title: h.dig("snippet", "title"))
58
+ )
59
+ end
60
+ OpenStruct.new(items: items)
61
+ end
62
+
63
+ include_context "search list result load fixture", "search_list.json"
64
+
65
+ before do
66
+ allow(client).to receive(:list_video_categories).and_return(de_category_response)
67
+ allow(Yourub::REST::Videos).to receive(:list).and_return(videos_list_request)
68
+ end
69
+
70
+ it 'loads default catalog when country omitted and sets videoCategoryId' do
71
+ expect(client).to receive(:list_video_categories).with(region_code: nil)
72
+ expect(Yourub::REST::Search).to receive(:list).with(
73
+ client,
74
+ hash_including(
75
+ q: "nasa",
76
+ order: "relevance",
77
+ videoCategoryId: 28
78
+ )
79
+ )
80
+ client.search(query: "nasa", category: "science") { |_v| }
34
81
  end
35
82
 
36
- it 'creates a search list request with the expected parameters' do
83
+ it 'uses first country for the category catalog when country is set' do
84
+ expect(client).to receive(:list_video_categories).with(region_code: "DE")
37
85
  expect(Yourub::REST::Search).to receive(:list).with(
38
- client,
39
- {:part => "snippet",
40
- :type => "video",
41
- :order => "date",
42
- :safeSearch => "none",
43
- :category => "Sports",
44
- :maxResults => 5,
45
- :regionCode => "US",
46
- :videoCategoryId => 17}
86
+ client,
87
+ hash_including(
88
+ regionCode: "DE",
89
+ q: "goals",
90
+ videoCategoryId: 17
91
+ )
92
+ )
93
+ client.search(query: "goals", country: "DE", category: "sports") { |_v| }
94
+ end
95
+
96
+ it 'raises ArgumentError listing categories when name does not match' do
97
+ expect {
98
+ client.search(query: "x", category: "zznotacategoryzz") { |_v| }
99
+ }.to raise_error(ArgumentError, /category not found/)
100
+ end
101
+
102
+ it 'rejects category "all"' do
103
+ expect {
104
+ client.search(query: "nasa", category: "all") { |_v| }
105
+ }.to raise_error(
106
+ ArgumentError,
107
+ 'category "all" is not supported; omit :category to search without a video category filter.'
47
108
  )
48
- client.search(
49
- country: 'US', category: 'Sports', order: 'date', max_results: 5
50
- ) { |v| v }
51
109
  end
52
110
  end
53
111
 
@@ -60,7 +118,7 @@ describe Yourub::MetaSearch do
60
118
  :data, :items).and_return(search_list_response)
61
119
  search_result.data.items.each do |single_video|
62
120
  allow(single_video).to receive_message_chain(
63
- :id, :videoId).and_return(1)
121
+ :id, :video_id).and_return(1)
64
122
  end
65
123
 
66
124
  allow(Yourub::REST::Search).to receive(:list).and_return(search_result)
@@ -75,7 +133,7 @@ describe Yourub::MetaSearch do
75
133
  videos.push(v)
76
134
  end
77
135
 
78
- expect(videos.count).to eq(4)
136
+ expect(videos.count).to eq(5)
79
137
  end
80
138
 
81
139
  it 'retrieves no videos with more than 200 views' do
@@ -103,37 +161,16 @@ describe Yourub::MetaSearch do
103
161
  # end
104
162
  # end
105
163
 
106
- # context 'when the parameter category is == "all"' do
107
- # it 'it iterates through all the categories' do
108
- # videos = []
109
- # client.search(country: 'US', category: 'all') do |v|
110
- # videos.push v
111
- # end
112
- # expect(videos).to_not be_empty
113
- # end
114
- # end
115
164
  end
116
165
 
117
166
  describe "methods used only for single video" do
118
- include_context "result load fixture", "video_with_200_views.json"
167
+ include_context "result load fixture", 'video_with_200_views.json'
119
168
 
120
169
  describe '#get' do
121
170
  it 'send the request with the correct parameters' do
122
171
  expect(Yourub::REST::Request).to receive(:new)
123
- .with(client, 'videos', 'list', :id => "mN0Dbj-xHY0", :part=>"snippet,statistics")
124
- client.get('mN0Dbj-xHY0')
125
- end
126
- end
127
-
128
- describe '#get_views' do
129
- it 'send the request with the correct parameters' do
130
- expect(Yourub::REST::Request).to receive(:new)
131
- .with(client, 'videos', 'list', :id => "mN0Dbj-xHY0", :part => "statistics")
132
- client.get_views('mN0Dbj-xHY0')
133
- end
134
-
135
- it 'return the number of view for the given video' do
136
- expect(client.get_views('mN0Dbj-xHY0')).to eq(200)
172
+ .with(client, 'videos', 'list', { :id => "yIlTwwJv1Ac", :part=>"snippet,statistics" })
173
+ client.get('yIlTwwJv1Ac')
137
174
  end
138
175
  end
139
176
  end
@@ -4,22 +4,46 @@ require_relative '../../spec_helper.rb'
4
4
  describe Yourub::REST::Categories do
5
5
  context 'Initialize the Request class if the given parameter are valid' do
6
6
  let(:category_request) { double }
7
- let(:client) { Yourub::Client.new }
8
- let(:categories) { fixture('categories_list.json') }
9
- let(:categories_formatted) { fixture('categories_list_formatted.json') }
7
+ let(:client) { Yourub::Client.new(client_options) }
8
+ let(:client_options) do
9
+ { developer_key: 'secret',
10
+ application_name: 'yourub',
11
+ application_version: '1.0',
12
+ log_level: 'WARN' }
13
+ end
14
+ let(:category_items) { fixture('categories_list.json').fetch('items') }
15
+ let(:categories_objects) do
16
+ category_items.map do |h|
17
+ OpenStruct.new(
18
+ id: h['id'],
19
+ snippet: OpenStruct.new(title: h.dig('snippet', 'title'))
20
+ )
21
+ end
22
+ end
23
+ let(:categories_formatted) do
24
+ category_items.map do |h|
25
+ title = h.dig('snippet', 'title')
26
+ slug = title.gsub("/", "-").downcase.gsub(/\s+/, "")
27
+ { h['id'] => slug }
28
+ end
29
+ end
10
30
 
11
31
  before do
12
32
  allow(category_request).to receive_message_chain(
13
33
  :data, :items
14
- ).and_return(categories)
34
+ ).and_return(categories_objects)
15
35
  allow(Yourub::REST::Request).to receive(:new).and_return(category_request)
16
36
  end
17
37
 
18
38
  describe '.for_country' do
19
39
  it 'create a request with the correct parameters' do
20
40
  expect(Yourub::REST::Request).to receive(:new)
21
- .with(client, 'video_categories', 'list',
22
- 'part' => 'snippet', 'regionCode' => ['US'])
41
+ .with(
42
+ client,
43
+ 'video_categories',
44
+ 'list',
45
+ { 'part' => 'snippet', 'regionCode' => 'US' }
46
+ )
23
47
  subject.for_country(client, ['US'])
24
48
  end
25
49
 
@@ -9,21 +9,21 @@ describe Yourub::REST::Request do
9
9
  describe 'the request object calls the execute! method on the client' do
10
10
  it 'execute the video list request on the client' do
11
11
  expect(client).to receive(:execute!).with(
12
- api_method: 'video_categories.list', parameters: param
12
+ api_method: :video_categories_list, parameters: param
13
13
  )
14
14
  Yourub::REST::Request.new(client, 'video_categories', 'list', param)
15
15
  end
16
16
 
17
17
  it 'execute the search list request on the client' do
18
18
  expect(client).to receive(:execute!).with(
19
- api_method: 'search.list', parameters: param
19
+ api_method: :search_list, parameters: param
20
20
  )
21
21
  Yourub::REST::Request.new(client, 'search', 'list', param)
22
22
  end
23
23
 
24
24
  it 'execute the video list request on the client' do
25
25
  expect(client).to receive(:execute!).with(
26
- api_method: 'videos.list', parameters: param
26
+ api_method: :videos_list, parameters: param
27
27
  )
28
28
  Yourub::REST::Request.new(client, 'videos', 'list', param)
29
29
  end
@@ -6,30 +6,30 @@ describe Yourub::Validator do
6
6
  context 'passing an hash containing the search criteria' do
7
7
  context 'with some valid criteria' do
8
8
  context 'with an old hash syntax' do
9
- let(:criteria) { { 'country' => 'US', 'category' => 'Sport' } }
9
+ let(:criteria) { { 'country' => 'US', 'category' => 'Sport', 'query' => 'highlights' } }
10
10
  it 'return the criteria in the sym: val format' do
11
- expect(subject).to eq(country: ['US'], category: 'Sport')
11
+ expect(subject).to eq(country: ['US'], category: 'Sport', query: 'highlights')
12
12
  end
13
13
  end
14
14
 
15
15
  context 'with valid nation but unknown parameter city' do
16
- let(:criteria) { { country: 'US', city: 'Berlin' } }
16
+ let(:criteria) { { country: 'US', city: 'Berlin', query: 'goals' } }
17
17
  it 'return criteria including nation but excluding the city' do
18
- expect(subject).to eq(country: ['US'])
18
+ expect(subject).to eq(country: ['US'], query: 'goals')
19
19
  end
20
20
  end
21
21
 
22
22
  context 'with an invalid :order value' do
23
23
  let(:criteria) { { order: 'banane', query: 'roberto baggio' } }
24
24
  it 'raise an argument error' do
25
- expect(lambda{ subject }).to raise_error(ArgumentError)
25
+ expect { subject }.to raise_error(ArgumentError)
26
26
  end
27
27
  end
28
28
 
29
29
  context 'with a given category without a country' do
30
- let(:criteria) { { country: '', category: 'Sport' } }
31
- it 'add the default country' do
32
- expect(subject).to eq(category: 'Sport', :country => ['US'])
30
+ let(:criteria) { { category: 'Sport', query: 'highlights' } }
31
+ it 'does not add a country' do
32
+ expect(subject).to eq(category: 'Sport', query: 'highlights')
33
33
  end
34
34
  end
35
35
 
@@ -39,12 +39,32 @@ describe Yourub::Validator do
39
39
  category: 'Sport',
40
40
  max_results: 2,
41
41
  count_filter: {},
42
- query: ''
42
+ query: 'goals'
43
43
  }
44
44
  end
45
45
  it 'return only them params that has a value' do
46
46
  expect(subject).to eq(
47
- country: ['IT'], category: 'Sport', max_results: 2
47
+ country: ['IT'], category: 'Sport', max_results: 2, query: 'goals'
48
+ )
49
+ end
50
+ end
51
+
52
+ context 'without a query' do
53
+ let(:criteria) { { country: 'US', category: 'Sport' } }
54
+ it 'raises explaining that q is required' do
55
+ expect { subject }.to raise_error(
56
+ ArgumentError,
57
+ 'search requires a :query parameter.'
58
+ )
59
+ end
60
+ end
61
+
62
+ context 'with a blank query' do
63
+ let(:criteria) { { query: ' ' } }
64
+ it 'raises' do
65
+ expect { subject }.to raise_error(
66
+ ArgumentError,
67
+ 'search requires a :query parameter.'
48
68
  )
49
69
  end
50
70
  end
@@ -54,21 +74,21 @@ describe Yourub::Validator do
54
74
  context 'with non valid criteria' do
55
75
  let(:criteria) { { big: 1, bang: 2 } }
56
76
  it 'raise an argument error' do
57
- expect(lambda{ subject }).to raise_error(ArgumentError)
77
+ expect { subject }.to raise_error(ArgumentError)
58
78
  end
59
79
  end
60
80
 
61
81
  context 'with criteria in the wrong format, like a string' do
62
82
  let(:criteria) { 'country = US' }
63
83
  it 'raise an argument error' do
64
- expect(lambda{ subject }).to raise_error(ArgumentError)
84
+ expect { subject }.to raise_error(ArgumentError)
65
85
  end
66
86
  end
67
87
 
68
88
  context 'with an invalid country' do
69
- let(:criteria) { { country: 'MOON' } }
89
+ let(:criteria) { { country: 'MOON', query: 'test' } }
70
90
  it 'raise an argument error' do
71
- expect(lambda{ subject }).to raise_error(ArgumentError)
91
+ expect { subject }.to raise_error(ArgumentError)
72
92
  end
73
93
  end
74
94
  end
@@ -79,7 +99,7 @@ describe Yourub::Validator do
79
99
  { max_results: 10, count_filter: { views: '>= 100' } }
80
100
  end
81
101
  it 'raise an argument error' do
82
- expect(lambda{ subject }).to raise_error(ArgumentError)
102
+ expect { subject }.to raise_error(ArgumentError)
83
103
  end
84
104
  end
85
105
  end
@@ -92,7 +112,7 @@ describe Yourub::Validator do
92
112
  context 'with an invalid category' do
93
113
  let(:selected_one) {"spaghetti"}
94
114
  it 'raise an argument error' do
95
- expect(lambda{subject}).to raise_error(ArgumentError)
115
+ expect { subject }.to raise_error(ArgumentError)
96
116
  end
97
117
  end
98
118
 
data/yourub.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Davide Prati"]
10
10
  spec.email = ["lastexxit@gmail.com "]
11
11
  spec.description = %q{Youtube API v3 parser}
12
- spec.summary = %q{Yourub is a gem that search videos on youtebe using the YouTube API v3}
12
+ spec.summary = %q{Yourub is a gem to search for videos on youtebe}
13
13
  spec.homepage = "https://github.com/edap/yourub"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'google-api-client', '~> 0.7'
22
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_runtime_dependency 'google-apis-youtube_v3', '>= 0.1', '< 2.0'
22
+ spec.add_development_dependency 'bundler', '>= 2.0'
23
23
 
24
24
  end
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yourub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davide Prati
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2026-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: google-api-client
14
+ name: google-apis-youtube_v3
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '0.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '0.7'
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '1.3'
39
+ version: '2.0'
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - "~>"
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '1.3'
46
+ version: '2.0'
41
47
  description: Youtube API v3 parser
42
48
  email:
43
49
  - 'lastexxit@gmail.com '
@@ -58,6 +64,7 @@ files:
58
64
  - lib/yourub/client.rb
59
65
  - lib/yourub/config.rb
60
66
  - lib/yourub/count_filter.rb
67
+ - lib/yourub/country_codes.rb
61
68
  - lib/yourub/default.rb
62
69
  - lib/yourub/logger.rb
63
70
  - lib/yourub/meta_search.rb
@@ -71,9 +78,7 @@ files:
71
78
  - lib/yourub/validator.rb
72
79
  - lib/yourub/version.rb
73
80
  - spec/fixtures/categories_list.json
74
- - spec/fixtures/categories_list_formatted.json
75
81
  - spec/fixtures/search_list.json
76
- - spec/fixtures/single_video.json
77
82
  - spec/fixtures/video_with_200_views.json
78
83
  - spec/fixtures/videos_list.json
79
84
  - spec/spec_helper.rb
@@ -95,7 +100,7 @@ homepage: https://github.com/edap/yourub
95
100
  licenses:
96
101
  - MIT
97
102
  metadata: {}
98
- post_install_message:
103
+ post_install_message:
99
104
  rdoc_options: []
100
105
  require_paths:
101
106
  - lib
@@ -110,16 +115,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
115
  - !ruby/object:Gem::Version
111
116
  version: '0'
112
117
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.2.0.rc.1
115
- signing_key:
118
+ rubygems_version: 3.5.3
119
+ signing_key:
116
120
  specification_version: 4
117
- summary: Yourub is a gem that search videos on youtebe using the YouTube API v3
121
+ summary: Yourub is a gem to search for videos on youtebe
118
122
  test_files:
119
123
  - spec/fixtures/categories_list.json
120
- - spec/fixtures/categories_list_formatted.json
121
124
  - spec/fixtures/search_list.json
122
- - spec/fixtures/single_video.json
123
125
  - spec/fixtures/video_with_200_views.json
124
126
  - spec/fixtures/videos_list.json
125
127
  - spec/spec_helper.rb
@@ -136,4 +138,3 @@ test_files:
136
138
  - spec/yourub/rest/request_spec.rb
137
139
  - spec/yourub/rest/videos_spec.rb
138
140
  - spec/yourub/validator_spec.rb
139
- has_rdoc:
@@ -1 +0,0 @@
1
- [{"1":"film&animation"}, {"2":"autos&vehicles"}, {"10":"music"}, {"15":"pets&animals"}, {"17":"sports"}, {"18":"shortmovies"}, {"19":"travel&events"}, {"20":"gaming"}, {"21":"videoblogging"}, {"22":"people&blogs"}, {"23":"comedy"}, {"24":"entertainment"}, {"25":"news&politics"}, {"26":"howto&style"}, {"27":"education"}, {"28":"science&technology"}, {"29":"nonprofits&activism"}, {"30":"movies"}, {"31":"anime-animation"}, {"32":"action-adventure"}, {"33":"classics"}, {"34":"comedy"}, {"35":"documentary"}, {"36":"drama"}, {"37":"family"}, {"38":"foreign"}, {"39":"horror"}, {"40":"sci-fi-fantasy"}, {"41":"thriller"}, {"42":"shorts"}, {"43":"shows"}, {"44":"trailers"}]
@@ -1 +0,0 @@
1
- [#<Google::APIClient::Schema::Youtube::V3::Video:0x3ff0d68e9aac DATA:{"id"=>"KDOLHClNTOI", "snippet"=>{"title"=>"When We Left Earth - The NASA Missions", "thumbnails"=>{"default"=>{"url"=>"https://i.ytimg.com/vi/KDOLHClNTOI/default.jpg", "width"=>120, "height"=>90}, "medium"=>{"url"=>"https://i.ytimg.com/vi/KDOLHClNTOI/mqdefault.jpg", "width"=>320, "height"=>180}, "high"=>{"url"=>"https://i.ytimg.com/vi/KDOLHClNTOI/hqdefault.jpg", "width"=>480, "height"=>360}}}, "statistics"=>{"viewCount"=>"767700"}}>]