Class: Telapi::MMS

Inherits:
Resource
  • Object
show all
Defined in:
lib/telapi/mms.rb

Overview

Wraps TelAPI MMS Message functionality

Constant Summary collapse

MAX_BODY_LENGTH =
160

Class Method Summary collapse

Methods inherited from Resource

#attributes, #initialize

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, attachment, status_callback = nil) ⇒ Object

Creates an MMS Message, returning a Telapi::MMS object

Required params:

to

mobile phone number

from

TelAPI or mobile phone number

body

plain text up to 160 characters in length

attachment

URL for MMS attachment

Optional param:

status_callback

valid URL

Raises:

  • (RangeError)


37
38
39
40
41
42
# File 'lib/telapi/mms.rb', line 37

def create(to, from, body, attachment, 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, :Attachment => attachment, :StatusCallback => status_callback }
  response = Network.post(['MMS', 'Messages'], opts)
  MMS.new(response)
end

.get(id) ⇒ Object

Returns a specific Telapi::MMS object given its id



21
22
23
24
# File 'lib/telapi/mms.rb', line 21

def get(id)
  response = Network.get(['MMS', 'Messages', id])
  Message.new(response)
end

.list(optional_params = {}) ⇒ Object

Returns a resource collection containing Telapi::MMS objects

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



15
16
17
18
# File 'lib/telapi/mms.rb', line 15

def list(optional_params = {})
  response = Network.get(['MMS', 'Messages'], optional_params)
  ResourceCollection.new(response, 'mms_messages', self)
end