Class: Telapi::Message
- Defined in:
- lib/telapi/message.rb
Overview
Wraps TelAPI SMS Message functionality
Constant Summary collapse
- MAX_BODY_LENGTH =
160
Class Method Summary collapse
-
.create(to, from, body, status_callback = nil) ⇒ Object
Creates an SMS Message, returning a Telapi::Message object See www.telapi.com/docs/api/rest/sms/send/.
-
.get(id) ⇒ Object
Returns a specific Telapi::Message object given its id See www.telapi.com/docs/api/rest/sms/view/.
-
.list(optional_params = {}) ⇒ Object
Returns a resource collection containing Telapi::Message objects See www.telapi.com/docs/api/rest/sms/list/.
Methods inherited from Resource
Methods included from Network
api_uri, default_options, delete, post, response_format
Constructor Details
This class inherits a constructor from Telapi::Resource
Class Method Details
.create(to, from, body, status_callback = nil) ⇒ Object
Creates an SMS Message, returning a Telapi::Message object See www.telapi.com/docs/api/rest/sms/send/
Required params:
to
-
mobile phone number
from
-
TelAPI or mobile phone number
body
-
plain text up to 160 characters in length
Optional params:
status_callback
-
valid URL
38 39 40 41 42 43 |
# File 'lib/telapi/message.rb', line 38 def create(to, from, body, status_callback=nil) raise RangeError, "Body must be between 0 and #{MAX_BODY_LENGTH} characters" if body.length>MAX_BODY_LENGTH || body.length==0 opts = { :To => to, :From => from, :Body => body, :StatusCallback => status_callback } response = Network.post(['SMS', 'Messages'], opts) Message.new(response) end |
.get(id) ⇒ Object
Returns a specific Telapi::Message object given its id See www.telapi.com/docs/api/rest/sms/view/
23 24 25 26 |
# File 'lib/telapi/message.rb', line 23 def get(id) response = Network.get(['SMS', 'Messages', id]) Message.new(response) end |
.list(optional_params = {}) ⇒ Object
Returns a resource collection containing Telapi::Message objects See www.telapi.com/docs/api/rest/sms/list/
Optional params is a hash containing:
To
-
mobile phone number
From
-
TelAPI or mobile phone number
DateSent
-
date in the following format: YYYY-MM-DD
Page
-
integer greater than 0
PageSize
-
integer greater than 0
16 17 18 19 |
# File 'lib/telapi/message.rb', line 16 def list(optional_params = {}) response = Network.get(['SMS', 'Messages'], optional_params) ResourceCollection.new(response, 'sms_messages', self) end |