yourub 1.0.7 → 1.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 494ed6a9104fae3170ddc50558721f98bc42f36f
4
- data.tar.gz: b2c160e3bf7410d175328205b2550e69e20001f3
3
+ metadata.gz: b2aa1059c797a786fea83046d74f8bd6751f954d
4
+ data.tar.gz: 7906cfcc12e3fd7e7cd82c2290f00a855c3ef8cd
5
5
  SHA512:
6
- metadata.gz: 4353aefef6f549703e09bbef10387008993e3844d744528005201239e117d5f01048c7f7bdd5b343e36b5527631091df35ba9ac16b0ed3f8437199259c8d3a91
7
- data.tar.gz: 9473dddeb12fef8f2a3d100ebd6b4dadf3fbec1c72d1db2ba5fe090fe88acbf2843d408739f29c771b91bb462b5cf38d404818b0ec7a57dab6640396ec919f82
6
+ metadata.gz: 3cb8c2d1c2c2ebce6e81bd0d8bcf832f0ac7365d3543e445bd3ced8c2e5049a24840e03d83684bd47725a466d277df596cd4b635c752ad1eb0747d85b5ef3f58
7
+ data.tar.gz: 4533693deb7dd813670d8ec362f44e66e985f41c6233c58798b2d14b977194f9ae59112ce0b67ef9984f0305c541c67c1713346eb01bc854694882df1112e42a
data/README.md CHANGED
@@ -49,7 +49,7 @@ test:
49
49
 
50
50
  `:category` String, example `comedy`
51
51
 
52
- `:count_filters` Hash, example `{views: ">= 100"}` or `{views: "== 600"}`
52
+ `:count_filter` Hash, example `{views: ">= 100"}` or `{views: "== 600"}`
53
53
 
54
54
  `:max_results` Integer, between 1 and 50
55
55
 
data/config/yourub.yml CHANGED
@@ -13,4 +13,4 @@ production:
13
13
  <<: *yourub_defaults
14
14
 
15
15
  test:
16
- <<: *yourub_defaults
16
+ <<: *yourub_defaults
data/lib/yourub/client.rb CHANGED
@@ -7,6 +7,7 @@ module Yourub
7
7
  def initialize()
8
8
  @extended_info = false
9
9
  @categories, @videos = [], []
10
+ @count_filter = {}
10
11
  @api_options= {
11
12
  :part => 'snippet',
12
13
  :type => 'video',
@@ -97,7 +98,7 @@ module Yourub
97
98
  def retrieve_videos
98
99
  consume_criteria do |criteria|
99
100
  req = search_list_request(criteria)
100
- if @extended_info || @criteria[:count_filter]
101
+ if @extended_info || Yourub::CountFilter.filter
101
102
  get_details_and_store req
102
103
  else
103
104
  videos = Yourub::Reader.parse_videos(req)
@@ -175,7 +176,7 @@ module Yourub
175
176
 
176
177
  def add_video_to_search_result(entry)
177
178
  video = @extended_info ? entry : Yourub::Reader.parse_entry(entry)
178
- if Yourub::CountFilter.accept?(entry, @criteria[:count_filter])
179
+ if Yourub::CountFilter.accept?(entry)
179
180
  @videos.push(video)
180
181
  end
181
182
  end
@@ -7,8 +7,7 @@ module Yourub
7
7
  VIEWS_COUNT_NUMBER = /\d*\z/
8
8
  ARITHMETIC_OPERATOR = /\A<(?!=)|>(?!=)|<=|>=|==|!=/
9
9
 
10
- def accept?(entry, filter)
11
- @filter = filter
10
+ def accept?(entry)
12
11
  return true if @filter.nil?
13
12
  validate_filter
14
13
  apply_filter(entry)
@@ -22,6 +22,7 @@ module Yourub
22
22
  countries_to_array
23
23
  add_default_country_if_category_is_present
24
24
  validate_countries
25
+ set_filter_count_options
25
26
 
26
27
  @criteria
27
28
  end
@@ -66,7 +67,14 @@ module Yourub
66
67
  end
67
68
  end
68
69
 
70
+ def set_filter_count_options
71
+ if @criteria.has_key? :count_filter
72
+ Yourub::CountFilter.filter = @criteria.delete(:count_filter)
73
+ end
74
+ end
75
+
69
76
  def valid_category(categories, selected_category)
77
+ #if selected_category == 'all' return categories
70
78
  categories = categories.select {|k| k.has_value?(selected_category.downcase)}
71
79
  if categories.first.nil?
72
80
  raise ArgumentError.new(
@@ -109,7 +117,7 @@ module Yourub
109
117
  raise ArgumentError.new(
110
118
  'max 50 videos pro categories or country'
111
119
  ) unless(
112
- @criteria[:max_results].to_i < 50 || @criteria[:max_results].to_i == 0
120
+ @criteria[:max_results].to_i < 51 || @criteria[:max_results].to_i == 0
113
121
  )
114
122
  end
115
123
 
@@ -1,6 +1,6 @@
1
1
  module Yourub
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- PATCH = 7
4
+ PATCH = 8
5
5
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
6
6
  end
@@ -16,22 +16,21 @@ describe Yourub::CountFilter do
16
16
  }
17
17
  }
18
18
 
19
+ let(:subject) { Yourub::CountFilter.accept?(video) }
20
+
19
21
  it "accept the video if satisfy the condition" do
20
- filter = {views: ">= 100"}
21
- res = Yourub::CountFilter.accept?(video, filter)
22
- expect(res).to be_true
22
+ Yourub::CountFilter.filter = {views: ">= 100"}
23
+ expect(subject).to be_true
23
24
  end
24
25
 
25
26
  it "accept the video if filter is nil" do
26
- filter = nil
27
- res = Yourub::CountFilter.accept?(video, filter)
28
- expect(res).to be_true
27
+ Yourub::CountFilter.filter = nil
28
+ expect(subject).to be_true
29
29
  end
30
30
 
31
31
  it "not accept the video if it does not satisfy the condition" do
32
- filter = {views: "<= 100"}
33
- res = Yourub::CountFilter.accept?(video, filter)
34
- expect(res).to be_false
32
+ Yourub::CountFilter.filter = {views: "<= 100"}
33
+ expect(subject).to be_false
35
34
  end
36
35
 
37
36
  end
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.0.7
4
+ version: 1.0.8
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-05-25 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client