pingfm 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/{README → README.rdoc} +40 -50
- data/Rakefile +11 -26
- data/bin/pingfm +37 -31
- data/lib/pingfm.rb +5 -53
- data/lib/pingfm/client.rb +194 -179
- data/lib/pingfm/config.rb +36 -0
- data/pingfm.gemspec +27 -0
- data/spec/pingfm/client_spec.rb +300 -0
- data/spec/pingfm/config_spec.rb +21 -0
- data/spec/pingfm_spec.rb +3 -305
- data/spec/pingfm_spec.yml +2 -0
- data/spec/spec_helper.rb +28 -40
- metadata +63 -60
- data/History.txt +0 -12
- data/Manifest.txt +0 -25
- data/lib/pingfm/keyloader.rb +0 -58
- data/spec/keyloader_spec.rb +0 -43
- data/tasks/ann.rake +0 -81
- data/tasks/bones.rake +0 -21
- data/tasks/gem.rake +0 -126
- data/tasks/git.rake +0 -41
- data/tasks/manifest.rake +0 -49
- data/tasks/notes.rake +0 -28
- data/tasks/post_load.rake +0 -39
- data/tasks/rdoc.rake +0 -51
- data/tasks/rubyforge.rake +0 -57
- data/tasks/setup.rb +0 -268
- data/tasks/spec.rake +0 -55
- data/tasks/svn.rake +0 -48
- data/tasks/test.rake +0 -38
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pingfm
|
2
|
+
class ConfigNotFound < Exception; end
|
3
|
+
|
4
|
+
class Config
|
5
|
+
CONFIG_PATH = (RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'])
|
6
|
+
CONFIG_FILE = File.expand_path(File.join(CONFIG_PATH, '.pingfm.yml'))
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Prompts the user for their API key and saves it.
|
11
|
+
def ask_for_app_key!
|
12
|
+
STDOUT.print 'Enter your Ping.fm User API key (http://ping.fm/key/): '
|
13
|
+
@@config ||= {}
|
14
|
+
@@config['app_key'] = STDIN.gets.chomp
|
15
|
+
save!
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](key)
|
19
|
+
setup! unless defined?(@@config)
|
20
|
+
@@config[key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def save!
|
24
|
+
::File.open(CONFIG_FILE, 'w') do |config_file|
|
25
|
+
::YAML.dump(@@config, config_file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup!(config_file = CONFIG_FILE)
|
30
|
+
raise Pingfm::ConfigNotFound unless File.exists?(config_file)
|
31
|
+
@@config = ::YAML.load_file(config_file)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/pingfm.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.push(File.expand_path("../lib", __FILE__))
|
2
|
+
require 'pingfm'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "pingfm"
|
6
|
+
s.version = Pingfm::VERSION
|
7
|
+
|
8
|
+
s.authors = ["Dale Campbell", "Kevin Williams", "Krunoslav Husak"]
|
9
|
+
s.email = ["oshuma@gmail.com", "kevwil@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/Oshuma/pingfm"
|
11
|
+
|
12
|
+
s.rubyforge_project = 'pingfm'
|
13
|
+
|
14
|
+
s.summary = %q{A Ping.fm Ruby library.}
|
15
|
+
s.description = %q{Ping.fm (http://ping.fm) is a simple service that makes updating your social networks a snap, and this it's Ruby library.}
|
16
|
+
|
17
|
+
s.add_dependency('slop')
|
18
|
+
s.add_development_dependency('rspec', '>= 2.6.0')
|
19
|
+
|
20
|
+
s.has_rdoc = true
|
21
|
+
s.rdoc_options = ['--inline-source']
|
22
|
+
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pingfm::Client do
|
4
|
+
it 'should have an API_URL' do
|
5
|
+
Pingfm::Client::API_URL.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should have an API_KEY' do
|
9
|
+
Pingfm::Client::API_KEY.should_not be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Pingfm::Client, "with expected results" do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@client = Pingfm::Client.new('b')
|
17
|
+
@params = {'api_key' => Pingfm::Client::API_KEY, 'user_app_key' => 'b'}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should validate keys successfully" do
|
21
|
+
init_ok_response 'user.validate'
|
22
|
+
|
23
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
24
|
+
|
25
|
+
# mock the http call
|
26
|
+
http_resp = mock('response')
|
27
|
+
http_resp.should_receive(:body).and_return(@response)
|
28
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
29
|
+
|
30
|
+
# call and verify
|
31
|
+
result = @client.validate
|
32
|
+
result.should_not be_empty
|
33
|
+
result['status'].should_not be_nil
|
34
|
+
result['status'].should eql('OK')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should list the user's services properly" do
|
38
|
+
init_service_response
|
39
|
+
|
40
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
41
|
+
|
42
|
+
# mock the http call
|
43
|
+
http_resp = mock('response')
|
44
|
+
http_resp.should_receive(:body).and_return(@response)
|
45
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
46
|
+
|
47
|
+
# call and verify
|
48
|
+
result = @client.services
|
49
|
+
result.should_not be_empty
|
50
|
+
result['status'].should_not be_nil
|
51
|
+
result['status'].should eql('OK')
|
52
|
+
result['services'].should_not be_nil
|
53
|
+
result['services'].should_not be_empty
|
54
|
+
result['services'].length.should eql(2)
|
55
|
+
result['services'].first['id'].should eql('twitter')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should list the system services" do
|
59
|
+
init_system_services_response
|
60
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
61
|
+
|
62
|
+
# mock the http call
|
63
|
+
http_resp = mock('response')
|
64
|
+
http_resp.should_receive(:body).and_return(@response)
|
65
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
66
|
+
|
67
|
+
# call and verify
|
68
|
+
result = @client.system_services
|
69
|
+
result.should_not be_empty
|
70
|
+
result['status'].should_not be_nil
|
71
|
+
result['status'].should eql('OK')
|
72
|
+
result['services'].should_not be_nil
|
73
|
+
result['services'].should_not be_empty
|
74
|
+
result['services'].length.should eql(2)
|
75
|
+
result['services'].first['id'].should eql('bebo')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should list the user's custom triggers" do
|
79
|
+
init_trigger_response
|
80
|
+
|
81
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
82
|
+
|
83
|
+
# mock the http call
|
84
|
+
http_resp = mock('response')
|
85
|
+
http_resp.should_receive(:body).and_return(@response)
|
86
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
87
|
+
|
88
|
+
# call and verify
|
89
|
+
result = @client.triggers
|
90
|
+
result.should_not be_empty
|
91
|
+
result['status'].should_not be_nil
|
92
|
+
result['status'].should eql('OK')
|
93
|
+
result['triggers'].should_not be_nil
|
94
|
+
result['triggers'].should_not be_empty
|
95
|
+
result['triggers'].length.should eql(2)
|
96
|
+
result['triggers'].first['id'].should eql('twt')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should list the user's recent posts" do
|
100
|
+
init_latest_response
|
101
|
+
|
102
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
103
|
+
@params.merge!('limit'=>5,'order'=>'DESC')
|
104
|
+
|
105
|
+
# mock the http call
|
106
|
+
http_resp = mock('response')
|
107
|
+
http_resp.should_receive(:body).and_return(@response)
|
108
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
109
|
+
|
110
|
+
# call and verify
|
111
|
+
result = @client.latest(5)
|
112
|
+
result.should_not be_empty
|
113
|
+
result['status'].should_not be_nil
|
114
|
+
result['status'].should eql('OK')
|
115
|
+
result['messages'].should_not be_nil
|
116
|
+
result['messages'].should_not be_empty
|
117
|
+
result['messages'].length.should eql(3)
|
118
|
+
result['messages'].first['id'].should eql('12345')
|
119
|
+
result['messages'].last['location'].should_not be_empty
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should post a message to the service" do
|
123
|
+
init_ok_response 'user.post'
|
124
|
+
|
125
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
126
|
+
@params.merge!('body' => 'foo', 'title' => '',
|
127
|
+
'post_method' => 'default', 'service' => '',
|
128
|
+
'debug' => 0)
|
129
|
+
|
130
|
+
# mock the http call
|
131
|
+
http_resp = mock('response')
|
132
|
+
http_resp.should_receive(:body).and_return(@response)
|
133
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
134
|
+
|
135
|
+
# call and verify
|
136
|
+
result = @client.post('foo')
|
137
|
+
result.should_not be_empty
|
138
|
+
result['status'].should_not be_nil
|
139
|
+
result['status'].should eql('OK')
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should post a message to the service using a trigger" do
|
143
|
+
init_ok_response 'user.tpost'
|
144
|
+
|
145
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
146
|
+
@params.merge!('body' => 'foo', 'title' => '',
|
147
|
+
'trigger' => 'twt', 'debug' => 0)
|
148
|
+
|
149
|
+
# mock the http call
|
150
|
+
http_resp = mock('response')
|
151
|
+
http_resp.should_receive(:body).and_return(@response)
|
152
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
153
|
+
|
154
|
+
# call and verify
|
155
|
+
result = @client.tpost('foo','twt')
|
156
|
+
result.should_not be_empty
|
157
|
+
result['status'].should_not be_nil
|
158
|
+
result['status'].should eql('OK')
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe Pingfm::Client, "with error messages" do
|
164
|
+
|
165
|
+
before(:each) do
|
166
|
+
@client = Pingfm::Client.new('b')
|
167
|
+
@params = {'api_key' => Pingfm::Client::API_KEY, 'user_app_key' => 'b'}
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should handle a failed validate cleanly" do
|
171
|
+
init_fail_response 'user.validate'
|
172
|
+
|
173
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
174
|
+
|
175
|
+
# mock the http call
|
176
|
+
http_resp = mock('response')
|
177
|
+
http_resp.should_receive(:body).and_return(@response)
|
178
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
179
|
+
|
180
|
+
# call and verify
|
181
|
+
result = @client.validate
|
182
|
+
result.should_not be_empty
|
183
|
+
result['status'].should_not be_nil
|
184
|
+
result['status'].should eql('FAIL')
|
185
|
+
result['message'].should_not be_nil
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should handle a failed system services cleanly" do
|
189
|
+
init_fail_response 'system.services'
|
190
|
+
|
191
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
192
|
+
|
193
|
+
# mock the http call
|
194
|
+
http_resp = mock('response')
|
195
|
+
http_resp.should_receive(:body).and_return(@response)
|
196
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
197
|
+
|
198
|
+
# call and verify
|
199
|
+
result = @client.system_services
|
200
|
+
result.should_not be_empty
|
201
|
+
result['status'].should_not be_nil
|
202
|
+
result['status'].should eql('FAIL')
|
203
|
+
result['message'].should_not be_nil
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should handle a failed user's services cleanly" do
|
207
|
+
init_fail_response 'user.services'
|
208
|
+
|
209
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
210
|
+
|
211
|
+
# mock the http call
|
212
|
+
http_resp = mock('response')
|
213
|
+
http_resp.should_receive(:body).and_return(@response)
|
214
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
215
|
+
|
216
|
+
# call and verify
|
217
|
+
result = @client.services
|
218
|
+
result.should_not be_empty
|
219
|
+
result['status'].should_not be_nil
|
220
|
+
result['status'].should eql('FAIL')
|
221
|
+
result['message'].should_not be_nil
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should handle a failed user's triggers cleanly" do
|
225
|
+
init_fail_response 'user.triggers'
|
226
|
+
|
227
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
228
|
+
|
229
|
+
# mock the http call
|
230
|
+
http_resp = mock('response')
|
231
|
+
http_resp.should_receive(:body).and_return(@response)
|
232
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
233
|
+
|
234
|
+
# call and verify
|
235
|
+
result = @client.triggers
|
236
|
+
result.should_not be_empty
|
237
|
+
result['status'].should_not be_nil
|
238
|
+
result['status'].should eql('FAIL')
|
239
|
+
result['message'].should_not be_nil
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should handle a failed user's latest messages cleanly" do
|
243
|
+
init_fail_response 'user.latest'
|
244
|
+
|
245
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
246
|
+
|
247
|
+
# mock the http call
|
248
|
+
http_resp = mock('response')
|
249
|
+
http_resp.should_receive(:body).and_return(@response)
|
250
|
+
@params.merge!('order' => 'DESC', 'limit' => 25)
|
251
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
252
|
+
|
253
|
+
# call and verify
|
254
|
+
result = @client.latest
|
255
|
+
result.should_not be_empty
|
256
|
+
result['status'].should_not be_nil
|
257
|
+
result['status'].should eql('FAIL')
|
258
|
+
result['message'].should_not be_nil
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should handle a failed user post cleanly" do
|
262
|
+
init_fail_response 'user.post'
|
263
|
+
|
264
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
265
|
+
|
266
|
+
# mock the http call
|
267
|
+
http_resp = mock('response')
|
268
|
+
http_resp.should_receive(:body).and_return(@response)
|
269
|
+
@params.merge!({'post_method' => 'default', 'title' => '',
|
270
|
+
'service' => '', 'body' => 'test message', 'debug' => 0})
|
271
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
272
|
+
|
273
|
+
# call and verify
|
274
|
+
result = @client.post('test message')
|
275
|
+
result.should_not be_empty
|
276
|
+
result['status'].should_not be_nil
|
277
|
+
result['status'].should eql('FAIL')
|
278
|
+
result['message'].should_not be_nil
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should handle a failed user trigger post cleanly" do
|
282
|
+
init_fail_response 'user.tpost'
|
283
|
+
|
284
|
+
uri = URI.parse "#{Pingfm::Client::API_URL}/#{@service_type}"
|
285
|
+
|
286
|
+
# mock the http call
|
287
|
+
http_resp = mock('response')
|
288
|
+
http_resp.should_receive(:body).and_return(@response)
|
289
|
+
@params.merge!({'title' => '', 'body' => 'test message',
|
290
|
+
'trigger' => '@trigger', 'debug' => 0})
|
291
|
+
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
292
|
+
|
293
|
+
# call and verify
|
294
|
+
result = @client.tpost('test message', '@trigger')
|
295
|
+
result.should_not be_empty
|
296
|
+
result['status'].should_not be_nil
|
297
|
+
result['status'].should eql('FAIL')
|
298
|
+
result['message'].should_not be_nil
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pingfm::Config do
|
4
|
+
|
5
|
+
SPEC_CONFIG_FILE = "#{File.dirname(__FILE__)}/../pingfm_spec.yml"
|
6
|
+
|
7
|
+
it 'has a CONFIG_PATH' do
|
8
|
+
Pingfm::Config::CONFIG_PATH.should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has a CONFIG_FILE' do
|
12
|
+
Pingfm::Config::CONFIG_FILE.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'loads the given config file' do
|
16
|
+
Pingfm::Config.setup!(SPEC_CONFIG_FILE)
|
17
|
+
@config = ::YAML.load_file(SPEC_CONFIG_FILE)
|
18
|
+
Pingfm::Config['app_key'].should == @config['app_key']
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/pingfm_spec.rb
CHANGED
@@ -1,309 +1,7 @@
|
|
1
|
-
|
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.
|
1
|
+
require 'spec_helper'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
describe Pingfm, 'main module' do
|
3
|
+
describe Pingfm do
|
8
4
|
it 'should return the version string' do
|
9
|
-
Pingfm.
|
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)
|
5
|
+
Pingfm::VERSION.should be_a_kind_of(String)
|
18
6
|
end
|
19
7
|
end
|
20
|
-
|
21
|
-
describe Pingfm::Client, "with expected results" do
|
22
|
-
|
23
|
-
before(:each) do
|
24
|
-
@client = Pingfm::Client.new('a','b')
|
25
|
-
@params = {'api_key' => 'a', 'user_app_key' => 'b'}
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should validate keys successfully" do
|
29
|
-
init_ok_response 'user.validate'
|
30
|
-
|
31
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
32
|
-
|
33
|
-
# mock the http call
|
34
|
-
http_resp = mock('response')
|
35
|
-
http_resp.should_receive(:body).and_return(@response)
|
36
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
37
|
-
|
38
|
-
# call and verify
|
39
|
-
result = @client.validate
|
40
|
-
result.should_not be_empty
|
41
|
-
result['status'].should_not be_nil
|
42
|
-
result['status'].should eql('OK')
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should list the user's services properly" do
|
46
|
-
init_service_response
|
47
|
-
|
48
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
49
|
-
|
50
|
-
# mock the http call
|
51
|
-
http_resp = mock('response')
|
52
|
-
http_resp.should_receive(:body).and_return(@response)
|
53
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
54
|
-
|
55
|
-
# call and verify
|
56
|
-
result = @client.services
|
57
|
-
result.should_not be_empty
|
58
|
-
result['status'].should_not be_nil
|
59
|
-
result['status'].should eql('OK')
|
60
|
-
result['services'].should_not be_nil
|
61
|
-
result['services'].should_not be_empty
|
62
|
-
result['services'].length.should eql(2)
|
63
|
-
result['services'].first['id'].should eql('twitter')
|
64
|
-
end
|
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
|
-
|
86
|
-
it "should list the user's custom triggers" do
|
87
|
-
init_trigger_response
|
88
|
-
|
89
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
90
|
-
|
91
|
-
# mock the http call
|
92
|
-
http_resp = mock('response')
|
93
|
-
http_resp.should_receive(:body).and_return(@response)
|
94
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
95
|
-
|
96
|
-
# call and verify
|
97
|
-
result = @client.triggers
|
98
|
-
result.should_not be_empty
|
99
|
-
result['status'].should_not be_nil
|
100
|
-
result['status'].should eql('OK')
|
101
|
-
result['triggers'].should_not be_nil
|
102
|
-
result['triggers'].should_not be_empty
|
103
|
-
result['triggers'].length.should eql(2)
|
104
|
-
result['triggers'].first['id'].should eql('twt')
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should list the user's recent posts" do
|
108
|
-
init_latest_response
|
109
|
-
|
110
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
111
|
-
@params.merge!('limit'=>5,'order'=>'DESC')
|
112
|
-
|
113
|
-
# mock the http call
|
114
|
-
http_resp = mock('response')
|
115
|
-
http_resp.should_receive(:body).and_return(@response)
|
116
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
117
|
-
|
118
|
-
# call and verify
|
119
|
-
result = @client.latest(5)
|
120
|
-
result.should_not be_empty
|
121
|
-
result['status'].should_not be_nil
|
122
|
-
result['status'].should eql('OK')
|
123
|
-
result['messages'].should_not be_nil
|
124
|
-
result['messages'].should_not be_empty
|
125
|
-
result['messages'].length.should eql(3)
|
126
|
-
result['messages'].first['id'].should eql('12345')
|
127
|
-
result['messages'].last['location'].should_not be_empty
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should post a message to the service" do
|
131
|
-
init_ok_response 'user.post'
|
132
|
-
|
133
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
134
|
-
@params.merge!('body' => 'foo', 'title' => '',
|
135
|
-
'post_method' => 'default', 'service' => '',
|
136
|
-
'debug' => 0)
|
137
|
-
|
138
|
-
# mock the http call
|
139
|
-
http_resp = mock('response')
|
140
|
-
http_resp.should_receive(:body).and_return(@response)
|
141
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
142
|
-
|
143
|
-
# call and verify
|
144
|
-
result = @client.post('foo')
|
145
|
-
result.should_not be_empty
|
146
|
-
result['status'].should_not be_nil
|
147
|
-
result['status'].should eql('OK')
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should post a message to the service using a trigger" do
|
151
|
-
init_ok_response 'user.tpost'
|
152
|
-
|
153
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
154
|
-
@params.merge!('body' => 'foo', 'title' => '',
|
155
|
-
'trigger' => 'twt', 'debug' => 0)
|
156
|
-
|
157
|
-
# mock the http call
|
158
|
-
http_resp = mock('response')
|
159
|
-
http_resp.should_receive(:body).and_return(@response)
|
160
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
161
|
-
|
162
|
-
# call and verify
|
163
|
-
result = @client.tpost('foo','twt')
|
164
|
-
result.should_not be_empty
|
165
|
-
result['status'].should_not be_nil
|
166
|
-
result['status'].should eql('OK')
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
describe Pingfm::Client, "with error messages" do
|
172
|
-
before(:each) do
|
173
|
-
@client = Pingfm::Client.new('a','b')
|
174
|
-
@params = {'api_key' => 'a', 'user_app_key' => 'b'}
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should handle a failed validate cleanly" do
|
178
|
-
init_fail_response 'user.validate'
|
179
|
-
|
180
|
-
uri = URI.parse "#{Pingfm::API_URL}/#{@service_type}"
|
181
|
-
|
182
|
-
# mock the http call
|
183
|
-
http_resp = mock('response')
|
184
|
-
http_resp.should_receive(:body).and_return(@response)
|
185
|
-
Net::HTTP.should_receive(:post_form).with(uri, @params).and_return(http_resp)
|
186
|
-
|
187
|
-
# call and verify
|
188
|
-
result = @client.validate
|
189
|
-
result.should_not be_empty
|
190
|
-
result['status'].should_not be_nil
|
191
|
-
result['status'].should eql('FAIL')
|
192
|
-
result['message'].should_not be_nil
|
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
|
307
|
-
end
|
308
|
-
|
309
|
-
# EOF
|