howcast 0.4.16 → 0.5.0
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.
- data/CHANGELOG +4 -0
- data/VERSION +1 -1
- data/howcast.gemspec +5 -2
- data/lib/howcast/client.rb +1 -1
- data/lib/howcast/client/user.rb +94 -0
- data/spec/howcast/client/user_spec.rb +43 -0
- data/spec/xml_fixtures_helper.rb +40 -0
- metadata +7 -4
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/howcast.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{howcast}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jingshen Jimmy Zhang", "Ian Smith-Heisters"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-17}
|
13
13
|
s.description = %q{ Howcast offers an Application Programming Interface (API) which allows
|
14
14
|
developers to build applications that interface with Howcast. The Howcast
|
15
15
|
API is RESTful (REpresentational State Transfer) and users of this API will
|
@@ -38,12 +38,14 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/howcast/client/category.rb",
|
39
39
|
"lib/howcast/client/marker.rb",
|
40
40
|
"lib/howcast/client/search.rb",
|
41
|
+
"lib/howcast/client/user.rb",
|
41
42
|
"lib/howcast/client/video.rb",
|
42
43
|
"lib/howcast/errors.rb",
|
43
44
|
"lib/howcast/logging.rb",
|
44
45
|
"spec/howcast/client/base_spec.rb",
|
45
46
|
"spec/howcast/client/category_spec.rb",
|
46
47
|
"spec/howcast/client/search_spec.rb",
|
48
|
+
"spec/howcast/client/user_spec.rb",
|
47
49
|
"spec/howcast/client/video_spec.rb",
|
48
50
|
"spec/output_capture_helper.rb",
|
49
51
|
"spec/spec.opts",
|
@@ -61,6 +63,7 @@ Gem::Specification.new do |s|
|
|
61
63
|
"spec/howcast/client/base_spec.rb",
|
62
64
|
"spec/howcast/client/category_spec.rb",
|
63
65
|
"spec/howcast/client/search_spec.rb",
|
66
|
+
"spec/howcast/client/user_spec.rb",
|
64
67
|
"spec/howcast/client/video_spec.rb",
|
65
68
|
"spec/output_capture_helper.rb",
|
66
69
|
"spec/spec_helper.rb",
|
data/lib/howcast/client.rb
CHANGED
@@ -2,6 +2,6 @@
|
|
2
2
|
class Howcast::Client
|
3
3
|
end
|
4
4
|
|
5
|
-
%w(client/base client/video client/search client/category client/marker).each do |dependency|
|
5
|
+
%w(client/base client/video client/search client/category client/marker client/user).each do |dependency|
|
6
6
|
require(File.expand_path(File.join(File.dirname(__FILE__), dependency)))
|
7
7
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 Howcast Media Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class Howcast::Client
|
25
|
+
class User
|
26
|
+
extend WatchAttrAccessors
|
27
|
+
attr_accessor :login, :videos
|
28
|
+
|
29
|
+
# Creates a new User object which is used to encapsulate all the attributes available
|
30
|
+
# from the Howcast user profile API.
|
31
|
+
#
|
32
|
+
# === Inputs
|
33
|
+
#
|
34
|
+
# * <tt>attributes</tt> -- A hash to set the various attributes of the user object
|
35
|
+
#
|
36
|
+
# === Examples
|
37
|
+
#
|
38
|
+
# Initialize a user with login "someone"
|
39
|
+
# User.new :login => "someone"
|
40
|
+
def initialize(attributes={})
|
41
|
+
attributes.each do |k, v|
|
42
|
+
self.send("#{k}=", v) if self.respond_to?(k)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Provides access to the Howcast user API.
|
48
|
+
#
|
49
|
+
# === Inputs
|
50
|
+
#
|
51
|
+
# * <tt>login</tt> -- The login/username of the user to lookup
|
52
|
+
#
|
53
|
+
# === Outputs
|
54
|
+
#
|
55
|
+
# User object if the login exists or nil if the login doesn't exist or is malformed
|
56
|
+
#
|
57
|
+
# === Exceptions
|
58
|
+
#
|
59
|
+
# * <tt>Howcast::ApiNotFound</tt>
|
60
|
+
#
|
61
|
+
# === Examples
|
62
|
+
#
|
63
|
+
# Get the Howcast user with login 'someone'
|
64
|
+
# Howcast::Client.new.user('someone')
|
65
|
+
def user(login)
|
66
|
+
response = establish_connection("users/#{login}/profile/videos.xml")
|
67
|
+
parse_single_user_xml(login, response)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
# Exception here to set the login vs. parsing it (not currently included in the api response)
|
72
|
+
def parse_single_user_xml(login, xml)
|
73
|
+
hash = {}
|
74
|
+
User.attr_accessors.each do |attribute|
|
75
|
+
node_name = attribute.to_s.gsub("_", "-") # xml schema uses hyphens for spaces, but ruby uses underscores
|
76
|
+
if node_name == "videos"
|
77
|
+
hash[attribute] = videos_for(xml) unless xml.at(node_name).nil?
|
78
|
+
else
|
79
|
+
hash[attribute] = !xml.at(node_name).nil? ? xml.at(node_name).inner_text.strip : ""
|
80
|
+
end
|
81
|
+
end
|
82
|
+
hash[:login] = login
|
83
|
+
hash.values.all?{|v| v==""} ? nil : User.new(hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
def videos_for(xml)
|
87
|
+
videos = []
|
88
|
+
node = xml.at('videos')
|
89
|
+
node.children_of_type('video').each do |child|
|
90
|
+
videos << parse_single_xml(child, Video)
|
91
|
+
end unless node.nil?
|
92
|
+
videos
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Howcast::Client::User, "initialize" do
|
4
|
+
it "should create a user object with all the inputted attributes" do
|
5
|
+
user = Howcast::Client::User.new :login => "someone"
|
6
|
+
user.login.should == 'someone'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should ignore inputs which are not user attributes" do
|
10
|
+
user = Howcast::Client::User.new :not_an_attribute => "value", :login => "someone"
|
11
|
+
user.respond_to?(:not_an_attribute).should be_false
|
12
|
+
user.login.should == "someone"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Howcast::Client, "user" do
|
17
|
+
before do
|
18
|
+
@hc = Howcast::Client.new(:key => "myapikey")
|
19
|
+
@hc.stub!(:open).and_return(user_videos_xml)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should establish a connection with the correct user url" do
|
23
|
+
@hc.should_receive(:open).with(equivalent_uri("http://www.howcast.com/users/someone/profile/videos.xml?api_key=myapikey")).and_return(user_videos_xml)
|
24
|
+
@hc.user('someone')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise Howcast::ApiKeyNotFound error when the response contains Invalid API Key" do
|
28
|
+
lambda {
|
29
|
+
@hc.stub!(:open).and_return(invalid_api_key_xml)
|
30
|
+
@hc.user('someone')
|
31
|
+
}.should raise_error(Howcast::ApiKeyNotFound)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set the login attribute in the user model response" do
|
35
|
+
@hc.user('someone').login.should == "someone"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set the videos attribute in the user model response" do
|
39
|
+
videos = @hc.user('someone').videos
|
40
|
+
videos.size.should == 1
|
41
|
+
videos[0].title.should == "How To Remove Bike Handlebar Grips"
|
42
|
+
end
|
43
|
+
end
|
data/spec/xml_fixtures_helper.rb
CHANGED
@@ -2485,4 +2485,44 @@ module XmlFixturesHelper
|
|
2485
2485
|
</howcast>
|
2486
2486
|
VID
|
2487
2487
|
end
|
2488
|
+
|
2489
|
+
def user_videos_xml
|
2490
|
+
<<-VID
|
2491
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2492
|
+
<howcast version="0.1">
|
2493
|
+
<title>Howcast - mrmark86's videos</title>
|
2494
|
+
<count>1</count>
|
2495
|
+
<videos>
|
2496
|
+
<video>
|
2497
|
+
<category-id>1356</category-id>
|
2498
|
+
<id>329098</id>
|
2499
|
+
<title>How To Remove Bike Handlebar Grips</title>
|
2500
|
+
<views>77</views>
|
2501
|
+
<type>HowcastGuide</type>
|
2502
|
+
<created-at>Sun, 14 Mar 2010 11:02:07 -0700</created-at>
|
2503
|
+
<rating>0</rating>
|
2504
|
+
<username>mrmark86</username>
|
2505
|
+
<description>
|
2506
|
+
<![CDATA[Remove your handlebar grips in just a few minutes with these tips.]]>
|
2507
|
+
</description>
|
2508
|
+
<embed>
|
2509
|
+
<![CDATA[<object width="425" height="352" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="howcastplayer"><param name="movie" value="http://www.howcast.com/flash/howcast_player.swf?file=329098"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.howcast.com/flash/howcast_player.swf?file=329098" type="application/x-shockwave-flash" width="425" height="352" allowFullScreen="true" allowScriptAccess="always" ></embed></object>]]>
|
2510
|
+
</embed>
|
2511
|
+
<duration>61</duration>
|
2512
|
+
<filename>http://media.howcast.com/system/videos/6/16/57/32/325716.flv</filename>
|
2513
|
+
<tags>sports, fitness, bikes, biking, bicycles, handles, grips, removal, tools, screwdriver</tags>
|
2514
|
+
<category-hierarchy>
|
2515
|
+
<category id="1334">Sports & Fitness</category>
|
2516
|
+
<category parent_id="1334" id="1353">Bikes & Biking</category>
|
2517
|
+
<category parent_id="1353" id="1356">Biking Equipment</category>
|
2518
|
+
</category-hierarchy>
|
2519
|
+
<comment-count>0</comment-count>
|
2520
|
+
<thumbnail-url>http://img.howcast.com/system/thumbnails/329098/RemoveBikeHandlebarGrips_xxlarge_maintained_aspect.png</thumbnail-url>
|
2521
|
+
<permalink>http://www.howcast.com/videos/329098-How-To-Remove-Bike-Handlebar-Grips</permalink>
|
2522
|
+
<content_rating>nonadult</content_rating>
|
2523
|
+
</video>
|
2524
|
+
</videos>
|
2525
|
+
</howcast>
|
2526
|
+
VID
|
2527
|
+
end
|
2488
2528
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jingshen Jimmy Zhang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-17 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -64,12 +64,14 @@ files:
|
|
64
64
|
- lib/howcast/client/category.rb
|
65
65
|
- lib/howcast/client/marker.rb
|
66
66
|
- lib/howcast/client/search.rb
|
67
|
+
- lib/howcast/client/user.rb
|
67
68
|
- lib/howcast/client/video.rb
|
68
69
|
- lib/howcast/errors.rb
|
69
70
|
- lib/howcast/logging.rb
|
70
71
|
- spec/howcast/client/base_spec.rb
|
71
72
|
- spec/howcast/client/category_spec.rb
|
72
73
|
- spec/howcast/client/search_spec.rb
|
74
|
+
- spec/howcast/client/user_spec.rb
|
73
75
|
- spec/howcast/client/video_spec.rb
|
74
76
|
- spec/output_capture_helper.rb
|
75
77
|
- spec/spec.opts
|
@@ -111,6 +113,7 @@ test_files:
|
|
111
113
|
- spec/howcast/client/base_spec.rb
|
112
114
|
- spec/howcast/client/category_spec.rb
|
113
115
|
- spec/howcast/client/search_spec.rb
|
116
|
+
- spec/howcast/client/user_spec.rb
|
114
117
|
- spec/howcast/client/video_spec.rb
|
115
118
|
- spec/output_capture_helper.rb
|
116
119
|
- spec/spec_helper.rb
|