howcast 0.4.3 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,4 +11,44 @@ describe Howcast::Client, "initialize" do
11
11
  Howcast::Client.new
12
12
  }.should raise_error(Howcast::ApiKeyNotFound)
13
13
  end
14
- end
14
+ end
15
+
16
+ describe Howcast::Client, "base_uri" do
17
+ after :each do
18
+ Howcast::Client.instance_variable_set :@base_uri, nil
19
+ end
20
+
21
+ it "should use a default base_uri of www.howcast.com" do
22
+ Howcast::Client.base_uri.to_s.should == "http://www.howcast.com"
23
+ end
24
+
25
+ it "should allow easily setting the base_url" do
26
+ lambda do
27
+ Howcast::Client.base_uri = URI.parse("http://example.com")
28
+ end.should change{Howcast::Client.base_uri.to_s}.to("http://example.com")
29
+ end
30
+
31
+ it "should be easy to set the base_uri with a URI object" do
32
+ Howcast::Client.base_uri = URI::HTTP.new 'http', nil, 'example.com', nil, nil, nil, nil, nil, nil
33
+ Howcast::Client.base_uri.should be_kind_of(URI)
34
+ Howcast::Client.base_uri.host.should == "example.com"
35
+ end
36
+
37
+ it "should be easy to set the base_uri with a string" do
38
+ Howcast::Client.base_uri = "http://example.com"
39
+ Howcast::Client.base_uri.should be_kind_of(URI)
40
+ Howcast::Client.base_uri.host.should == "example.com"
41
+ end
42
+
43
+ it "should be easy to set the base_uri with a hash" do
44
+ Howcast::Client.base_uri = {:scheme => 'http', :host => 'example.com'}
45
+ Howcast::Client.base_uri.should be_kind_of(URI)
46
+ Howcast::Client.base_uri.host.should == "example.com"
47
+ end
48
+
49
+ it "should raise an error when trying to set the base_uri to something weird" do
50
+ lambda do
51
+ Howcast::Client.base_uri = nil
52
+ end.should raise_error(ArgumentError)
53
+ end
54
+ end
@@ -20,7 +20,7 @@ describe Howcast::Client, "category" do
20
20
  end
21
21
 
22
22
  it "should establish a connection with the correct category url" do
23
- @hc.should_receive(:open).with("http://www.howcast.com/categories/2.xml?api_key=myapikey").and_return(category_xml)
23
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/categories/2.xml?api_key=myapikey")).and_return(category_xml)
24
24
  @hc.category(2)
25
25
  end
26
26
 
@@ -42,4 +42,4 @@ describe Howcast::Client, "category" do
42
42
  it "should set the parents metadata hash" do
43
43
  @hc.category(2).parents.should == [{:id => "1571", :name => "Travel"}, {:id => "1584", :name => "African Travel"}]
44
44
  end
45
- end
45
+ end
@@ -1,88 +1,85 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe Howcast::Client, "video_search" do
4
- before do
5
- @hc = Howcast::Client.new(:key => "myapikey")
6
- end
7
-
8
- it "should establish a connection with search.xml?q=something&view=video when query is 'something'" do
9
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something&view=video&api_key=myapikey").and_return(videos_xml)
10
- @hc.video_search("something")
11
- end
12
-
13
- it "should establish a connection with search.xml?q=something&view=video&page=2 when query is 'something' and :page => 2" do
14
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something&view=video&page=2&api_key=myapikey").and_return(videos_xml)
15
- @hc.video_search("something", :page => 2)
16
- end
17
-
18
- it "should escape the query when esablishing the connection" do
19
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something+%26+something&view=video&api_key=myapikey").and_return(videos_xml)
20
- @hc.video_search("something & something")
21
- end
22
-
23
- it "should append mode=extended when passed in as an option" do
24
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something&view=video&mode=extended&api_key=myapikey").and_return(videos_xml)
25
- @hc.video_search("something", :mode => :extended)
26
- end
27
-
3
+ shared_examples_for "a search method" do
28
4
  it "should raise a Howcast::ApiNotFound if url is invalid" do
29
5
  lambda {
30
6
  @hc.should_receive(:open).and_raise(URI::InvalidURIError)
31
- @hc.video_search("something")
7
+ do_search
32
8
  }.should raise_error(Howcast::ApiNotFound)
33
9
  end
34
-
10
+
35
11
  it "should return an empty array if there are no results" do
36
12
  @hc.should_receive(:open).and_return(blank_videos_xml)
37
- @hc.video_search("something").should be_empty
13
+ do_search.should be_empty
38
14
  end
39
-
15
+
40
16
  it "should return an array of video objects if there are some returned" do
41
17
  @hc.should_receive(:open).and_return(videos_xml)
42
- videos = @hc.video_search("something")
18
+ videos = do_search
43
19
  videos.size.should == 3
44
20
  videos.first.permalink.should == "http://www.howcast.com/videos/1101-How-To-Pretend-Youre-a-Real-New-Yorker"
45
21
  videos.last.permalink.should == "http://www.howcast.com/videos/866-How-To-Make-a-Water-Gun-Alarm-Clock"
46
22
  end
47
23
  end
48
24
 
49
- describe Howcast::Client, "guide_search" do
25
+ describe Howcast::Client, "search" do
50
26
  before do
51
27
  @hc = Howcast::Client.new(:key => "myapikey")
28
+ @method = :search
52
29
  end
53
-
54
- it "should establish a connection with search.xml?q=something&view=guide when query is 'something'" do
55
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something&view=guide&api_key=myapikey").and_return(guides_xml)
56
- @hc.guide_search("something")
30
+
31
+ def do_search
32
+ @hc.search "something"
33
+ end
34
+
35
+ it_should_behave_like "a search method"
36
+
37
+ it "should establish a connection with search.xml?q=something&view=videos when query is 'something'" do
38
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/search.xml?q=something&view=videos&api_key=myapikey")).and_return(videos_xml)
39
+ @hc.search("something")
57
40
  end
58
-
59
- it "should establish a connection with search.xml?q=something&view=guide&page=2 when query is 'something' and :page => 2" do
60
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something&view=guide&page=2&api_key=myapikey").and_return(guides_xml)
61
- @hc.guide_search("something", :page => 2)
41
+
42
+ it "should establish a connection with search.xml?q=something&view=videos&page=2 when query is 'something' and :page => 2" do
43
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/search.xml?q=something&view=videos&page=2&api_key=myapikey")).and_return(videos_xml)
44
+ @hc.search("something", :page => 2)
62
45
  end
63
-
46
+
64
47
  it "should escape the query when esablishing the connection" do
65
- @hc.should_receive(:open).with("http://www.howcast.com/search.xml?q=something+%26+something&view=guide&api_key=myapikey").and_return(guides_xml)
66
- @hc.guide_search("something & something")
48
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/search.xml?q=something+%26+something&view=videos&api_key=myapikey")).and_return(videos_xml)
49
+ @hc.search("something & something")
67
50
  end
68
-
69
- it "should raise a Howcast::ApiNotFound if url is invalid" do
70
- lambda {
71
- @hc.should_receive(:open).and_raise(URI::InvalidURIError)
72
- @hc.guide_search("something")
73
- }.should raise_error(Howcast::ApiNotFound)
51
+
52
+ it "should append mode=extended when passed in as an option" do
53
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/search.xml?q=something&mode=extended&view=videos&api_key=myapikey")).and_return(videos_xml)
54
+ @hc.search("something", :mode => :extended)
74
55
  end
75
-
76
- it "should return an empty array if there are no results" do
77
- @hc.should_receive(:open).and_return(blank_guides_xml)
78
- @hc.guide_search("something").should be_empty
56
+
57
+ end
58
+
59
+ describe Howcast::Client, "advanced_search" do
60
+ before do
61
+ @hc = Howcast::Client.new(:key => "myapikey")
79
62
  end
80
-
81
- it "should return an array of video objects if there are some returned" do
82
- @hc.should_receive(:open).and_return(videos_xml)
83
- videos = @hc.video_search("something")
84
- videos.size.should == 3
85
- videos.first.permalink.should == "http://www.howcast.com/videos/1101-How-To-Pretend-Youre-a-Real-New-Yorker"
86
- videos.last.permalink.should == "http://www.howcast.com/videos/866-How-To-Make-a-Water-Gun-Alarm-Clock"
63
+
64
+ def do_search
65
+ @hc.advanced_search :q => "something"
66
+ end
67
+
68
+ it_should_behave_like "a search method"
69
+
70
+ it "should establish a connection to the search path on howcast.com" do
71
+ @hc.should_receive(:open).with(to_s_like(%r{^http://www.howcast.com/search.xml})).and_return(videos_xml)
72
+ @hc.advanced_search({})
87
73
  end
88
- end
74
+
75
+ it "should url-encode any passed params" do
76
+ @hc.should_receive(:open).with(to_s_like(%r{q=something})).and_return(videos_xml)
77
+ @hc.advanced_search :q => "something"
78
+ end
79
+
80
+ it "should not create default params" do
81
+ @hc.should_receive(:open).with(to_s_like(%r{mode=foo})).and_return(videos_xml)
82
+ @hc.should_not_receive(:open).with(to_s_like(%r{view=}))
83
+ @hc.advanced_search :mode => "foo"
84
+ end
85
+ end
@@ -20,7 +20,7 @@ describe Howcast::Client, "video" do
20
20
  end
21
21
 
22
22
  it "should establish a connection with the correct video url" do
23
- @hc.should_receive(:open).with("http://www.howcast.com/videos/2.xml?api_key=myapikey").and_return(video_xml)
23
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/2.xml?api_key=myapikey")).and_return(video_xml)
24
24
  @hc.video(2)
25
25
  end
26
26
 
@@ -75,27 +75,27 @@ describe Howcast::Client, "videos" do
75
75
  end
76
76
 
77
77
  it "should establish a connection with videos/most_recent/howcast_studios.xml by default" do
78
- @hc.should_receive(:open).with("http://www.howcast.com/videos/most_recent/howcast_studios.xml?api_key=myapikey").and_return(videos_xml)
78
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/most_recent/howcast_studios.xml?api_key=myapikey")).and_return(videos_xml)
79
79
  @hc.videos
80
80
  end
81
81
 
82
82
  it "should establish a connection with videos/most_recent/howcast_studios/2.xml when :page => 2" do
83
- @hc.should_receive(:open).with("http://www.howcast.com/videos/most_recent/howcast_studios/2.xml?api_key=myapikey").and_return(videos_xml)
83
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/most_recent/howcast_studios/2.xml?api_key=myapikey")).and_return(videos_xml)
84
84
  @hc.videos(:page => 2)
85
85
  end
86
86
 
87
87
  it "should establish a connection with videos/most_viewed/howcast_studios.xml when :sort => most_viewed" do
88
- @hc.should_receive(:open).with("http://www.howcast.com/videos/most_viewed/howcast_studios.xml?api_key=myapikey").and_return(videos_xml)
88
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/most_viewed/howcast_studios.xml?api_key=myapikey")).and_return(videos_xml)
89
89
  @hc.videos(:sort => "most_viewed")
90
90
  end
91
91
 
92
92
  it "should establish a connection with videos/most_viewed/directors_program.xml when :sort => most_viewed and :filter => directors_program" do
93
- @hc.should_receive(:open).with("http://www.howcast.com/videos/most_viewed/directors_program.xml?api_key=myapikey").and_return(videos_xml)
93
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/most_viewed/directors_program.xml?api_key=myapikey")).and_return(videos_xml)
94
94
  @hc.videos(:sort => "most_viewed", :filter => "directors_program")
95
95
  end
96
96
 
97
97
  it "should establish a connection with videos/top_rated/directors_program.xml when :sort => most_viewed and :filter => directors_program" do
98
- @hc.should_receive(:open).with("http://www.howcast.com/videos/top_rated/directors_program.xml?api_key=myapikey").and_return(videos_xml)
98
+ @hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/videos/top_rated/directors_program.xml?api_key=myapikey")).and_return(videos_xml)
99
99
  @hc.videos(:sort => "top_rated", :filter => "directors_program")
100
100
  end
101
101
 
@@ -118,4 +118,4 @@ describe Howcast::Client, "videos" do
118
118
  videos.first.permalink.should == "http://www.howcast.com/videos/1101-How-To-Pretend-Youre-a-Real-New-Yorker"
119
119
  videos.last.permalink.should == "http://www.howcast.com/videos/866-How-To-Make-a-Water-Gun-Alarm-Clock"
120
120
  end
121
- end
121
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,28 @@ end
8
8
 
9
9
  require File.expand_path(File.dirname(__FILE__) + "/../lib/howcast")
10
10
 
11
+
12
+ def to_s_like like
13
+ simple_matcher("converts to a string like #{like.inspect}") do |candidate|
14
+ like === candidate.to_s
15
+ end
16
+ end
17
+
18
+ def equivalent_uri string
19
+ simple_matcher("is an equivalent uri to #{string.inspect}") do |candidate|
20
+ verifier = URI.parse string
21
+ tests = [
22
+ lambda{|x|x.scheme},
23
+ lambda{|x|x.userinfo},
24
+ lambda{|x|x.port},
25
+ lambda{|x|x.path},
26
+ lambda{|x|x.query.split('&').sort},
27
+ lambda{|x|x.fragment}
28
+ ]
29
+ tests.all?{|t|t.call(candidate) == t.call(verifier)}
30
+ end
31
+ end
32
+
11
33
  Spec::Runner.configure do |config|
12
34
  def invalid_api_key_xml
13
35
  <<-INVALID
@@ -204,4 +226,4 @@ Spec::Runner.configure do |config|
204
226
  </howcast>
205
227
  VID
206
228
  end
207
- end
229
+ end
data/tasks/github.rake ADDED
@@ -0,0 +1,3 @@
1
+ task :build_for_github => [:manifest, :build_gemspec] do
2
+ p `ruby script/github-test.rb howcast.gemspec`
3
+ end
metadata CHANGED
@@ -1,92 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howcast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Murray
7
+ - Jingshen Jimmy Zhang
8
+ - Ian Smith-Heisters
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-03-02 00:00:00 -08:00
13
+ date: 2010-01-04 00:00:00 -08:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
- name: why-hpricot
17
+ name: hpricot
17
18
  type: :runtime
18
19
  version_requirement:
19
20
  version_requirements: !ruby/object:Gem::Requirement
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
- version: "0.6"
24
+ version: "0"
24
25
  version:
25
26
  - !ruby/object:Gem::Dependency
26
- name: hoe
27
+ name: rspec
27
28
  type: :development
28
29
  version_requirement:
29
30
  version_requirements: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 1.8.2
34
+ version: "0"
34
35
  version:
35
- description: Howcast API Ruby Wrapper
36
- email:
37
- - michael+gem@howcast.com
36
+ description: " Howcast offers an Application Programming Interface (API) which allows\n developers to build applications that interface with Howcast. The Howcast\n API is RESTful (REpresentational State Transfer) and users of this API will\n be able: 1) Retreive detailed information about a single video, including\n metadata such as title, description, video views, rating etc; 2) Retrieve a\n list of videos restricted by a set of filters offered by Howcast and sorted\n using several metrics that you can specify (most recent, most views, etc);\n 3) Search for video; 4) And much more. Note: Before you can use our APIs,\n you must register an API key, that is submitted with each request.\n"
37
+ email: support@howcast.com
38
38
  executables: []
39
39
 
40
40
  extensions: []
41
41
 
42
42
  extra_rdoc_files:
43
- - History.txt
44
- - License.txt
45
- - Manifest.txt
46
- - website/index.txt
43
+ - README.markdown
47
44
  files:
48
- - History.txt
45
+ - CHANGELOG
49
46
  - License.txt
50
- - Manifest.txt
47
+ - Manifest
51
48
  - README.markdown
52
49
  - Rakefile
53
- - config/hoe.rb
54
- - config/requirements.rb
50
+ - VERSION
51
+ - howcast.gemspec
55
52
  - lib/howcast.rb
56
53
  - lib/howcast/client.rb
57
- - lib/howcast/version.rb
58
- - lib/howcast/errors.rb
59
54
  - lib/howcast/client/base.rb
60
- - lib/howcast/client/video.rb
61
- - lib/howcast/client/guide.rb
62
- - lib/howcast/client/search.rb
63
55
  - lib/howcast/client/category.rb
64
- - script/destroy
65
- - script/generate
66
- - script/txt2html
67
- - setup.rb
68
- - spec/spec.opts
69
- - spec/spec_helper.rb
56
+ - lib/howcast/client/search.rb
57
+ - lib/howcast/client/video.rb
58
+ - lib/howcast/errors.rb
70
59
  - spec/howcast/client/base_spec.rb
71
- - spec/howcast/client/guide_spec.rb
72
- - spec/howcast/client/video_spec.rb
73
- - spec/howcast/client/search_spec.rb
74
60
  - spec/howcast/client/category_spec.rb
75
- - tasks/deployment.rake
76
- - tasks/environment.rake
77
- - tasks/rspec.rake
78
- - tasks/website.rake
79
- - website/index.html
80
- - website/index.txt
81
- - website/javascripts/rounded_corners_lite.inc.js
82
- - website/stylesheets/screen.css
83
- - website/template.rhtml
61
+ - spec/howcast/client/search_spec.rb
62
+ - spec/howcast/client/video_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ - tasks/github.rake
84
66
  has_rdoc: true
85
- homepage: http://howcast.rubyforge.org
67
+ homepage: http://github.com/howcast/howcast-gem
68
+ licenses: []
69
+
86
70
  post_install_message:
87
71
  rdoc_options:
88
- - --main
89
- - README.txt
72
+ - --charset=UTF-8
90
73
  require_paths:
91
74
  - lib
92
75
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -103,10 +86,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
86
  version:
104
87
  requirements: []
105
88
 
106
- rubyforge_project: howcast
107
- rubygems_version: 1.3.1
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
108
91
  signing_key:
109
- specification_version: 2
92
+ specification_version: 3
110
93
  summary: Howcast API Ruby Wrapper
111
- test_files: []
112
-
94
+ test_files:
95
+ - spec/howcast/client/base_spec.rb
96
+ - spec/howcast/client/category_spec.rb
97
+ - spec/howcast/client/search_spec.rb
98
+ - spec/howcast/client/video_spec.rb
99
+ - spec/spec_helper.rb
data/Manifest.txt DELETED
@@ -1,36 +0,0 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- README.markdown
5
- Rakefile
6
- config/hoe.rb
7
- config/requirements.rb
8
- lib/howcast.rb
9
- lib/howcast/client.rb
10
- lib/howcast/version.rb
11
- lib/howcast/errors.rb
12
- lib/howcast/client/base.rb
13
- lib/howcast/client/video.rb
14
- lib/howcast/client/guide.rb
15
- lib/howcast/client/search.rb
16
- lib/howcast/client/category.rb
17
- script/destroy
18
- script/generate
19
- script/txt2html
20
- setup.rb
21
- spec/spec.opts
22
- spec/spec_helper.rb
23
- spec/howcast/client/base_spec.rb
24
- spec/howcast/client/guide_spec.rb
25
- spec/howcast/client/video_spec.rb
26
- spec/howcast/client/search_spec.rb
27
- spec/howcast/client/category_spec.rb
28
- tasks/deployment.rake
29
- tasks/environment.rake
30
- tasks/rspec.rake
31
- tasks/website.rake
32
- website/index.html
33
- website/index.txt
34
- website/javascripts/rounded_corners_lite.inc.js
35
- website/stylesheets/screen.css
36
- website/template.rhtml