Oshuma-pingfm 1.0.0 → 1.0.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/History.txt CHANGED
@@ -1,4 +1,8 @@
1
- == 1.0.0 / 2008-08-30
1
+ == 1.0.1 / 2008-12-26
2
+
3
+ * Fixed small bug in the command-line script.
4
+
5
+ == 1.0.0 / 2008-09-25
2
6
 
3
7
  * first gem release
4
8
  * woohoo!
data/bin/pingfm CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # TODO: Eventually add some flags to support all Ping.fm functionality.
2
3
 
3
4
  # TODO: Move this into a YAML config?
4
5
  API_KEY = '5fcb8b7041d5c32c7e1e60dc076989ba'
@@ -9,7 +10,7 @@ require File.expand_path(
9
10
  keyloader = ::Pingfm::Keyloader.new
10
11
  unless keyloader.has_keys?
11
12
  keyloader.api_key = API_KEY
12
- puts 'Enter your Ping.fm User API key (http://ping.fm/key/): '
13
+ print 'Enter your Ping.fm User API key (http://ping.fm/key/): '
13
14
  keyloader.app_key = STDIN.gets.chomp
14
15
  keyloader.save
15
16
  end
@@ -30,8 +31,8 @@ if s['status'] == 'OK'
30
31
 
31
32
  post_result = pingfm.post(status)
32
33
 
33
- if s['status'] == 'FAIL'
34
- puts s['message']
34
+ if post_result['status'] == 'FAIL'
35
+ puts post_result['message']
35
36
  else
36
37
  puts 'Message sent.'
37
38
  end
data/lib/pingfm/client.rb CHANGED
@@ -29,9 +29,32 @@ module Pingfm
29
29
  end
30
30
  end
31
31
 
32
+ # Return a complete list of supported services
33
+ # if successful returns:
34
+ # {'status' => 'OK', 'services' => [{'id' => 'serviceid', 'name' => 'servicename', 'trigger' => 'servicetrigger', 'url' => 'serviceurl', 'icon' => 'serviceicon'}, ...]}
35
+ # if unsuccessful returns:
36
+ # {'status' => 'FAIL', 'message' => 'message what went wrong'}
37
+ def system_services
38
+ response = get_response('system.services')
39
+ if response.elements['rsp'].attributes['status'] == 'OK'
40
+ services = status_ok
41
+ services['services'] = []
42
+ response.elements.each('rsp/services/service') do |service|
43
+ services['services'].push({'id' => service.attributes['id'],
44
+ 'name' => service.attributes['name'],
45
+ 'trigger' => service.elements['trigger'].text,
46
+ 'url' => service.elements['url'].text,
47
+ 'icon' => service.elements['icon'].text})
48
+ end
49
+ return services
50
+ else
51
+ return status_fail(response)
52
+ end
53
+ end
54
+
32
55
  # Returns a list of services the user has set up through Ping.fm
33
56
  # if successful returns:
34
- # {'status' => 'OK', services = [{'id' => 'serviceid', 'name' => 'servicename', 'methods' => 'status,blog'}, ...]}
57
+ # {'status' => 'OK', 'services' => [{'id' => 'serviceid', 'name' => 'servicename', 'trigger' => 'servicetrigger', 'url' => 'serviceurl', 'icon' => 'serviceicon', 'methods' => 'status,blog'}, ...]}
35
58
  # if unsuccessful returns:
36
59
  # {'status' => 'FAIL', 'message' => 'message what went wrong'}
37
60
  def services
@@ -40,7 +63,12 @@ module Pingfm
40
63
  services = status_ok()
41
64
  services['services'] = []
42
65
  response.elements.each('rsp/services/service') do |service|
43
- services['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name'], 'methods' => service.elements['methods'].text})
66
+ services['services'].push({'id' => service.attributes['id'],
67
+ 'name' => service.attributes['name'],
68
+ 'trigger' => service.elements['trigger'].text,
69
+ 'url' => service.elements['url'].text,
70
+ 'icon' => service.elements['icon'].text,
71
+ 'methods' => service.elements['methods'].text})
44
72
  end
45
73
  return services
46
74
  else
@@ -50,7 +78,7 @@ module Pingfm
50
78
 
51
79
  # Returns a user's custom triggers
52
80
  # if successful returns:
53
- # {'status' => 'OK', triggers = [{'id' => 'triggerid', 'method' => 'triggermethod', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
81
+ # {'status' => 'OK', 'triggers' => [{'id' => 'triggerid', 'method' => 'triggermethod', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
54
82
  # if unsuccessful returns:
55
83
  # {'status' => 'FAIL', 'message' => 'message what went wrong'}
56
84
  def triggers
@@ -96,6 +124,11 @@ module Pingfm
96
124
  else
97
125
  latest['messages'].last['title'] = ''
98
126
  end
127
+ if message.elements['location'] != nil
128
+ latest['messages'].last['location'] = message.elements['location'].text
129
+ else
130
+ latest['messages'].last['location'] = ''
131
+ end
99
132
  latest['messages'].last['body'] = message.elements['*/body'].text
100
133
  latest['messages'].last['services'] = []
101
134
  message.elements.each('services/service') do |service|
@@ -16,7 +16,10 @@ module Pingfm
16
16
  # ping.fm uses this as the key for the user
17
17
  attr_accessor :app_key
18
18
 
19
- def initialize(keyfile = File.expand_path('~/.pingfm_keys.yml'))
19
+ KEY_PATH = (RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'])
20
+ KEY_FILE = '.pingfm_keys.yml'
21
+
22
+ def initialize(keyfile = File.expand_path(File.join(KEY_PATH, KEY_FILE)))
20
23
  @api_key = nil
21
24
  @keyfile = keyfile
22
25
 
data/lib/pingfm.rb CHANGED
@@ -7,7 +7,7 @@ unless defined? Pingfm
7
7
  module Pingfm
8
8
 
9
9
  # :stopdoc:
10
- VERSION = '1.0.0'
10
+ VERSION = '1.0.1'
11
11
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
12
12
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
13
13
  # :startdoc:
data/spec/pingfm_spec.rb CHANGED
@@ -1,8 +1,24 @@
1
1
  # $Id$
2
+ # TODO: LOTS of repetition here that can probably be refactored a bit.
3
+ # TODO: Split these specs into a pingfm/ subdirectory, moving the client specs into their own file.
2
4
 
3
5
  require File.join(File.dirname(__FILE__), %w[spec_helper])
4
6
 
5
- describe Pingfm::Client, " with expected results" do
7
+ describe Pingfm, 'main module' do
8
+ it 'should return the version string' do
9
+ Pingfm.version.should be_a_kind_of(String)
10
+ end
11
+
12
+ it 'should return the library path' do
13
+ Pingfm.libpath.should eql(Pingfm::LIBPATH)
14
+ end
15
+
16
+ it 'should return the path to the library' do
17
+ Pingfm.path.should eql(Pingfm::PATH)
18
+ end
19
+ end
20
+
21
+ describe Pingfm::Client, "with expected results" do
6
22
 
7
23
  before(:each) do
8
24
  @client = Pingfm::Client.new('a','b')
@@ -47,6 +63,26 @@ describe Pingfm::Client, " with expected results" do
47
63
  result['services'].first['id'].should eql('twitter')
48
64
  end
49
65
 
66
+ it "should list the system services" do
67
+ init_system_services_response
68
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
69
+
70
+ # mock the http call
71
+ http_resp = mock('response')
72
+ http_resp.should_receive(:body).and_return(@response)
73
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
74
+
75
+ # call and verify
76
+ result = @client.system_services
77
+ result.should_not be_empty
78
+ result['status'].should_not be_nil
79
+ result['status'].should eql('OK')
80
+ result['services'].should_not be_nil
81
+ result['services'].should_not be_empty
82
+ result['services'].length.should eql(2)
83
+ result['services'].first['id'].should eql('bebo')
84
+ end
85
+
50
86
  it "should list the user's custom triggers" do
51
87
  init_trigger_response
52
88
 
@@ -88,6 +124,7 @@ describe Pingfm::Client, " with expected results" do
88
124
  result['messages'].should_not be_empty
89
125
  result['messages'].length.should eql(3)
90
126
  result['messages'].first['id'].should eql('12345')
127
+ result['messages'].last['location'].should_not be_empty
91
128
  end
92
129
 
93
130
  it "should post a message to the service" do
@@ -131,7 +168,7 @@ describe Pingfm::Client, " with expected results" do
131
168
 
132
169
  end
133
170
 
134
- describe Pingfm::Client, " with error messages" do
171
+ describe Pingfm::Client, "with error messages" do
135
172
  before(:each) do
136
173
  @client = Pingfm::Client.new('a','b')
137
174
  @params = {'api_key' => 'a', 'user_app_key' => 'b'}
@@ -154,6 +191,119 @@ describe Pingfm::Client, " with error messages" do
154
191
  result['status'].should eql('FAIL')
155
192
  result['message'].should_not be_nil
156
193
  end
194
+
195
+ it "should handle a failed system services cleanly" do
196
+ init_fail_response 'system.services'
197
+
198
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
199
+
200
+ # mock the http call
201
+ http_resp = mock('response')
202
+ http_resp.should_receive(:body).and_return(@response)
203
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
204
+
205
+ # call and verify
206
+ result = @client.system_services
207
+ result.should_not be_empty
208
+ result['status'].should_not be_nil
209
+ result['status'].should eql('FAIL')
210
+ result['message'].should_not be_nil
211
+ end
212
+
213
+ it "should handle a failed user's services cleanly" do
214
+ init_fail_response 'user.services'
215
+
216
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
217
+
218
+ # mock the http call
219
+ http_resp = mock('response')
220
+ http_resp.should_receive(:body).and_return(@response)
221
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
222
+
223
+ # call and verify
224
+ result = @client.services
225
+ result.should_not be_empty
226
+ result['status'].should_not be_nil
227
+ result['status'].should eql('FAIL')
228
+ result['message'].should_not be_nil
229
+ end
230
+
231
+ it "should handle a failed user's triggers cleanly" do
232
+ init_fail_response 'user.triggers'
233
+
234
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
235
+
236
+ # mock the http call
237
+ http_resp = mock('response')
238
+ http_resp.should_receive(:body).and_return(@response)
239
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
240
+
241
+ # call and verify
242
+ result = @client.triggers
243
+ result.should_not be_empty
244
+ result['status'].should_not be_nil
245
+ result['status'].should eql('FAIL')
246
+ result['message'].should_not be_nil
247
+ end
248
+
249
+ it "should handle a failed user's latest messages cleanly" do
250
+ init_fail_response 'user.latest'
251
+
252
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
253
+
254
+ # mock the http call
255
+ http_resp = mock('response')
256
+ http_resp.should_receive(:body).and_return(@response)
257
+ @params.merge!('order' => 'DESC', 'limit' => 25)
258
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
259
+
260
+ # call and verify
261
+ result = @client.latest
262
+ result.should_not be_empty
263
+ result['status'].should_not be_nil
264
+ result['status'].should eql('FAIL')
265
+ result['message'].should_not be_nil
266
+ end
267
+
268
+ it "should handle a failed user post cleanly" do
269
+ init_fail_response 'user.post'
270
+
271
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
272
+
273
+ # mock the http call
274
+ http_resp = mock('response')
275
+ http_resp.should_receive(:body).and_return(@response)
276
+ @params.merge!({'post_method' => 'default', 'title' => '',
277
+ 'service' => '', 'body' => 'test message', 'debug' => 0})
278
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
279
+
280
+ # call and verify
281
+ result = @client.post('test message')
282
+ result.should_not be_empty
283
+ result['status'].should_not be_nil
284
+ result['status'].should eql('FAIL')
285
+ result['message'].should_not be_nil
286
+ end
287
+
288
+ it "should handle a failed user trigger post cleanly" do
289
+ init_fail_response 'user.tpost'
290
+
291
+ uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
292
+
293
+ # mock the http call
294
+ http_resp = mock('response')
295
+ http_resp.should_receive(:body).and_return(@response)
296
+ @params.merge!({'title' => '', 'body' => 'test message',
297
+ 'trigger' => '@trigger', 'debug' => 0})
298
+ Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
299
+
300
+ # call and verify
301
+ result = @client.tpost('test message', '@trigger')
302
+ result.should_not be_empty
303
+ result['status'].should_not be_nil
304
+ result['status'].should eql('FAIL')
305
+ result['message'].should_not be_nil
306
+ end
157
307
  end
158
308
 
159
309
  # EOF
data/spec/spec_helper.rb CHANGED
@@ -62,6 +62,28 @@ def init_service_response
62
62
  EOXML
63
63
  end
64
64
 
65
+ def init_system_services_response
66
+ @service_type = 'system.services'
67
+ @response = <<EOXML
68
+ <rsp status="OK">
69
+ <transaction>12345</transaction>
70
+ <method>system.services</method>
71
+ <services>
72
+ <service id="bebo" name="Bebo">
73
+ <trigger>@be</trigger>
74
+ <url>http://www.bebo.com/</url>
75
+ <icon>http://p.ping.fm/static/icons/bebo.png</icon>
76
+ </service>
77
+ <service id="blogger" name="Blogger">
78
+ <trigger>@bl</trigger>
79
+ <url>http://www.blogger.com/</url>
80
+ <icon>http://p.ping.fm/static/icons/blogger.png</icon>
81
+ </service>
82
+ </services>
83
+ </rsp>
84
+ EOXML
85
+ end
86
+
65
87
  def init_trigger_response
66
88
  @service_type = 'user.triggers'
67
89
  @response = <<EOXML
@@ -121,6 +143,7 @@ def init_latest_response
121
143
  <content>
122
144
  <body>aXMgdGVzdGluZyBQaW5nLmZtIQ==</body>
123
145
  </content>
146
+ <location>VHVsc2EsIE9L</location>
124
147
  </message>
125
148
  </messages>
126
149
  </rsp>
data/tasks/setup.rb CHANGED
@@ -66,7 +66,7 @@ PROJ = OpenStruct.new(
66
66
  # Rcov
67
67
  :rcov => OpenStruct.new(
68
68
  :dir => 'coverage',
69
- :opts => %w[--sort coverage -T],
69
+ :opts => %w[--sort coverage -T -x rcov.rb],
70
70
  :threshold => 90.0,
71
71
  :threshold_exact => false
72
72
  ),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Oshuma-pingfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krunoslav Husak