partigi-partigirb 0.2.1
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/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/partigirb/client.rb +190 -0
- data/lib/partigirb/core_ext.rb +78 -0
- data/lib/partigirb/handlers/atom_handler.rb +24 -0
- data/lib/partigirb/handlers/json_handler.rb +10 -0
- data/lib/partigirb/handlers/string_handler.rb +9 -0
- data/lib/partigirb/handlers/xml_handler.rb +51 -0
- data/lib/partigirb/transport.rb +160 -0
- data/lib/partigirb.rb +25 -0
- data/partigirb.gemspec +69 -0
- data/test/atom_handler_test.rb +61 -0
- data/test/client_test.rb +198 -0
- data/test/fixtures/alvaro_friends.atom.xml +80 -0
- data/test/fixtures/pulp_fiction.atom.xml +99 -0
- data/test/json_handler_test.rb +7 -0
- data/test/mocks/net_http_mock.rb +12 -0
- data/test/mocks/response_mock.rb +12 -0
- data/test/mocks/transport_mock.rb +15 -0
- data/test/test_helper.rb +47 -0
- data/test/transport_test.rb +8 -0
- data/test/xml_handler_test.rb +65 -0
- metadata +89 -0
data/partigirb.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{partigirb}
|
5
|
+
s.version = "0.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Alvaro Bautista", "Fernando Blat"]
|
9
|
+
s.date = %q{2009-07-24}
|
10
|
+
s.email = ["alvarobp@gmail.com", "ferblape@gmail.com"]
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"lib/partigirb.rb",
|
22
|
+
"lib/partigirb/client.rb",
|
23
|
+
"lib/partigirb/core_ext.rb",
|
24
|
+
"lib/partigirb/handlers/atom_handler.rb",
|
25
|
+
"lib/partigirb/handlers/json_handler.rb",
|
26
|
+
"lib/partigirb/handlers/string_handler.rb",
|
27
|
+
"lib/partigirb/handlers/xml_handler.rb",
|
28
|
+
"lib/partigirb/transport.rb",
|
29
|
+
"partigirb.gemspec",
|
30
|
+
"test/atom_handler_test.rb",
|
31
|
+
"test/client_test.rb",
|
32
|
+
"test/fixtures/alvaro_friends.atom.xml",
|
33
|
+
"test/fixtures/pulp_fiction.atom.xml",
|
34
|
+
"test/json_handler_test.rb",
|
35
|
+
"test/mocks/net_http_mock.rb",
|
36
|
+
"test/mocks/response_mock.rb",
|
37
|
+
"test/mocks/transport_mock.rb",
|
38
|
+
"test/test_helper.rb",
|
39
|
+
"test/transport_test.rb",
|
40
|
+
"test/xml_handler_test.rb"
|
41
|
+
]
|
42
|
+
s.has_rdoc = true
|
43
|
+
s.homepage = %q{http://github.com/partigi/partigirb}
|
44
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.1}
|
47
|
+
s.summary = %q{TODO}
|
48
|
+
s.test_files = [
|
49
|
+
"test/atom_handler_test.rb",
|
50
|
+
"test/client_test.rb",
|
51
|
+
"test/json_handler_test.rb",
|
52
|
+
"test/mocks/net_http_mock.rb",
|
53
|
+
"test/mocks/response_mock.rb",
|
54
|
+
"test/mocks/transport_mock.rb",
|
55
|
+
"test/test_helper.rb",
|
56
|
+
"test/transport_test.rb",
|
57
|
+
"test/xml_handler_test.rb"
|
58
|
+
]
|
59
|
+
|
60
|
+
if s.respond_to? :specification_version then
|
61
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
+
s.specification_version = 2
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
+
else
|
66
|
+
end
|
67
|
+
else
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class AtomHandlerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@handler = Partigirb::Handlers::AtomHandler.new
|
6
|
+
end
|
7
|
+
|
8
|
+
should "return a PartigiStruct with entry elements for feeds with just one entry" do
|
9
|
+
xmls = build_xml_string do |xml|
|
10
|
+
xml.instruct!
|
11
|
+
|
12
|
+
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
|
13
|
+
xml.title "A feed"
|
14
|
+
xml.id "http://the.feed.url.com"
|
15
|
+
xml.updated "2009-07-24T10:40:22Z"
|
16
|
+
|
17
|
+
xml.entry({"xmlns:ptUser" => 'http://schemas.partigi.com/v1.0/ptUser'}) do
|
18
|
+
xml.category({:scheme => "http://schemas.partigi.com/v1.0#kind", :term => "http://schemas.partigi.com/v1.0#user"})
|
19
|
+
xml.id "http://the.feed.url2.com"
|
20
|
+
xml.title "User entry"
|
21
|
+
xml.ptUser :id, 321
|
22
|
+
xml.ptUser :login, "user_login"
|
23
|
+
xml.ptUser :name, "User Name"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
res = @handler.decode_response(xmls)
|
29
|
+
assert res.is_a?(Partigirb::PartigiStruct)
|
30
|
+
|
31
|
+
assert_equal "User entry", res.title
|
32
|
+
assert_equal "http://the.feed.url2.com", res.id
|
33
|
+
assert_equal 321, res.ptUser_id
|
34
|
+
assert_equal "user_login", res.ptUser_login
|
35
|
+
assert_equal "User Name", res.ptUser_name
|
36
|
+
assert_nil res.updated
|
37
|
+
end
|
38
|
+
|
39
|
+
should "return an array of PartigiStruct with PartigiStruct of each entry in the feed" do
|
40
|
+
xmls = build_xml_string do |xml|
|
41
|
+
xml.instruct!
|
42
|
+
|
43
|
+
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
|
44
|
+
xml.title "A feed"
|
45
|
+
xml.entry({"xmlns:ptUser" => 'http://schemas.partigi.com/v1.0/ptUser'}) do
|
46
|
+
xml.ptUser :id, 321
|
47
|
+
end
|
48
|
+
xml.entry({"xmlns:ptUser" => 'http://schemas.partigi.com/v1.0/ptUser'}) do
|
49
|
+
xml.ptUser :id, 123
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
res = @handler.decode_response(xmls)
|
55
|
+
assert res.is_a?(Array)
|
56
|
+
assert_equal 2, res.size
|
57
|
+
|
58
|
+
assert_equal 321, res[0].ptUser_id
|
59
|
+
assert_equal 123, res[1].ptUser_id
|
60
|
+
end
|
61
|
+
end
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = new_client
|
6
|
+
end
|
7
|
+
|
8
|
+
should "use GET method by default" do
|
9
|
+
@client.users.show.xml
|
10
|
+
|
11
|
+
assert_equal(:get, @client.transport.method)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "use GET method for methods ending with ?" do
|
15
|
+
@client.users.show.xml?
|
16
|
+
|
17
|
+
assert_equal(:get, @client.transport.method)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not make a request if format is missing" do
|
21
|
+
MockTransport.any_instance.expects(:request).never
|
22
|
+
|
23
|
+
@client.users.show
|
24
|
+
|
25
|
+
assert_nil @client.transport.url
|
26
|
+
end
|
27
|
+
|
28
|
+
should "use POST method for methods ending with !" do
|
29
|
+
@client.users.show.xml!
|
30
|
+
|
31
|
+
assert_equal(:post, @client.transport.method)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "use POST method and default format for methods ending with !" do
|
35
|
+
@client.friendships.create!
|
36
|
+
|
37
|
+
assert_equal(:post, @client.transport.method)
|
38
|
+
assert @client.transport.url.path.include?("/friendships/create.atom")
|
39
|
+
end
|
40
|
+
|
41
|
+
should "request to the Partigi API host through HTTP protocol" do
|
42
|
+
@client.users.show.xml
|
43
|
+
|
44
|
+
assert_equal('http', @client.transport.url.scheme)
|
45
|
+
assert_equal(Partigirb::Client::PARTIGI_API_HOST, @client.transport.url.host)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "use the current API version by default" do
|
49
|
+
@client.users.show.xml
|
50
|
+
|
51
|
+
assert_equal(Partigirb::CURRENT_API_VERSION, @client.api_version)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "put the requested API version in the request url" do
|
55
|
+
@client = new_client(200, '', {:api_version => 3})
|
56
|
+
@client.users.show.xml
|
57
|
+
|
58
|
+
assert_equal '/api/v3/users/show.xml', @client.transport.url.path
|
59
|
+
end
|
60
|
+
|
61
|
+
should "add paremeters to url on GET" do
|
62
|
+
@client.items.index.xml :type => 'film', :page => 1, :per_page => 20
|
63
|
+
|
64
|
+
assert_equal 3, request_query.size
|
65
|
+
assert request_query.include?('type=film')
|
66
|
+
assert request_query.include?('page=1')
|
67
|
+
assert request_query.include?('per_page=20')
|
68
|
+
end
|
69
|
+
|
70
|
+
should "add parameters to request body on POST" do
|
71
|
+
@client.reviews.create! :item_id => 'star-wars', :type => 'film', :status => 2, :text => 'My favorite movie', :rating => '5'
|
72
|
+
|
73
|
+
assert_equal 5, post_data.size
|
74
|
+
assert post_data.include?('item_id=star-wars')
|
75
|
+
assert post_data.include?('type=film')
|
76
|
+
assert post_data.include?('status=2')
|
77
|
+
assert post_data.include?('text=My%20favorite%20movie')
|
78
|
+
assert post_data.include?('rating=5')
|
79
|
+
end
|
80
|
+
|
81
|
+
should "add any headers to the HTTP requests" do
|
82
|
+
@client = new_client(200, '', {:headers => {'Useless' => 'void', 'Fake' => 'header'}})
|
83
|
+
@client.user.show.xml
|
84
|
+
|
85
|
+
assert_not_nil Net::HTTP.request['Useless']
|
86
|
+
assert_equal 'void', Net::HTTP.request['Useless']
|
87
|
+
assert_not_nil Net::HTTP.request['Fake']
|
88
|
+
assert_equal 'header', Net::HTTP.request['Fake']
|
89
|
+
end
|
90
|
+
|
91
|
+
should "add authentication headers when login and secret are provided" do
|
92
|
+
@client = new_client(200, '', :auth => {:login => 'auser', :api_secret => 'his_api_secret'})
|
93
|
+
|
94
|
+
@client.friendships.update! :id => 321
|
95
|
+
|
96
|
+
assert_not_nil Net::HTTP.request['Authorization']
|
97
|
+
assert_equal "WSSE realm=\"#{Partigirb::Client::PARTIGI_API_HOST}\", profile=\"UsernameToken\"", Net::HTTP.request['Authorization']
|
98
|
+
|
99
|
+
assert_not_nil Net::HTTP.request['X-WSSE']
|
100
|
+
assert_match /UsernameToken Username="auser", PasswordDigest="[^"]+", Nonce="[^"]+", Created="[^"]+"/, Net::HTTP.request['X-WSSE']
|
101
|
+
end
|
102
|
+
|
103
|
+
should "not add authentication headers if no auth params are provided" do
|
104
|
+
@client.friendships.update! :id => 321
|
105
|
+
|
106
|
+
assert_nil Net::HTTP.request['Authorization']
|
107
|
+
assert_nil Net::HTTP.request['X-WSSE']
|
108
|
+
end
|
109
|
+
|
110
|
+
should "use given nonce for authentication" do
|
111
|
+
@client = new_client(200, '', :auth => {:login => 'auser', :api_secret => 'his_api_secret', :nonce => '123456789101112'})
|
112
|
+
@client.friendships.update! :id => 321
|
113
|
+
|
114
|
+
assert_equal "WSSE realm=\"#{Partigirb::Client::PARTIGI_API_HOST}\", profile=\"UsernameToken\"", Net::HTTP.request['Authorization']
|
115
|
+
assert_match /UsernameToken Username="auser", PasswordDigest="[^"]+", Nonce="123456789101112", Created="[^"]+"/, Net::HTTP.request['X-WSSE']
|
116
|
+
end
|
117
|
+
|
118
|
+
should "use given timestamp string for authentication" do
|
119
|
+
@client = new_client(200, '', :auth => {:login => 'auser', :api_secret => 'his_api_secret', :timestamp => '2009-07-15T14:43:07Z'})
|
120
|
+
@client.friendships.update! :id => 321
|
121
|
+
|
122
|
+
assert_equal "WSSE realm=\"#{Partigirb::Client::PARTIGI_API_HOST}\", profile=\"UsernameToken\"", Net::HTTP.request['Authorization']
|
123
|
+
assert_match /UsernameToken Username="auser", PasswordDigest="[^"]+", Nonce="[^"]+", Created="2009-07-15T14:43:07Z"/, Net::HTTP.request['X-WSSE']
|
124
|
+
end
|
125
|
+
|
126
|
+
should "use given Time object as timestamp for authentication" do
|
127
|
+
timestamp = Time.now
|
128
|
+
@client = new_client(200, '', :auth => {:login => 'auser', :api_secret => 'his_api_secret', :timestamp => timestamp})
|
129
|
+
@client.friendships.update! :id => 321
|
130
|
+
|
131
|
+
assert_equal "WSSE realm=\"#{Partigirb::Client::PARTIGI_API_HOST}\", profile=\"UsernameToken\"", Net::HTTP.request['Authorization']
|
132
|
+
assert_match /UsernameToken Username="auser", PasswordDigest="[^"]+", Nonce="[^"]+", Created="#{timestamp.strftime(Partigirb::Client::TIMESTAMP_FORMAT)}"/, Net::HTTP.request['X-WSSE']
|
133
|
+
end
|
134
|
+
|
135
|
+
should "use the PasswordDigest from given parameters" do
|
136
|
+
@client = new_client(200, '', :auth => {:login => 'auser', :api_secret => 'his_api_secret', :nonce => '123456789101112', :timestamp => '2009-07-15T14:43:07Z'})
|
137
|
+
@client.friendships.update! :id => 321
|
138
|
+
|
139
|
+
pdigest = Base64.encode64(Digest::SHA1.hexdigest("1234567891011122009-07-15T14:43:07Zauserhis_api_secret")).chomp
|
140
|
+
|
141
|
+
assert_equal "WSSE realm=\"#{Partigirb::Client::PARTIGI_API_HOST}\", profile=\"UsernameToken\"", Net::HTTP.request['Authorization']
|
142
|
+
assert_match /UsernameToken Username="auser", PasswordDigest="#{pdigest}", Nonce="123456789101112", Created="2009-07-15T14:43:07Z"/, Net::HTTP.request['X-WSSE']
|
143
|
+
end
|
144
|
+
|
145
|
+
context "generate_nonce method" do
|
146
|
+
should "generate random strings" do
|
147
|
+
@client.instance_eval do
|
148
|
+
nonces = []
|
149
|
+
1.upto(25) do
|
150
|
+
assert !nonces.include?(generate_nonce)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
should "process XML response by XML handler" do
|
157
|
+
Partigirb::Handlers::XMLHandler.any_instance.expects(:decode_response).once
|
158
|
+
Partigirb::Handlers::AtomHandler.any_instance.expects(:decode_response).never
|
159
|
+
Partigirb::Handlers::JSONHandler.any_instance.expects(:decode_response).never
|
160
|
+
@client.items.xml
|
161
|
+
end
|
162
|
+
|
163
|
+
should "process Atom response by Atom handler" do
|
164
|
+
Partigirb::Handlers::XMLHandler.any_instance.expects(:decode_response).never
|
165
|
+
Partigirb::Handlers::AtomHandler.any_instance.expects(:decode_response).once
|
166
|
+
Partigirb::Handlers::JSONHandler.any_instance.expects(:decode_response).never
|
167
|
+
@client.items.atom
|
168
|
+
end
|
169
|
+
|
170
|
+
should "process JSON response by JSON handler" do
|
171
|
+
Partigirb::Handlers::XMLHandler.any_instance.expects(:decode_response).never
|
172
|
+
Partigirb::Handlers::AtomHandler.any_instance.expects(:decode_response).never
|
173
|
+
Partigirb::Handlers::JSONHandler.any_instance.expects(:decode_response).once
|
174
|
+
@client.items.json
|
175
|
+
end
|
176
|
+
|
177
|
+
# Copied from Grackle
|
178
|
+
should "clear the request path on clear" do
|
179
|
+
client = new_client(200,'[{"id":1,"text":"test 1"}]')
|
180
|
+
client.some.url.that.does.not.exist
|
181
|
+
assert_equal('/some/url/that/does/not/exist',client.send(:request).path,"An unexecuted path should be build up")
|
182
|
+
client.clear
|
183
|
+
assert_equal('',client.send(:request).path,"The path shoudl be cleared")
|
184
|
+
end
|
185
|
+
|
186
|
+
should "use multipart encoding when using a file param" do
|
187
|
+
client = new_client(200,'')
|
188
|
+
client.account.update_profile_image! :image=>File.new(__FILE__)
|
189
|
+
assert_match(/multipart\/form-data/,Net::HTTP.request['Content-Type'])
|
190
|
+
end
|
191
|
+
|
192
|
+
should "escape and encode time param" do
|
193
|
+
client = new_client(200,'')
|
194
|
+
time = Time.now-60*60
|
195
|
+
client.statuses.public_timeline? :since=>time
|
196
|
+
assert_equal("/api/v#{Partigirb::CURRENT_API_VERSION}/statuses/public_timeline.atom?since=#{CGI::escape(time.httpdate)}", Net::HTTP.request.path)
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
|
+
<title>user/7/friends » Partigi</title>
|
4
|
+
<id>http://www.partigi.com/api/v1/friends/show/7.atom</id>
|
5
|
+
<updated>2009-07-23T10:08:14Z</updated>
|
6
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/friends/show/7.atom" rel="self"/>
|
7
|
+
<link type="text/html" href="http://www.partigi.com/alvarobp/friends/follows" rel="alternate"/>
|
8
|
+
<author>
|
9
|
+
<name>Partigi</name>
|
10
|
+
</author>
|
11
|
+
<entry xmlns:ptUser="http://schemas.partigi.com/v1.0/ptUser">
|
12
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#user"/>
|
13
|
+
<id>http://www.partigi.com/friend1</id>
|
14
|
+
<title>Friend 1</title>
|
15
|
+
<updated>2009-07-24T19:16:14Z</updated>
|
16
|
+
<published>2009-07-23T10:07:49Z</published>
|
17
|
+
<link type="text/html" href="http://www.partigi.com/friend1" rel="alternate"/>
|
18
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/users/show.atom?id=friend1" rel="self"/>
|
19
|
+
<ptUser:id>440</ptUser:id>
|
20
|
+
<ptUser:login>friend1</ptUser:login>
|
21
|
+
<ptUser:name>Friend 1</ptUser:name>
|
22
|
+
<ptUser:surname>Surname 1</ptUser:surname>
|
23
|
+
<ptUser:country>ES</ptUser:country>
|
24
|
+
</entry>
|
25
|
+
<entry xmlns:ptUser="http://schemas.partigi.com/v1.0/ptUser">
|
26
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#user"/>
|
27
|
+
<id>http://www.partigi.com/friend2</id>
|
28
|
+
<title>Friend 2</title>
|
29
|
+
<updated>2009-07-23T10:15:18Z</updated>
|
30
|
+
<published>2009-07-03T04:20:09Z</published>
|
31
|
+
<link type="text/html" href="http://www.partigi.com/friend2" rel="alternate"/>
|
32
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/users/show.atom?id=friend2" rel="self"/>
|
33
|
+
<ptUser:id>357</ptUser:id>
|
34
|
+
<ptUser:login>friend2</ptUser:login>
|
35
|
+
<ptUser:name>Friend 2</ptUser:name>
|
36
|
+
<ptUser:surname>Surname 2</ptUser:surname>
|
37
|
+
<ptUser:country>ES</ptUser:country>
|
38
|
+
</entry>
|
39
|
+
<entry xmlns:ptUser="http://schemas.partigi.com/v1.0/ptUser">
|
40
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#user"/>
|
41
|
+
<id>http://www.partigi.com/friend3</id>
|
42
|
+
<title>Friend 3</title>
|
43
|
+
<updated>2009-07-18T17:05:42Z</updated>
|
44
|
+
<published>2009-07-18T17:04:43Z</published>
|
45
|
+
<link type="text/html" href="http://www.partigi.com/friend3" rel="alternate"/>
|
46
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/users/show.atom?id=friend3" rel="self"/>
|
47
|
+
<ptUser:id>408</ptUser:id>
|
48
|
+
<ptUser:login>friend3</ptUser:login>
|
49
|
+
<ptUser:name>Friend 3</ptUser:name>
|
50
|
+
<ptUser:surname>Surname 3</ptUser:surname>
|
51
|
+
<ptUser:country>ES</ptUser:country>
|
52
|
+
</entry>
|
53
|
+
<entry xmlns:ptUser="http://schemas.partigi.com/v1.0/ptUser">
|
54
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#user"/>
|
55
|
+
<id>http://www.partigi.com/friend4</id>
|
56
|
+
<title>Friend 4</title>
|
57
|
+
<updated>2009-07-18T12:35:46Z</updated>
|
58
|
+
<published>2009-05-20T13:51:09Z</published>
|
59
|
+
<link type="text/html" href="http://www.partigi.com/friend4" rel="alternate"/>
|
60
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/users/show.atom?id=friend4" rel="self"/>
|
61
|
+
<ptUser:id>183</ptUser:id>
|
62
|
+
<ptUser:login>friend4</ptUser:login>
|
63
|
+
<ptUser:name>Friend 4</ptUser:name>
|
64
|
+
<ptUser:surname>Surname 4</ptUser:surname>
|
65
|
+
</entry>
|
66
|
+
<entry xmlns:ptUser="http://schemas.partigi.com/v1.0/ptUser">
|
67
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#user"/>
|
68
|
+
<id>http://www.partigi.com/friend5</id>
|
69
|
+
<title>Friend 5</title>
|
70
|
+
<updated>2009-07-19T17:27:53Z</updated>
|
71
|
+
<published>2009-06-04T11:37:17Z</published>
|
72
|
+
<link type="text/html" href="http://www.partigi.com/friend5" rel="alternate"/>
|
73
|
+
<link type="application/atom+xml" href="http://www.partigi.com/api/v1/users/show.atom?id=friend5" rel="self"/>
|
74
|
+
<ptUser:id>249</ptUser:id>
|
75
|
+
<ptUser:login>friend5</ptUser:login>
|
76
|
+
<ptUser:name>Friend 5</ptUser:name>
|
77
|
+
<ptUser:surname>Surname 5</ptUser:surname>
|
78
|
+
<ptUser:country>ES</ptUser:country>
|
79
|
+
</entry>
|
80
|
+
</feed>
|
@@ -0,0 +1,99 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
|
+
<title>Partigi</title>
|
4
|
+
<id>http://localhost:3000/films/pulp-fiction</id>
|
5
|
+
<updated>2009-07-17T07:18:27Z</updated>
|
6
|
+
<link type="application/atom+xml" href="http://localhost:3000/api/v1/items/show.atom?id=pulp-fiction&type=film" rel="self"/>
|
7
|
+
<link type="text/html" href="http://localhost:3000/films/pulp-fiction" rel="alternate"/>
|
8
|
+
<author>
|
9
|
+
<name>Partigi</name>
|
10
|
+
</author>
|
11
|
+
<entry xmlns:ptPerson="http://schemas.partigi.com/v1.0/ptPerson" xmlns:ptItem="http://schemas.partigi.com/v1.0/ptItem">
|
12
|
+
<category scheme="http://schemas.partigi.com/v1.0#kind" term="http://schemas.partigi.com/v1.0#item"/>
|
13
|
+
<id>http://localhost:3000/films/pulp-fiction</id>
|
14
|
+
<title>Pulp Fiction</title>
|
15
|
+
<updated>2009-07-17T07:18:27Z</updated>
|
16
|
+
<published>2009-03-31T18:46:15Z</published>
|
17
|
+
<link type="text/html" rel="alternate" href="http://localhost:3000/films/pulp-fiction"/>
|
18
|
+
<link type="application/atom+xml" rel="self" href="http://localhost:3000/api/v1/items/show.atom?id=pulp-fiction&type=film"/>
|
19
|
+
<ptItem:id>50</ptItem:id>
|
20
|
+
<ptItem:type>film</ptItem:type>
|
21
|
+
<ptItem:release_year>1994</ptItem:release_year>
|
22
|
+
<ptItem:title lang="es">Pulp Fiction</ptItem:title>
|
23
|
+
<ptItem:country>USA</ptItem:country>
|
24
|
+
<ptItem:posters>
|
25
|
+
<ptItem:poster type="image/jpeg" lang="" size="thumb" href="http://s3.amazonaws.com/partigidev/films/posters/251/pulp-fiction_thumb.jpg"/>
|
26
|
+
</ptItem:posters>
|
27
|
+
<ptItem:genre lang="es" name="comedia"/>
|
28
|
+
<ptItem:credits>
|
29
|
+
<ptPerson:entry rel="director">
|
30
|
+
<ptPerson:id>733</ptPerson:id>
|
31
|
+
<ptPerson:name>Quentin Tarantino</ptPerson:name>
|
32
|
+
</ptPerson:entry>
|
33
|
+
<ptPerson:entry rel="writer">
|
34
|
+
<ptPerson:id>733</ptPerson:id>
|
35
|
+
<ptPerson:name>Quentin Tarantino</ptPerson:name>
|
36
|
+
</ptPerson:entry>
|
37
|
+
<ptPerson:entry rel="cast_member">
|
38
|
+
<ptPerson:id>734</ptPerson:id>
|
39
|
+
<ptPerson:name>John Travolta</ptPerson:name>
|
40
|
+
</ptPerson:entry>
|
41
|
+
<ptPerson:entry rel="cast_member">
|
42
|
+
<ptPerson:id>735</ptPerson:id>
|
43
|
+
<ptPerson:name>Samuel L. Jackson</ptPerson:name>
|
44
|
+
</ptPerson:entry>
|
45
|
+
<ptPerson:entry rel="cast_member">
|
46
|
+
<ptPerson:id>736</ptPerson:id>
|
47
|
+
<ptPerson:name>Tim Roth</ptPerson:name>
|
48
|
+
</ptPerson:entry>
|
49
|
+
<ptPerson:entry rel="cast_member">
|
50
|
+
<ptPerson:id>737</ptPerson:id>
|
51
|
+
<ptPerson:name>Amanda Plummer</ptPerson:name>
|
52
|
+
</ptPerson:entry>
|
53
|
+
<ptPerson:entry rel="cast_member">
|
54
|
+
<ptPerson:id>738</ptPerson:id>
|
55
|
+
<ptPerson:name>Eric Stoltz</ptPerson:name>
|
56
|
+
</ptPerson:entry>
|
57
|
+
<ptPerson:entry rel="cast_member">
|
58
|
+
<ptPerson:id>739</ptPerson:id>
|
59
|
+
<ptPerson:name>Bruce Willis</ptPerson:name>
|
60
|
+
</ptPerson:entry>
|
61
|
+
<ptPerson:entry rel="cast_member">
|
62
|
+
<ptPerson:id>499</ptPerson:id>
|
63
|
+
<ptPerson:name>Ving Rhames</ptPerson:name>
|
64
|
+
</ptPerson:entry>
|
65
|
+
<ptPerson:entry rel="cast_member">
|
66
|
+
<ptPerson:id>740</ptPerson:id>
|
67
|
+
<ptPerson:name>Phil LaMarr</ptPerson:name>
|
68
|
+
</ptPerson:entry>
|
69
|
+
<ptPerson:entry rel="cast_member">
|
70
|
+
<ptPerson:id>741</ptPerson:id>
|
71
|
+
<ptPerson:name>Maria de Medeiros</ptPerson:name>
|
72
|
+
</ptPerson:entry>
|
73
|
+
<ptPerson:entry rel="cast_member">
|
74
|
+
<ptPerson:id>742</ptPerson:id>
|
75
|
+
<ptPerson:name>Rosanna Arquette</ptPerson:name>
|
76
|
+
</ptPerson:entry>
|
77
|
+
<ptPerson:entry rel="cast_member">
|
78
|
+
<ptPerson:id>743</ptPerson:id>
|
79
|
+
<ptPerson:name>Peter Greene</ptPerson:name>
|
80
|
+
</ptPerson:entry>
|
81
|
+
<ptPerson:entry rel="cast_member">
|
82
|
+
<ptPerson:id>744</ptPerson:id>
|
83
|
+
<ptPerson:name>Uma Thurman</ptPerson:name>
|
84
|
+
</ptPerson:entry>
|
85
|
+
<ptPerson:entry rel="cast_member">
|
86
|
+
<ptPerson:id>745</ptPerson:id>
|
87
|
+
<ptPerson:name>Duane Whitaker</ptPerson:name>
|
88
|
+
</ptPerson:entry>
|
89
|
+
<ptPerson:entry rel="cast_member">
|
90
|
+
<ptPerson:id>746</ptPerson:id>
|
91
|
+
<ptPerson:name>Paul Calderon</ptPerson:name>
|
92
|
+
</ptPerson:entry>
|
93
|
+
<ptPerson:entry rel="cast_member">
|
94
|
+
<ptPerson:id>747</ptPerson:id>
|
95
|
+
<ptPerson:name>Frank Whaley</ptPerson:name>
|
96
|
+
</ptPerson:entry>
|
97
|
+
</ptItem:credits>
|
98
|
+
</entry>
|
99
|
+
</feed>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#Mock responses that conform mostly to HTTPResponse's interface
|
2
|
+
class MockResponse
|
3
|
+
include Net::HTTPHeader
|
4
|
+
attr_accessor :code, :body
|
5
|
+
def initialize(code,body,headers={})
|
6
|
+
self.code = code
|
7
|
+
self.body = body
|
8
|
+
headers.each do |name, value|
|
9
|
+
self[name] = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#Transport that collects info on requests and responses for testing purposes
|
2
|
+
class MockTransport < Partigirb::Transport
|
3
|
+
attr_accessor :status, :body, :method, :url, :options
|
4
|
+
|
5
|
+
def initialize(status,body,headers={})
|
6
|
+
Net::HTTP.response = MockResponse.new(status,body,headers)
|
7
|
+
end
|
8
|
+
|
9
|
+
def request(method, string_url, options)
|
10
|
+
self.method = method
|
11
|
+
self.url = URI.parse(string_url)
|
12
|
+
self.options = options
|
13
|
+
super(method,string_url,options)
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'builder'
|
6
|
+
require 'ruby-debug'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'partigirb'
|
11
|
+
|
12
|
+
Dir.glob('test/mocks/*_mock.rb').each { |e| require e }
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
def new_client(status=200, response_body='', client_opts={})
|
16
|
+
client = Partigirb::Client.new(client_opts)
|
17
|
+
client.transport = MockTransport.new(status,response_body)
|
18
|
+
client
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_query
|
22
|
+
if Net::HTTP.request && !Net::HTTP.request.path.nil? && !Net::HTTP.request.path.empty?
|
23
|
+
Net::HTTP.request.path.split(/\?/)[1].split('&')
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def post_data
|
30
|
+
Net::HTTP.request.body.split('&')
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_xml_string(&block)
|
34
|
+
s = String.new
|
35
|
+
xml = Builder::XmlMarkup.new(:target => s)
|
36
|
+
yield(xml)
|
37
|
+
s
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_fixture(name, format = :xml)
|
41
|
+
name += '.xml' if format.to_s == 'xml'
|
42
|
+
name += '.atom.xml' if format.to_s == 'atom'
|
43
|
+
name += '.json' if format.to_s == 'json'
|
44
|
+
|
45
|
+
File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
|
46
|
+
end
|
47
|
+
end
|