yourub 1.0.4 → 1.0.5
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 +4 -3
- data/lib/yourub/client.rb +2 -1
- data/lib/yourub/validator.rb +20 -12
- data/lib/yourub/version.rb +1 -1
- data/spec/client_spec.rb +5 -0
- data/spec/validator_spec.rb +8 -1
- data/yourub.gemspec +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50484cd54ec618de42e1bc3159c5d38b2926f66d
|
4
|
+
data.tar.gz: 0bd8f7e973ee94ddf8a55d8be05a7165c795c519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55da616aafeb6704d14d99d7f09f545088a2b780cd9334019fb67befd0f792e83e792aeee6c9b04cc66f34ec4a0bc1598eda34e477204b87f061a1c567671681
|
7
|
+
data.tar.gz: 46516c6624186015d2f0590dc6e40f107f2a80f6fe4bd8551e4cf4843f6c15cc53567d89463eaef04d21ffae1d55ff6c7bed6f0050d5063199ae86b8d2100e66
|
data/README.md
CHANGED
@@ -43,14 +43,16 @@ If you are using rails, create a app/config/yourub.yml file as follow:
|
|
43
43
|
|
44
44
|
`:max_results` Integer, between 1 and 50
|
45
45
|
|
46
|
+
`:order` String, one of these: 'date', 'rating', 'relevance', 'title', 'videocount', 'viewcount'. The default one is `'relevance'`
|
47
|
+
|
46
48
|
It's necessary at least one of this parameters to start a search: `:country`, `:category`, `:query`, `:id`
|
47
49
|
|
48
50
|
### Examples
|
49
51
|
|
50
|
-
For example, to find videos in the category "sports" in
|
52
|
+
For example, to find the most recent videos in the category "sports" in Germany
|
51
53
|
```ruby
|
52
54
|
client = Yourub::Client.new
|
53
|
-
client.search(country: "DE", category: "sports")
|
55
|
+
client.search(country: "DE", category: "sports", order: 'date')
|
54
56
|
client.videos
|
55
57
|
```
|
56
58
|
|
@@ -88,7 +90,6 @@ It will give you much more information
|
|
88
90
|
##TODO
|
89
91
|
|
90
92
|
1. adding a CLI
|
91
|
-
2. add `:order` in the search criteria
|
92
93
|
|
93
94
|
## Contributing
|
94
95
|
|
data/lib/yourub/client.rb
CHANGED
@@ -11,7 +11,7 @@ module Yourub
|
|
11
11
|
:part => 'snippet',
|
12
12
|
:type => 'video',
|
13
13
|
:eventType => 'completed',
|
14
|
-
:order => '
|
14
|
+
:order => 'relevance',
|
15
15
|
:safeSearch => 'none',
|
16
16
|
}
|
17
17
|
end
|
@@ -140,6 +140,7 @@ module Yourub
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def search_list_request(options)
|
143
|
+
byebug
|
143
144
|
search_response = client.execute!(
|
144
145
|
:api_method => youtube.search.list,
|
145
146
|
:parameters => options
|
data/lib/yourub/validator.rb
CHANGED
@@ -2,22 +2,23 @@ module Yourub
|
|
2
2
|
module Validator
|
3
3
|
class << self
|
4
4
|
|
5
|
-
DEFAULT_COUNTRY = "US"
|
6
|
-
COUNTRIES
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
MINIMUM_PARAMS = [:country, :category, :query, :id]
|
5
|
+
DEFAULT_COUNTRY = "US"
|
6
|
+
COUNTRIES = [ 'AR','AU','AT','BE','BR','CA','CL','CO','CZ','EG','FR','DE','GB','HK',
|
7
|
+
'HU','IN','IE','IL','IT','JP','JO','MY','MX','MA','NL','NZ','PE','PH',
|
8
|
+
'PL','RU','SA','SG','ZA','KR','ES','SE','CH','TW','AE','US']
|
9
|
+
ORDERS = ['date', 'rating', 'relevance', 'title', 'videocount', 'viewcount']
|
10
|
+
VALID_PARAMS = [:country, :category, :query, :id, :max_results, :count_filter, :order]
|
11
|
+
MINIMUM_PARAMS = [:country, :category, :query, :id]
|
13
12
|
|
14
13
|
def confirm(criteria)
|
15
14
|
valid_format?(criteria)
|
16
15
|
@criteria = symbolize_keys(criteria)
|
16
|
+
|
17
17
|
remove_empty_and_non_valid_params
|
18
18
|
minimum_param_present?
|
19
19
|
|
20
20
|
keep_only_the_id_if_present
|
21
|
+
validate_order
|
21
22
|
countries_to_array
|
22
23
|
add_default_country_if_category_is_present
|
23
24
|
validate_countries
|
@@ -25,10 +26,6 @@ module Yourub
|
|
25
26
|
@criteria
|
26
27
|
end
|
27
28
|
|
28
|
-
def available_countries
|
29
|
-
COUNTRIES
|
30
|
-
end
|
31
|
-
|
32
29
|
def symbolize_keys(hash)
|
33
30
|
hash.inject({}){|result, (key, value)|
|
34
31
|
new_key = case key
|
@@ -89,6 +86,14 @@ module Yourub
|
|
89
86
|
end
|
90
87
|
end
|
91
88
|
|
89
|
+
def validate_order
|
90
|
+
if @criteria.has_key? :order
|
91
|
+
raise ArgumentError.new(
|
92
|
+
"the given order is not in the available ones: #{ORDERS.join(',')}"
|
93
|
+
) unless( ORDERS.include? @criteria[:order] )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
92
97
|
def validate_countries
|
93
98
|
if @criteria.has_key? :country
|
94
99
|
raise ArgumentError.new(
|
@@ -105,6 +110,9 @@ module Yourub
|
|
105
110
|
)
|
106
111
|
end
|
107
112
|
|
113
|
+
def available_countries
|
114
|
+
COUNTRIES
|
115
|
+
end
|
108
116
|
end
|
109
117
|
end
|
110
118
|
end
|
data/lib/yourub/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -27,6 +27,11 @@ describe Yourub::Client do
|
|
27
27
|
expect(subject.videos).to be_a_kind_of(Array)
|
28
28
|
end
|
29
29
|
|
30
|
+
it "accept an 'order' parameter within the others" do
|
31
|
+
subject.search(country: "US", category: "Sports", order: 'date')
|
32
|
+
expect(subject.videos).to be_a_kind_of(Array)
|
33
|
+
end
|
34
|
+
|
30
35
|
it "retrieves 5 videos for each given category" do
|
31
36
|
subject.search(country: "US, DE", category: "Sports", max_results: 5)
|
32
37
|
expect(subject.videos.count).to eq(10)
|
data/spec/validator_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Yourub::Validator do
|
|
8
8
|
|
9
9
|
context "no matter if the crteria has old 'key' => 'val' or key: val sintax" do
|
10
10
|
let(:criteria) { {"country" => 'US', "category" => 'Sport'} }
|
11
|
-
it "return criteria
|
11
|
+
it "return the criteria in the sym: val format" do
|
12
12
|
expect(subject).to eq({country: ['US'], category: 'Sport'})
|
13
13
|
end
|
14
14
|
end
|
@@ -20,6 +20,13 @@ describe Yourub::Validator do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
context "with an invalid :order value" do
|
24
|
+
let(:criteria) { {order: 'banane', query: 'roberto baggio'} }
|
25
|
+
it 'raise an argument error' do
|
26
|
+
expect(lambda{subject}).to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
context "with a given category without a country" do
|
24
31
|
let(:criteria) { {country: '', category: 'Sport'} }
|
25
32
|
it "add the default country" do
|
data/yourub.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["lastexxit@gmail.com "]
|
11
11
|
spec.description = %q{Youtube API v3 parser}
|
12
12
|
spec.summary = %q{Yourub is a gem that search videos on youtebe using the YouTube API v3}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/edap/yourub"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.1"
|
25
25
|
spec.add_development_dependency "rspec", "~> 2.14"
|
26
|
+
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yourub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Prati
|
@@ -111,7 +111,7 @@ files:
|
|
111
111
|
- spec/validator_spec.rb
|
112
112
|
- yourub.gemspec
|
113
113
|
- yourub.sublime-project
|
114
|
-
homepage:
|
114
|
+
homepage: https://github.com/edap/yourub
|
115
115
|
licenses:
|
116
116
|
- MIT
|
117
117
|
metadata: {}
|