Class: Pingfm::Client
- Inherits:
-
Object
- Object
- Pingfm::Client
- Defined in:
- lib/pingfm/client.rb
Instance Method Summary collapse
-
#initialize(api_key, user_app_key) ⇒ Client
constructor
A new instance of Client.
-
#latest(limit = 25, order = 'DESC') ⇒ Object
Returns the last
limitmessages a user has posted through Ping.fm Optional arguments: limit = limit the results returned, default is 25 order = which direction to order the returned results by date, default is DESC (descending) if successful returns: => ‘OK’, ‘messages’ => [{‘id’ => ‘messageid’, ‘method’ => ‘messsagemethod’, ‘rfc’ => ‘date’, ‘unix’ => ‘date’, ‘title’ => ‘messagetitle’, ‘body’ => ‘messagebody’, ‘services’ => [{‘id’ => ‘serviceid’, ‘name’ => ‘servicename’, …]}, …]} if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’. -
#post(body, title = '', post_method = 'default', service = '', debug = 0) ⇒ Object
Posts a message to the user’s Ping.fm services Arguments: body = message body Optional arguments: title = title of the posted message, title is required for ‘blog’ post method post_method = posting method; either ‘default’, ‘blog’, ‘microblog’ or ‘status.’ service = a single service to post to debug = set debug to 1 to avoid posting test data if successful returns: => ‘OK’ if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
-
#services ⇒ Object
if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
-
#system_services ⇒ Object
Return a complete list of supported services if successful returns: => ‘OK’, ‘services’ => [{‘id’ => ‘serviceid’, ‘name’ => ‘servicename’, ‘trigger’ => ‘servicetrigger’, ‘url’ => ‘serviceurl’, ‘icon’ => ‘serviceicon’, …]} if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
-
#tpost(body, trigger, title = '', debug = 0) ⇒ Object
Posts a message to the user’s Ping.fm services using one of their custom triggers Arguments: body = message body trigger = custom trigger the user has defined from the Ping.fm website Optional arguments: title = title of the posted message, title is required for ‘blog’ post method debug = set debug to 1 to avoid posting test data if successful returns: => ‘OK’ if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
-
#triggers ⇒ Object
Returns a user’s custom triggers if successful returns: => ‘OK’, ‘triggers’ => [{‘id’ => ‘triggerid’, ‘method’ => ‘triggermethod’, ‘services’ => [{‘id’ => ‘serviceid’, ‘name’ => ‘servicename’, …]}, …]} if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
-
#validate ⇒ Object
Validates API key and user APP key if successful returns: => ‘OK’ if unsuccessful returns: => ‘FAIL’, ‘message’ => ‘message what went wrong’.
Constructor Details
#initialize(api_key, user_app_key) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/pingfm/client.rb', line 13 def initialize(api_key, user_app_key) @api_key = api_key @user_app_key = user_app_key end |
Instance Method Details
#latest(limit = 25, order = 'DESC') ⇒ Object
Returns the last limit messages a user has posted through Ping.fm Optional arguments: limit = limit the results returned, default is 25 order = which direction to order the returned results by date, default is DESC (descending) if successful returns:
{'status' => 'OK', 'messages' => [{'id' => 'messageid', 'method' => 'messsagemethod', 'rfc' => 'date', 'unix' => 'date', 'title' => 'messagetitle', 'body' => 'messagebody', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/pingfm/client.rb', line 110 def latest(limit = 25, order = 'DESC') response = get_response('user.latest', 'limit' => limit, 'order' => order) if response.elements['rsp'].attributes['status'] == 'OK' latest = status_ok latest['messages'] = [] response.elements.each('rsp/messages/message') do || latest['messages'].push({}) latest['messages'].last['id'] = .attributes['id'] latest['messages'].last['method'] = .attributes['method'] latest['messages'].last['rfc'] = .elements['date'].attributes['rfc'] latest['messages'].last['unix'] = .elements['date'].attributes['unix'] if .elements['*/title'] != nil latest['messages'].last['title'] = .elements['*/title'].text else latest['messages'].last['title'] = '' end if .elements['location'] != nil latest['messages'].last['location'] = .elements['location'].text else latest['messages'].last['location'] = '' end latest['messages'].last['body'] = .elements['*/body'].text latest['messages'].last['services'] = [] .elements.each('services/service') do |service| latest['messages'].last['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name']}) end end return latest else return status_fail(response) end end |
#post(body, title = '', post_method = 'default', service = '', debug = 0) ⇒ Object
Posts a message to the user’s Ping.fm services Arguments: body = message body Optional arguments: title = title of the posted message, title is required for ‘blog’ post method post_method = posting method; either ‘default’, ‘blog’, ‘microblog’ or ‘status.’ service = a single service to post to debug = set debug to 1 to avoid posting test data if successful returns:
{'status' => 'OK'}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/pingfm/client.rb', line 156 def post(body, title = '', post_method = 'default', service = '', debug = 0) response = get_response('user.post', 'body' => body, 'title' => title, 'post_method' => post_method, 'service' => service, 'debug' => debug) if response.elements['rsp'].attributes['status'] == 'OK' return status_ok else return status_fail(response) end end |
#services ⇒ Object
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pingfm/client.rb', line 60 def services response = get_response('user.services') if response.elements['rsp'].attributes['status'] == 'OK' services = status_ok() services['services'] = [] response.elements.each('rsp/services/service') do |service| services['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name'], 'trigger' => service.elements['trigger'].text, 'url' => service.elements['url'].text, 'icon' => service.elements['icon'].text, 'methods' => service.elements['methods'].text}) end return services else return status_fail(response) end end |
#system_services ⇒ Object
Return a complete list of supported services if successful returns:
{'status' => 'OK', 'services' => [{'id' => 'serviceid', 'name' => 'servicename', 'trigger' => 'servicetrigger', 'url' => 'serviceurl', 'icon' => 'serviceicon'}, ...]}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pingfm/client.rb', line 37 def system_services response = get_response('system.services') if response.elements['rsp'].attributes['status'] == 'OK' services = status_ok services['services'] = [] response.elements.each('rsp/services/service') do |service| services['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name'], 'trigger' => service.elements['trigger'].text, 'url' => service.elements['url'].text, 'icon' => service.elements['icon'].text}) end return services else return status_fail(response) end end |
#tpost(body, trigger, title = '', debug = 0) ⇒ Object
Posts a message to the user’s Ping.fm services using one of their custom triggers Arguments: body = message body trigger = custom trigger the user has defined from the Ping.fm website Optional arguments: title = title of the posted message, title is required for ‘blog’ post method debug = set debug to 1 to avoid posting test data if successful returns:
{'status' => 'OK'}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/pingfm/client.rb', line 179 def tpost(body, trigger, title = '', debug = 0) response = get_response('user.tpost', 'body' => body, 'title' => title, 'trigger' => trigger, 'debug' => debug) if response.elements['rsp'].attributes['status'] == 'OK' return status_ok else return status_fail(response) end end |
#triggers ⇒ Object
Returns a user’s custom triggers if successful returns:
{'status' => 'OK', 'triggers' => [{'id' => 'triggerid', 'method' => 'triggermethod', 'services' => [{'id' => 'serviceid', 'name' => 'servicename'}, ...]}, ...]}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pingfm/client.rb', line 84 def triggers response = get_response('user.triggers') if response.elements['rsp'].attributes['status'] == 'OK' triggers = status_ok triggers['triggers'] = [] response.elements.each('rsp/triggers/trigger') do |trigger| triggers['triggers'].push({'id' => trigger.attributes['id'], 'method' => trigger.attributes['method'], 'services' => []}) trigger.elements.each('services/service') do |service| triggers['triggers'].last['services'].push({'id' => service.attributes['id'], 'name' => service.attributes['name']}) end end return triggers else return status_fail(response) end end |
#validate ⇒ Object
Validates API key and user APP key if successful returns:
{'status' => 'OK'}
if unsuccessful returns:
{'status' => 'FAIL', 'message' => 'message what went wrong'}
23 24 25 26 27 28 29 30 |
# File 'lib/pingfm/client.rb', line 23 def validate response = get_response('user.validate') if response.elements['rsp'].attributes['status'] == 'OK' return status_ok else return status_fail(response) end end |