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 +4 -0
- data/bin/pingfm +3 -2
- data/lib/pingfm.rb +1 -1
- data/lib/pingfm/keyloader.rb +4 -1
- data/spec/pingfm_spec.rb +152 -2
- data/spec/spec_helper.rb +23 -0
- data/tasks/setup.rb +1 -1
- metadata +3 -3
data/History.txt
CHANGED
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'
|
@@ -30,8 +31,8 @@ if s['status'] == 'OK'
|
|
30
31
|
|
31
32
|
post_result = pingfm.post(status)
|
32
33
|
|
33
|
-
if
|
34
|
-
puts
|
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.rb
CHANGED
data/lib/pingfm/keyloader.rb
CHANGED
@@ -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
|
-
|
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/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
|
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, "
|
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
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krunoslav Husak
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2008-
|
14
|
+
date: 2008-12-26 00:00:00 -06:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
requirements: []
|
76
76
|
|
77
77
|
rubyforge_project: pingfm
|
78
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.3.1
|
79
79
|
signing_key:
|
80
80
|
specification_version: 2
|
81
81
|
summary: Ping.fm (http://ping.fm) is a simple service that makes updating your social networks a snap, and this it's Ruby library.
|