Permalink
Browse files

adding Client#links()

  • Loading branch information...
1 parent a028415 commit 1953c3cb5075f86f2985a282bf5ebf6b0d6f8ca3 @Oshuma committed Jun 12, 2011
Showing with 73 additions and 3 deletions.
  1. +1 −1 Gemfile.lock
  2. +33 −2 lib/pingfm/client.rb
  3. +16 −0 spec/pingfm/client_spec.rb
  4. +23 −0 spec/spec_helper.rb
View
2 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- pingfm (2.0.0)
+ pingfm (2.1.2)
slop
GEM
View
35 lib/pingfm/client.rb
@@ -23,7 +23,7 @@ def initialize(user_app_key)
#
# Optional arguments:
# [limit] Limit the results returned; default is 25.
- # [order] = Which direction to order the returned results by date; default is descending.
+ # [order] Which direction to order the returned results by date; default is 'DESC'.
#
# If successful returns:
# {'status' => 'OK', 'messages' => [{'id' => 'messageid', 'method' => 'messsagemethod', 'rfc' => 'date', 'unix' => 'date', 'title' => 'messagetitle', 'body' => 'messagebody', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
@@ -63,6 +63,37 @@ def latest(limit = 25, order = 'DESC')
end
end
+ # Returns the last +limit+ number of links the user has shortened and posted through Ping.fm.
+ #
+ # Optional arguments:
+ # [limit] Limit the results returned; default is 25.
+ # [order] The sort order of the results; default is 'DESC'.
+ #
+ # If successful returns:
+ # {'status' => 'OK', 'links' => [{ 'short' => 'http://ping.fm/}, ...]}
+ def links(limit = 25, order = 'DESC')
+ response = get_response('user.links', 'limit' => limit, 'order' => order)
+ if response.elements['rsp'].attributes['status'] == 'OK'
+ links = []
+ response.elements.each('rsp/links/link') do |link|
+ links << {
+ 'date' => link.elements['date'].attributes['rfc'],
+ 'short' => link.elements['short'].text,
+ 'long' => link.elements['long'].text,
+ }
+ end
+ status_ok('links' => links)
+ else
+ status_fail(response)
+ end
+ end
+
+ def url_create
+ end
+
+ def url_resolve
+ end
+
# Posts a message to the user's Ping.fm services.
#
# Arguments:
@@ -239,7 +270,7 @@ def status_ok(info = {})
# Failed response.
def status_fail(response)
- if response.elements.include? 'rsp/message'
+ if response.elements.include?('rsp/message')
message = response.elements['rsp/message'].text
else
message = "Unknown error from Ping.fm."
View
16 spec/pingfm/client_spec.rb
@@ -176,6 +176,22 @@
result['app_key'].should == @app_key
end
+ it "should get the user's links" do
+ init_user_links_response
+
+ uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
+ @params.merge!('limit' => 25, 'order' => 'DESC')
+
+ http_resp = mock('response')
+ http_resp.should_receive(:body).and_return(@response)
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
+
+ result = @client.links
+ result.should_not be_empty
+ result['status'].should_not be_nil
+ result['links'].should_not be_empty
+ end
+
end
describe Pingfm::Client, "with error messages" do
View
23 spec/spec_helper.rb
@@ -140,6 +140,29 @@ def init_latest_response
EOXML
end
+ def init_user_links_response
+ @service_type = 'user.links'
+ @response = <<EOXML
+<?xml version="1.0"?>
+<rsp status="OK">
+ <transaction>12345</transaction>
+ <method>user.links</method>
+ <links>
+ <link>
+ <date rfc="Mon, 14 Sep 2009 01:53:12 -0500" unix="1252911192" />
+ <short>http://ping.fm/1souk</short>
+ <long>http://www.techcrunch.com/2009/09/13/intuit-to-acquire-former-techcrunch50-winner-mint-for-170-million/</long>
+ </link>
+ <link>
+ <date rfc="Mon, 14 Sep 2009 00:26:10 -0500" unix="1252905970" />
+ <short>http://ping.fm/U5azR</short>
+ <long>http://www.wired.com/wiredscience/2009/09/gallery_dinoauction/</long>
+ </link>
+ </links>
+</rsp>
+EOXML
+ end
+
def init_user_key_response
@service_type = 'user.key'
@app_key = 'USER_APP_KEY'

0 comments on commit 1953c3c

Please sign in to comment.