Skip to content

Commit

Permalink
ready for a first release
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Sep 29, 2008
1 parent 4badb2e commit 046afc2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 14 deletions.
12 changes: 12 additions & 0 deletions README
Expand Up @@ -4,11 +4,23 @@ dm-gvideo-adapter
# dependencies # dependencies
Gvideo: http://github.com/mattetti/gvideo Gvideo: http://github.com/mattetti/gvideo


install the dependency:

$ sudo gem install mattetti-gvideo

install this adapter

$ sudo gem install mattetti-dm-gvideo-adapter


Usage: Usage:


# URI: # URI:
googlevideo://A005148908335059515423 # google video user id googlevideo://A005148908335059515423 # google video user id


(or you can set the user_id in your database.yml)


Video.all # returns all the user's videos Video.all # returns all the user's videos
Video.get("-2838281997424715962") Video.get("-2838281997424715962")
Video.first(:title => "The Illuminati - Secret societies") Video.first(:title => "The Illuminati - Secret societies")
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -4,7 +4,7 @@ require 'rubygems/specification'
require 'date' require 'date'


GEM = "dm-gvideo-adapter" GEM = "dm-gvideo-adapter"
GEM_VERSION = "0.0.1" GEM_VERSION = "1.0.0"
AUTHOR = "Matt Aimonetti" AUTHOR = "Matt Aimonetti"
EMAIL = "mattaimonetti@gmail.com" EMAIL = "mattaimonetti@gmail.com"
HOMEPAGE = "http://merbist.com" HOMEPAGE = "http://merbist.com"
Expand All @@ -23,7 +23,7 @@ spec = Gem::Specification.new do |s|
s.homepage = HOMEPAGE s.homepage = HOMEPAGE


# Uncomment this to add a dependency # Uncomment this to add a dependency
# s.add_dependency "foo" # s.add_dependency "gvideo"


s.require_path = 'lib' s.require_path = 'lib'
s.autorequire = GEM s.autorequire = GEM
Expand Down
28 changes: 28 additions & 0 deletions dm-gvideo-adapter.gemspec
@@ -0,0 +1,28 @@
Gem::Specification.new do |s|
s.name = %q{dm-gvideo-adapter}
s.version = "1.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Matt Aimonetti"]
s.autorequire = %q{dm-gvideo-adapter}
s.date = %q{2008-09-28}
s.description = %q{A gem that provides...}
s.email = %q{mattaimonetti@gmail.com}
s.extra_rdoc_files = ["README", "LICENSE", "TODO"]
s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/dm-gvideo-adapter.rb", "lib/gvideo_model.rb"]
s.has_rdoc = true
s.homepage = %q{http://merbist.com}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.2.0}
s.summary = %q{A gem that provides...}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2

if current_version >= 3 then
else
end
else
end
end
2 changes: 1 addition & 1 deletion lib/dm-gvideo-adapter.rb
Expand Up @@ -55,7 +55,7 @@ def read(query, set, arr = true)
end end


# This is the core logic that handles the difference between all/first # This is the core logic that handles the difference between all/first
(results || []).each do |result| results.each do |result|
props = props_from_result(properties_with_indexes, result, repository) props = props_from_result(properties_with_indexes, result, repository)
arr ? set.load(props) : (break set.load(props, query)) arr ? set.load(props) : (break set.load(props, query))
end end
Expand Down
32 changes: 21 additions & 11 deletions spec/dm-gvideo-adapter_spec.rb
Expand Up @@ -32,53 +32,63 @@
@videos.length.should == @gvideos.length @videos.length.should == @gvideos.length
end end


it "should be able to retrieve itams using a title (string) condition" do it "should be able to retrieve items using a title (string) condition" do
videos = @videos.all(:title => "Durex: The Garden") videos = Video.all(:title => "Durex: The Garden")
videos.length.should == 1 videos.length.should == 1
videos.first.title.should == "Durex: The Garden" videos.first.title.should == "Durex: The Garden"
end end


it "should be able to retrieve items using a title (regexp) condition" do it "should be able to retrieve items using a title (regexp) condition" do
videos = @videos.all(:title.like => "The Garden") videos = Video.all(:title.like => "The Garden")
videos.length.should == 1 videos.length.should == 1
videos.first.title.should == "Durex: The Garden" videos.first.title.should == "Durex: The Garden"
end end


it "should be able to retrieve items using a duration (integer) condition (seconds)" do it "should be able to retrieve items using a duration (integer) condition (seconds)" do
videos = @videos.all(:duration => 12) videos = Video.all(:duration => 12)
videos.length.should == 2 videos.length.should == 2
end end


it "should be able to retrieve items using a duration condition :gte " do it "should be able to retrieve items using a duration condition :gte " do
videos = @videos.all(:duration.gte => 13) videos = Video.all(:duration.gte => 13)
videos.length.should < @gvideos.length videos.length.should < @gvideos.length
end end


it "should be able to retrieve items using a duration condition :lte " do it "should be able to retrieve items using a duration condition :lte " do
videos = @videos.all(:duration.lte => 12) videos = Video.all(:duration.lte => 12)
videos.length.should < @gvideos.length videos.length.should < @gvideos.length
(@videos.all(:duration.gte => 13).length + @videos.all(:duration.lte => 12).length).should == @gvideos.length (@videos.all(:duration.gte => 13).length + @videos.all(:duration.lte => 12).length).should == @gvideos.length
end end


it "should be able to use 2 duration conditions" do it "should be able to use 2 duration conditions" do
videos = @videos.all(:duration.lte => 12, :duration.gte => 12) videos = Video.all(:duration.lte => 12, :duration.gte => 12)
videos.length.should == @videos.all(:duration => 12).length videos.length.should == @videos.all(:duration => 12).length
end end


end end


describe "getting one resource" do describe "getting one resource" do
before(:all) do
@video = Video.first
end


it "should have all the attributes of a video" do it "should have all the attributes of a video" do
video = Video.first
methods = %W{docid title video_url duration duration_in_minutes thumbnail_url embed_player} methods = %W{docid title video_url duration duration_in_minutes thumbnail_url embed_player}
methods.each do |meth| methods.each do |meth|
@video.send(meth.to_sym).should_not be_nil video.send(meth.to_sym).should_not be_nil
end end
end end


it "should be able to retrieve an item using a title (string) condition" do
video = Video.first(:title => "Durex: The Garden")
video.should be_an_instance_of(Video)
video.title.should == "Durex: The Garden"
end

it "should be able to retrieve items using a title (regexp) condition" do
video = Video.first(:title.like => "The Garden")
video.should be_an_instance_of(Video)
video.title.should == "Durex: The Garden"
end

end end




Expand Down
35 changes: 35 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -19,5 +19,40 @@ class Video
property :thumbnail_url, String property :thumbnail_url, String
property :embed_player, String property :embed_player, String


##
# Simulates Array#first by returning the first entry (when
# there are no arguments), or transforms the collection's query
# by applying :limit => n when you supply an Integer. If you
# provide a conditions hash, or a Query object, the internal
# query is scoped and a new collection is returned
#
# @param [Integer, Hash[Symbol, Object], Query] args
#
# @return [DataMapper::Resource, DataMapper::Collection] The
# first resource in the entries of this collection, or
# a new collection whose query has been merged
#
# @api public
def first(*args)

# # TODO: this shouldn't be a kicker if scoped_query() is called
# if loaded?
# if args.empty?
# return super
# elsif args.size == 1 && args.first.kind_of?(Integer)
# limit = args.shift
# return self.class.new(scoped_query(:limit => limit)) { |c| c.replace(super(limit)) }
# end
# end
#
# query = args.last.respond_to?(:merge) ? args.pop : {}
# query = scoped_query(query.merge(:limit => args.first || 1))
#
# if args.any?
# query.repository.read_many(query)
# else
# query.repository.read_one(query)
# end
end


end end

0 comments on commit 046afc2

Please sign in to comment.