Skip to content

Commit

Permalink
New .where method to filter account.videos list
Browse files Browse the repository at this point in the history
For instance, it is now possible to call

    account.videos.where(q: 'query')

to only return the videos owned by account with 'query'
in the title or description.
  • Loading branch information
claudiob committed Jun 11, 2014
1 parent 68075f9 commit 269a0c8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -22,3 +22,4 @@ env:
- secure: Ejj8tsuwyrRVmCc/R9ubKWCHWhCGpe0Dy6fc1UuPCkcMZyXq9ZC02v2obWsTQQ7epEgsCYZAO4v/gWpuv1b1huGcWdfJzMW7RCoY87cEf9HnAK0lSwGx4+/pYkEMe8y5p149C3vAR8nqczvEavN1fUq/WwPUqp+JyDP7kwFTs2Y=
- secure: gE5kAT1R54hmS+W3YYGcUtlD8ZskvTctVR3sr+C5CUjVPdq6Ktx5Q/a6EJyAVVrhxpaCOuk3LG+VkzdQIVFUNRiDPcOulkond4HkSQDoy+IJ/wTXvUS+lIJ1ERUnWega+APrQUjH5s2WayPGZUBqWt/u8Tt9EmSUZfuKZSEXqZk=
- secure: ZUx5v/wHW/TENg8NfFINiiMoe2D031ntDTiuIBdf88c/bMClkEtRRgomtK9RBkFonEyGEOkXxUm2SLzRf340V3eIXWQhil7ab1lcYs8X59aVS/NK/GqChH8Nia17gc3OTQ9k6rYvj4Lp60Dh9WG1cijLPd4/OvPmf6qX9uYfJMw=
- secure: DumQVO01Y3Ki1skuOYOZzosDb6jS0XyG1O8Agy3mVxXGJzQE+s1z2UFz4gMpsU9o/gmiNMddp7I6+RtbZjo9hN3H7vlRRwEeB7tuUMiDyomSx1FlHcCFfPdTmhxGg8X78SErMWqNC6eReGrCTgBdIq1ho7dIu53qJNxTEFqx7eI=
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
yt (0.6.1)
yt (0.6.2)
activesupport

GEM
Expand Down
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -4,6 +4,7 @@ v0.6 - 2014/06/05
* [breaking change] Rename Channel#earning to Channel#earnings_on
* [breaking change] Account#videos shows *all* videos owned by account (public and private)
* Add the .status association to *every* type of resource (Channel, Video, Playlist)
* Allow account.videos to be chained with .where, such as in account.videos.where(q: 'query')

v0.5 - 2014/05/16
-----------------
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -330,7 +330,7 @@ To install on your system, run

To use inside a bundled Ruby project, add this line to the Gemfile:

gem 'yt', '~> 0.6.1'
gem 'yt', '~> 0.6.2'

Since the gem follows [Semantic Versioning](http://semver.org),
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
Expand Down
6 changes: 6 additions & 0 deletions lib/yt/collections/base.rb
Expand Up @@ -18,6 +18,12 @@ def initialize(options = {})
def self.of(parent)
new parent: parent, auth: parent.auth
end

def where(conditions = {})
@items = []
@extra_params = conditions
self
end
end
end
end
7 changes: 6 additions & 1 deletion lib/yt/collections/videos.rb
Expand Up @@ -13,10 +13,15 @@ def new_item(data)

def list_params
super.tap do |params|
params[:params] = @parent.videos_params.merge type: :video, maxResults: 50, part: 'snippet'
params[:params] = @parent.videos_params.merge videos_params
params[:path] = '/youtube/v3/search'
end
end

def videos_params
@extra_params ||= {}
{type: :video, maxResults: 50, part: 'snippet'}.merge @extra_params
end
end
end
end
2 changes: 1 addition & 1 deletion lib/yt/version.rb
@@ -1,3 +1,3 @@
module Yt
VERSION = '0.6.1'
VERSION = '0.6.2'
end
14 changes: 14 additions & 0 deletions spec/associations/device_auth/account_spec.rb
Expand Up @@ -13,5 +13,19 @@
describe '.videos' do
it { expect($account.videos).to be_a Yt::Collections::Videos }
it { expect($account.videos.first).to be_a Yt::Video }

describe '.where(q: query_string)' do
let(:count) { $account.videos.where(q: query).count }

context 'given a query string that matches any video owned by the account' do
let(:query) { ENV['YT_TEST_MATCHING_QUERY_STRING'] }
it { expect(count).to be > 0 }
end

context 'given a query string that does not match any video owned by the account' do
let(:query) { '--not-a-matching-query-string--' }
it { expect(count).to be_zero }
end
end
end
end

0 comments on commit 269a0c8

Please sign in to comment.