Class: ClickSend::REST::Sms

Inherits:
Resource show all
Defined in:
lib/click_send/rest/sms.rb

Overview

A class to wrap all messaging related functionality within the ClickSend API.

Instance Attribute Summary

Attributes inherited from Resource

#connection

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from ClickSend::REST::Resource

Instance Method Details

#receiveObject

Poll ClickSend API for replies to messages. Make sure ‘Poll our server’ settings is selected under ‘SMS Reply Report Settings’ before using this.



77
78
79
# File 'lib/click_send/rest/sms.rb', line 77

def receive
  perform_request(:post, '/rest/v2/reply.json')
end

#send(params = {}) ⇒ Object

Send messages using ClickSend API. The params parameter is a hash of options. The following keys are mandatory:

:to => '+614XXXXXXXX'

Recipient Mobile Number in international format (with leading + and country code). Separate multiple recipients with a comma (,) where applicable. Maximum 1000 recipients.

For example:

+614XXXXXXXX (Australia)

+1XXXXXXXXXX (US)

+65XXXXXXXXX (Singapore)

+44XXXXXXXXXX (UK)

:message => 'Hello'

The message to be sent. Maximum 960 characters.

The following keys are optional and can be used:

:senderid => '+61411111111'

custom sender ID:

-Alphanumeric e.g. “MyCompany”. 11 characters max. No spaces. The recipient will not be able to reply to the message.

-Numeric e.g. +61411111111. You can enter your own mobile number in international format to make messages appear to come from your mobile number. Replies will be sent directly to your mobile.

-Leave blank for two-way SMS. Replies will be directed back to the original sender.

:schedule => '1348742950'

Allows you to schedule message delivery. Must be in unix format.

For example: 1348742950.

Leave blank for instant delivery.

:customstring => 'From ClickSend'

A custom string that will be passed back with replies and delivery reports. Maximum 50 characters.

:return => 'http://mydomain.com/callback'

Redirect to a URL after delivering the message(s).

:messagetype => 'Unicode'

For non-English characters use messagetype=Unicode.

Leave blank for a standard English message.

Raises:



63
64
65
66
67
68
69
70
71
72
# File 'lib/click_send/rest/sms.rb', line 63

def send(params={})
  params.reject!{|key, value| ![:to, :message, :senderid, :schedule, :customstring, :return, :messagetype].include?(key)}
  raise ClickSendError, 'Recipient Mobile Number is mandatory' if params[:to].nil? || params[:to].empty?
  raise ClickSendError, 'Message is mandatory' if params[:message].nil? || params[:message].empty?
  params[:schedule]=params[:schedule].to_i if !(params[:schedule].nil?)
  
  params.merge!(method: 'rest')
  
  perform_request(:post, '/rest/v2/send.json', params)
end