partigi-partigirb 0.2.3 → 0.2.4
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/README.rdoc +67 -2
- data/VERSION +1 -1
- data/examples/last_reviews_summary.rb +34 -0
- data/examples/who_ignores_me.rb +35 -0
- data/lib/partigirb/handlers/xml_handler.rb +7 -0
- data/lib/partigirb.rb +2 -0
- data/partigirb.gemspec +7 -3
- data/test/xml_handler_test.rb +23 -5
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -1,8 +1,73 @@
|
|
1
1
|
= partigirb
|
2
2
|
|
3
|
-
|
3
|
+
Ruby wrapper for the Partigi API, adapted from Grackle by Hayes Davis (http://github.com/hayesdavis/grackle/tree/master).
|
4
4
|
|
5
|
-
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
=== Creating a client
|
8
|
+
|
9
|
+
==== Without Authentication
|
10
|
+
|
11
|
+
client = Partigirb::Client.new
|
12
|
+
|
13
|
+
==== With Authentication
|
14
|
+
|
15
|
+
client = Partigirb::Client.new(:auth => {:login => 'SOMEUSERLOGIN', :api_secret => 'SECRETGENERATEDFORTHEUSER'})
|
16
|
+
|
17
|
+
==== With specific API version
|
18
|
+
|
19
|
+
client = Partigirb::Client.new(:api_version => 2)
|
20
|
+
|
21
|
+
=== Request methods
|
22
|
+
|
23
|
+
A request to Partigi servers is done by translating Partigi URL paths into a set of chained method calls, just changing slashes by dots. Each call is used to build the request URL until a format call is found which causes the request to be sent. In order to specify the HTTP method use:
|
24
|
+
|
25
|
+
- <tt>?</tt> for HTTP GET
|
26
|
+
- <tt>!</tt> for HTTP POST (in this case you will need to use a client with authentication)
|
27
|
+
|
28
|
+
A request is not performed until either you add the above signs to your last method call or you use a format method call.
|
29
|
+
|
30
|
+
=== Formats
|
31
|
+
|
32
|
+
The response format is specified by a method call with the format name (atom, json or xml). Notice that the only format fully implemented on Partigi API at the moment is atom, which is the default used by the wrapper.
|
33
|
+
|
34
|
+
=== Example requests
|
35
|
+
|
36
|
+
The simplest way of executing a GET request is to use the <tt>?</tt> notation, using the default format.
|
37
|
+
|
38
|
+
client.users.show? :id => 'johnwayne' # http://www.partigi.com/api/v1/users/show.atom?id=johnwayne
|
39
|
+
|
40
|
+
Also you can force the format:
|
41
|
+
|
42
|
+
client.users.show.json? :id => 'johnwayne # http://www.partigi.com/api/v1/users/show.json?id=johnwayne
|
43
|
+
|
44
|
+
For POST requests just change <tt>?</tt> by <tt>!</tt>:
|
45
|
+
|
46
|
+
client.reviews.update! :id => 123, :status => 1 # POST to http://www.partigi.com/api/v1/reviews/update.atom
|
47
|
+
|
48
|
+
|
49
|
+
=== Parameter handling
|
50
|
+
|
51
|
+
- All parameters are URL encoded as necessary.
|
52
|
+
- If you use a File object as a parameter it will be POSTed to Twitter in a multipart request.
|
53
|
+
- If you use a Time object as a parameter, .httpdate will be called on it and that value will be used
|
54
|
+
|
55
|
+
=== Return values
|
56
|
+
|
57
|
+
The returned values are always OpenStruct objects (wrapped in Partigirb::PartigiStruct) containing the response values as attributes.
|
58
|
+
|
59
|
+
If the response contains several entries the client returns an Array of OpenStruct objects.
|
60
|
+
|
61
|
+
When using Atom format Partigi returns some XML elements using namespaces. In those cases the elements are mapped to attributes by convention, for example: namespaceName:attribute becomes <tt>namespaceName</tt>_<tt>attribute</tt>
|
62
|
+
|
63
|
+
=== Error handling
|
64
|
+
|
65
|
+
In case Partigi returns an error response, this is turned into a PartigiError object having the error string returned in the XML response as message attribute.
|
66
|
+
|
67
|
+
== Requirements
|
68
|
+
|
69
|
+
- json
|
70
|
+
- mime-types
|
6
71
|
|
7
72
|
== Copyright
|
8
73
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/partigirb'
|
2
|
+
|
3
|
+
if ARGV.empty?
|
4
|
+
puts "\nUsage: ruby #{__FILE__} user_id_or_login\n\n"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
user_id = ARGV.first
|
9
|
+
|
10
|
+
def show_reviews(client, reviews, title)
|
11
|
+
puts
|
12
|
+
puts title
|
13
|
+
puts "-" * title.size
|
14
|
+
puts
|
15
|
+
|
16
|
+
reviews.each do |review|
|
17
|
+
film = client.items.show? :id => review.ptItem_id, :type => 'film'
|
18
|
+
puts "- #{film.title}"
|
19
|
+
puts " Comment: #{review.content}"
|
20
|
+
puts
|
21
|
+
end
|
22
|
+
puts
|
23
|
+
end
|
24
|
+
|
25
|
+
client = Partigirb::Client.new
|
26
|
+
|
27
|
+
reviews = client.reviews.index? :user_id => user_id, :per_page => 5, :status => 0, :order => 'desc'
|
28
|
+
show_reviews(client, reviews, "Latest 5 films you want to watch")
|
29
|
+
|
30
|
+
reviews = client.reviews.index? :user_id => user_id, :per_page => 5, :status => 1, :order => 'desc'
|
31
|
+
show_reviews(client, reviews, "Latest 5 films you have seen")
|
32
|
+
|
33
|
+
reviews = client.reviews.index? :user_id => user_id, :per_page => 5, :status => 2, :order => 'desc'
|
34
|
+
show_reviews(client, reviews, "Latest 5 films you own")
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/partigirb'
|
2
|
+
|
3
|
+
if ARGV.empty?
|
4
|
+
puts "\nUsage: #{__FILE__} user_id_or_login\n\n"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
user_id = ARGV.first
|
9
|
+
|
10
|
+
client = Partigirb::Client.new
|
11
|
+
|
12
|
+
traitors = []
|
13
|
+
|
14
|
+
page = 1
|
15
|
+
friends = []
|
16
|
+
|
17
|
+
# Get logins of people user is following
|
18
|
+
begin
|
19
|
+
friends = client.friendships.index? :user_id => user_id, :type => 'follows', :page => page
|
20
|
+
|
21
|
+
friends.each do |friend|
|
22
|
+
relationship = client.friendships.show? :source_id => user_id, :target_id => friend.ptUser_id
|
23
|
+
traitors << friend.ptUser_login if relationship.ptRelationship_source.ptRelationship_followed_by == 'false'
|
24
|
+
end
|
25
|
+
|
26
|
+
page += 1
|
27
|
+
end while !friends.empty?
|
28
|
+
|
29
|
+
if traitors.empty?
|
30
|
+
"Everything is fine. Everyone you follow is following you."
|
31
|
+
else
|
32
|
+
puts "Those are the ones that don't want to know about you:"
|
33
|
+
puts
|
34
|
+
traitors.each {|t| puts " - #{t}"}
|
35
|
+
end
|
@@ -32,6 +32,8 @@ module Partigirb
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
links = node.elements.delete_all('link')
|
36
|
+
|
35
37
|
node.elements.each do |e|
|
36
38
|
property = ""
|
37
39
|
|
@@ -43,6 +45,11 @@ module Partigirb
|
|
43
45
|
property << e.name
|
44
46
|
ts.send("#{property}=", load_recursive(e))
|
45
47
|
end
|
48
|
+
|
49
|
+
unless links.empty?
|
50
|
+
ts.send("links=", links.map{|l| build_struct(l)})
|
51
|
+
end
|
52
|
+
|
46
53
|
ts
|
47
54
|
end
|
48
55
|
|
data/lib/partigirb.rb
CHANGED
data/partigirb.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{partigirb}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Alvaro Bautista", "Fernando Blat"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-30}
|
10
10
|
s.email = ["alvarobp@gmail.com", "ferblape@gmail.com"]
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
"README.rdoc",
|
19
19
|
"Rakefile",
|
20
20
|
"VERSION",
|
21
|
+
"examples/last_reviews_summary.rb",
|
22
|
+
"examples/who_ignores_me.rb",
|
21
23
|
"lib/partigirb.rb",
|
22
24
|
"lib/partigirb/client.rb",
|
23
25
|
"lib/partigirb/core_ext.rb",
|
@@ -54,7 +56,9 @@ Gem::Specification.new do |s|
|
|
54
56
|
"test/mocks/transport_mock.rb",
|
55
57
|
"test/test_helper.rb",
|
56
58
|
"test/transport_test.rb",
|
57
|
-
"test/xml_handler_test.rb"
|
59
|
+
"test/xml_handler_test.rb",
|
60
|
+
"examples/last_reviews_summary.rb",
|
61
|
+
"examples/who_ignores_me.rb"
|
58
62
|
]
|
59
63
|
|
60
64
|
if s.respond_to? :specification_version then
|
data/test/xml_handler_test.rb
CHANGED
@@ -69,7 +69,7 @@ class XMLHandlerTest < Test::Unit::TestCase
|
|
69
69
|
xml.user do
|
70
70
|
xml.id 123
|
71
71
|
xml.name 'Bob'
|
72
|
-
xml.
|
72
|
+
xml.field({:attribute1 => 'value1', :attribute2 => 'value2', :attribute3 => 'value3'})
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -78,9 +78,27 @@ class XMLHandlerTest < Test::Unit::TestCase
|
|
78
78
|
assert_equal 123, res.id
|
79
79
|
assert_equal 'Bob', res.name
|
80
80
|
|
81
|
-
assert res.
|
82
|
-
assert_equal '
|
83
|
-
assert_equal '
|
84
|
-
assert_equal '
|
81
|
+
assert res.field.is_a?(Partigirb::PartigiStruct)
|
82
|
+
assert_equal 'value1', res.field.attribute1
|
83
|
+
assert_equal 'value2', res.field.attribute2
|
84
|
+
assert_equal 'value3', res.field.attribute3
|
85
|
+
end
|
86
|
+
|
87
|
+
should "extract links to an array" do
|
88
|
+
xmls = build_xml_string do |xml|
|
89
|
+
xml.instruct!
|
90
|
+
xml.user do
|
91
|
+
xml.id 123
|
92
|
+
xml.link({:rel => 'alternate', :href => 'http://www.pointing-to-something.com', :type => 'text/html'})
|
93
|
+
xml.link({:rel => 'self', :href => 'http://www.pointing-to-self-something.com', :type => 'application/xml'})
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
res = @handler.decode_response(xmls)
|
98
|
+
assert res.is_a?(Partigirb::PartigiStruct)
|
99
|
+
assert_not_nil res.links
|
100
|
+
assert res.links.is_a?(Array)
|
101
|
+
assert_equal 'alternate', res.links.first.rel
|
102
|
+
assert_equal 'self', res.links[1].rel
|
85
103
|
end
|
86
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partigi-partigirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alvaro Bautista
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-07-
|
13
|
+
date: 2009-07-30 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -31,6 +31,8 @@ files:
|
|
31
31
|
- README.rdoc
|
32
32
|
- Rakefile
|
33
33
|
- VERSION
|
34
|
+
- examples/last_reviews_summary.rb
|
35
|
+
- examples/who_ignores_me.rb
|
34
36
|
- lib/partigirb.rb
|
35
37
|
- lib/partigirb/client.rb
|
36
38
|
- lib/partigirb/core_ext.rb
|
@@ -88,3 +90,5 @@ test_files:
|
|
88
90
|
- test/test_helper.rb
|
89
91
|
- test/transport_test.rb
|
90
92
|
- test/xml_handler_test.rb
|
93
|
+
- examples/last_reviews_summary.rb
|
94
|
+
- examples/who_ignores_me.rb
|