pingfm 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pingfm (2.0.0)
4
+ pingfm (2.1.2)
5
5
  slop
6
6
 
7
7
  GEM
@@ -4,5 +4,5 @@ require 'pingfm/client'
4
4
  require 'pingfm/config'
5
5
 
6
6
  module Pingfm
7
- VERSION = '2.1.0'
7
+ VERSION = '2.1.2'
8
8
  end
@@ -2,6 +2,7 @@ require 'net/http'
2
2
  require 'rexml/document' # TODO: Rewrite this to use something faster (Nokogiri, possibly).
3
3
 
4
4
  module Pingfm
5
+ # TODO: The status_ok and status_fail methods need a little thought.
5
6
  class Client
6
7
 
7
8
  # The registered API key for the Ping.fm Ruby library client.
@@ -22,7 +23,7 @@ module Pingfm
22
23
  #
23
24
  # Optional arguments:
24
25
  # [limit] Limit the results returned; default is 25.
25
- # [order] = Which direction to order the returned results by date; default is descending.
26
+ # [order] Which direction to order the returned results by date; default is 'DESC'.
26
27
  #
27
28
  # If successful returns:
28
29
  # {'status' => 'OK', 'messages' => [{'id' => 'messageid', 'method' => 'messsagemethod', 'rfc' => 'date', 'unix' => 'date', 'title' => 'messagetitle', 'body' => 'messagebody', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
@@ -62,6 +63,37 @@ module Pingfm
62
63
  end
63
64
  end
64
65
 
66
+ # Returns the last +limit+ number of links the user has shortened and posted through Ping.fm.
67
+ #
68
+ # Optional arguments:
69
+ # [limit] Limit the results returned; default is 25.
70
+ # [order] The sort order of the results; default is 'DESC'.
71
+ #
72
+ # If successful returns:
73
+ # {'status' => 'OK', 'links' => [{ 'short' => 'http://ping.fm/}, ...]}
74
+ def links(limit = 25, order = 'DESC')
75
+ response = get_response('user.links', 'limit' => limit, 'order' => order)
76
+ if response.elements['rsp'].attributes['status'] == 'OK'
77
+ links = []
78
+ response.elements.each('rsp/links/link') do |link|
79
+ links << {
80
+ 'date' => link.elements['date'].attributes['rfc'],
81
+ 'short' => link.elements['short'].text,
82
+ 'long' => link.elements['long'].text,
83
+ }
84
+ end
85
+ status_ok('links' => links)
86
+ else
87
+ status_fail(response)
88
+ end
89
+ end
90
+
91
+ def url_create
92
+ end
93
+
94
+ def url_resolve
95
+ end
96
+
65
97
  # Posts a message to the user's Ping.fm services.
66
98
  #
67
99
  # Arguments:
@@ -99,7 +131,7 @@ module Pingfm
99
131
  def services
100
132
  response = get_response('user.services')
101
133
  if response.elements['rsp'].attributes['status'] == 'OK'
102
- services = status_ok()
134
+ services = status_ok
103
135
  services['services'] = []
104
136
  response.elements.each('rsp/services/service') do |service|
105
137
  services['services'].push({'id' => service.attributes['id'],
@@ -188,6 +220,17 @@ module Pingfm
188
220
  end
189
221
  end
190
222
 
223
+ # Returns the full user app key from the provided <tt>mobile_key</tt>.
224
+ def user_key(mobile_key)
225
+ response = get_response('user.key', 'mobile_key' => mobile_key)
226
+ if response.elements['rsp'].attributes['status'] == 'OK'
227
+ app_key = response.elements['rsp'].elements['key'].text
228
+ status_ok('app_key' => app_key)
229
+ else
230
+ status_fail(response)
231
+ end
232
+ end
233
+
191
234
  # Validates the API key and user APP key.
192
235
  #
193
236
  # If successful returns:
@@ -221,13 +264,13 @@ module Pingfm
221
264
  end
222
265
 
223
266
  # Successful response.
224
- def status_ok
225
- return {'status' => 'OK'}
267
+ def status_ok(info = {})
268
+ return {'status' => 'OK'}.merge(info)
226
269
  end
227
270
 
228
271
  # Failed response.
229
272
  def status_fail(response)
230
- if response.elements.include? 'rsp/message'
273
+ if response.elements.include?('rsp/message')
231
274
  message = response.elements['rsp/message'].text
232
275
  else
233
276
  message = "Unknown error from Ping.fm."
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Pingfm
2
4
  class ConfigNotFound < Exception; end
3
5
 
@@ -1,5 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # TODO: These specs kinda suck.
4
+
3
5
  describe Pingfm::Client do
4
6
  it 'should have an API_URL' do
5
7
  Pingfm::Client::API_URL.should_not be_nil
@@ -158,6 +160,38 @@ describe Pingfm::Client, "with expected results" do
158
160
  result['status'].should eql('OK')
159
161
  end
160
162
 
163
+ it "should get the user app key from the mobile_key" do
164
+ init_user_key_response
165
+
166
+ uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
167
+ @params.merge!('mobile_key' => @mobile_key)
168
+
169
+ http_resp = mock('response')
170
+ http_resp.should_receive(:body).and_return(@response)
171
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
172
+
173
+ result = @client.user_key(@mobile_key)
174
+ result.should_not be_empty
175
+ result['status'].should_not be_nil
176
+ result['app_key'].should == @app_key
177
+ end
178
+
179
+ it "should get the user's links" do
180
+ init_user_links_response
181
+
182
+ uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
183
+ @params.merge!('limit' => 25, 'order' => 'DESC')
184
+
185
+ http_resp = mock('response')
186
+ http_resp.should_receive(:body).and_return(@response)
187
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
188
+
189
+ result = @client.links
190
+ result.should_not be_empty
191
+ result['status'].should_not be_nil
192
+ result['links'].should_not be_empty
193
+ end
194
+
161
195
  end
162
196
 
163
197
  describe Pingfm::Client, "with error messages" do
@@ -54,6 +54,7 @@ EOXML
54
54
  def init_system_services_response
55
55
  @service_type = 'system.services'
56
56
  @response = <<EOXML
57
+ <?xml version="1.0"?>
57
58
  <rsp status="OK">
58
59
  <transaction>12345</transaction>
59
60
  <method>system.services</method>
@@ -99,7 +100,7 @@ EOXML
99
100
  def init_latest_response
100
101
  @service_type = 'user.latest'
101
102
  @response = <<EOXML
102
- <?xml version="1.0"?>
103
+ <?xml version="1.0"?>
103
104
  <rsp status="OK">
104
105
  <transaction>12345</transaction>
105
106
  <method>user.latest</method>
@@ -136,6 +137,43 @@ EOXML
136
137
  </message>
137
138
  </messages>
138
139
  </rsp>
140
+ EOXML
141
+ end
142
+
143
+ def init_user_links_response
144
+ @service_type = 'user.links'
145
+ @response = <<EOXML
146
+ <?xml version="1.0"?>
147
+ <rsp status="OK">
148
+ <transaction>12345</transaction>
149
+ <method>user.links</method>
150
+ <links>
151
+ <link>
152
+ <date rfc="Mon, 14 Sep 2009 01:53:12 -0500" unix="1252911192" />
153
+ <short>http://ping.fm/1souk</short>
154
+ <long>http://www.techcrunch.com/2009/09/13/intuit-to-acquire-former-techcrunch50-winner-mint-for-170-million/</long>
155
+ </link>
156
+ <link>
157
+ <date rfc="Mon, 14 Sep 2009 00:26:10 -0500" unix="1252905970" />
158
+ <short>http://ping.fm/U5azR</short>
159
+ <long>http://www.wired.com/wiredscience/2009/09/gallery_dinoauction/</long>
160
+ </link>
161
+ </links>
162
+ </rsp>
163
+ EOXML
164
+ end
165
+
166
+ def init_user_key_response
167
+ @service_type = 'user.key'
168
+ @app_key = 'USER_APP_KEY'
169
+ @mobile_key = 'MOBILE_KEY'
170
+ @response = <<EOXML
171
+ <?xml version="1.0"?>
172
+ <rsp status="OK">
173
+ <transaction>12345</transaction>
174
+ <method>user.key</method>
175
+ <key>#{@app_key}</key>
176
+ </rsp>
139
177
  EOXML
140
178
  end
141
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-06-12 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: slop
18
- requirement: &76760630 !ruby/object:Gem::Requirement
18
+ requirement: &76732520 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *76760630
26
+ version_requirements: *76732520
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
- requirement: &76759860 !ruby/object:Gem::Requirement
29
+ requirement: &76731170 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 2.6.0
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *76759860
37
+ version_requirements: *76731170
38
38
  description: Ping.fm (http://ping.fm) is a simple service that makes updating your
39
39
  social networks a snap, and this it's Ruby library.
40
40
  email: