pingfm 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -0
- data/bin/pingfm +4 -1
- data/lib/pingfm.rb +1 -1
- data/lib/pingfm/client.rb +19 -10
- data/pingfm.gemspec +1 -0
- metadata +17 -6
data/Gemfile.lock
CHANGED
data/bin/pingfm
CHANGED
@@ -41,7 +41,10 @@ rescue Pingfm::ConfigNotFound => error
|
|
41
41
|
Pingfm::Config['app_key'] = app_key
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
options = {
|
45
|
+
:debug => opts.debug?,
|
46
|
+
}
|
47
|
+
client = Pingfm::Client.new(app_key, options)
|
45
48
|
response = client.post(message)
|
46
49
|
|
47
50
|
if response['status'] == 'OK'
|
data/lib/pingfm.rb
CHANGED
data/lib/pingfm/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'base64'
|
1
2
|
require 'net/http'
|
2
3
|
require 'rexml/document' # TODO: Rewrite this to use something faster (Nokogiri, possibly).
|
3
4
|
|
@@ -14,9 +15,18 @@ module Pingfm
|
|
14
15
|
API_URL = 'http://api.ping.fm/v1'
|
15
16
|
|
16
17
|
attr_reader :user_app_key
|
18
|
+
attr_reader :options
|
17
19
|
|
18
|
-
|
20
|
+
# You can pass an <tt>options</tt> hash:
|
21
|
+
# [debug] Boolean used when testing to avoid actually posting a message.
|
22
|
+
# [decode_body] If <tt>true</tt>, the 'body' of appropriate elements will be Base64 decoded; default is <tt>false</tt>.
|
23
|
+
def initialize(user_app_key, options = {})
|
19
24
|
@user_app_key = user_app_key
|
25
|
+
@options = {
|
26
|
+
# Defaults:
|
27
|
+
:debug => false,
|
28
|
+
:decode_body => false,
|
29
|
+
}.merge(options)
|
20
30
|
end
|
21
31
|
|
22
32
|
# Returns the last <tt>limit</tt> messages a user has posted through Ping.fm.
|
@@ -51,7 +61,8 @@ module Pingfm
|
|
51
61
|
else
|
52
62
|
latest['messages'].last['location'] = ''
|
53
63
|
end
|
54
|
-
|
64
|
+
encoded_body = message.elements['*/body'].text
|
65
|
+
latest['messages'].last['body'] = @options[:decode_body] ? Base64.decode64(encoded_body) : encoded_body
|
55
66
|
latest['messages'].last['services'] = []
|
56
67
|
message.elements.each('services/service') do |service|
|
57
68
|
latest['messages'].last['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name']})
|
@@ -99,21 +110,20 @@ module Pingfm
|
|
99
110
|
# Arguments:
|
100
111
|
# [body] Message body.
|
101
112
|
#
|
102
|
-
# Optional <tt>
|
113
|
+
# Optional <tt>opts</tt>:
|
103
114
|
# [title] Title of the posted message; title is required for 'blog' post method.
|
104
115
|
# [post_method] Posting method; either 'default', 'blog', 'microblog' or 'status'.
|
105
116
|
# [service] A single service to post to.
|
106
|
-
# [debug] Set debug to 1 to avoid posting test data.
|
107
117
|
#
|
108
118
|
# If successful returns:
|
109
119
|
# {'status' => 'OK'}
|
110
120
|
# If unsuccessful returns:
|
111
121
|
# {'status' => 'FAIL', 'message' => 'message what went wrong'}
|
112
|
-
def post(body, opts = { :title => '', :post_method => 'default', :service => ''
|
122
|
+
def post(body, opts = { :title => '', :post_method => 'default', :service => '' })
|
113
123
|
response = get_response('user.post',
|
114
124
|
'body' => body, 'title' => opts[:title],
|
115
125
|
'post_method' => opts[:post_method], 'service' => opts[:service],
|
116
|
-
'debug' => (
|
126
|
+
'debug' => (@options[:debug] ? 1 : 0))
|
117
127
|
|
118
128
|
if response.elements['rsp'].attributes['status'] == 'OK'
|
119
129
|
return status_ok
|
@@ -177,18 +187,17 @@ module Pingfm
|
|
177
187
|
# [body] Message body.
|
178
188
|
# [trigger] Custom trigger the user has defined from the Ping.fm website.
|
179
189
|
#
|
180
|
-
# Optional
|
190
|
+
# Optional <tt>opts</tt>:
|
181
191
|
# [title] Title of the posted message; title is required for 'blog' post method.
|
182
|
-
# [debug] Set debug to +true+ to avoid posting test data.
|
183
192
|
#
|
184
193
|
# If successful returns:
|
185
194
|
# {'status' => 'OK'}
|
186
195
|
# If unsuccessful returns:
|
187
196
|
# {'status' => 'FAIL', 'message' => 'message what went wrong'}
|
188
|
-
def tpost(body, trigger, opts = { :title => ''
|
197
|
+
def tpost(body, trigger, opts = { :title => '' })
|
189
198
|
response = get_response('user.tpost',
|
190
199
|
'body' => body, 'title' => opts[:title],
|
191
|
-
'trigger' => trigger, 'debug' => (
|
200
|
+
'trigger' => trigger, 'debug' => (@options[:debug] ? 1 : 0))
|
192
201
|
if response.elements['rsp'].attributes['status'] == 'OK'
|
193
202
|
return status_ok
|
194
203
|
else
|
data/pingfm.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.summary = %q{A Ping.fm Ruby library.}
|
15
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
16
|
|
17
|
+
s.add_dependency('bundler')
|
17
18
|
s.add_dependency('slop')
|
18
19
|
s.add_development_dependency('rspec', '>= 2.6.0')
|
19
20
|
|
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.
|
4
|
+
version: 2.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-06-
|
14
|
+
date: 2011-06-13 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &68794930 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *68794930
|
16
27
|
- !ruby/object:Gem::Dependency
|
17
28
|
name: slop
|
18
|
-
requirement: &
|
29
|
+
requirement: &68794440 !ruby/object:Gem::Requirement
|
19
30
|
none: false
|
20
31
|
requirements:
|
21
32
|
- - ! '>='
|
@@ -23,10 +34,10 @@ dependencies:
|
|
23
34
|
version: '0'
|
24
35
|
type: :runtime
|
25
36
|
prerelease: false
|
26
|
-
version_requirements: *
|
37
|
+
version_requirements: *68794440
|
27
38
|
- !ruby/object:Gem::Dependency
|
28
39
|
name: rspec
|
29
|
-
requirement: &
|
40
|
+
requirement: &68793840 !ruby/object:Gem::Requirement
|
30
41
|
none: false
|
31
42
|
requirements:
|
32
43
|
- - ! '>='
|
@@ -34,7 +45,7 @@ dependencies:
|
|
34
45
|
version: 2.6.0
|
35
46
|
type: :development
|
36
47
|
prerelease: false
|
37
|
-
version_requirements: *
|
48
|
+
version_requirements: *68793840
|
38
49
|
description: Ping.fm (http://ping.fm) is a simple service that makes updating your
|
39
50
|
social networks a snap, and this it's Ruby library.
|
40
51
|
email:
|