Class: Net::SMS::BulkSMS::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/net/sms/bulksms.rb

Constant Summary collapse

MESSAGE_SERVICE_PORT =

The port the message service rus on

80
MESSAGE_SERVICE_PATH =

Path to the message service gateway

'/eapi/submission/send_sms/2/2.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, country = INTER) ⇒ Service



41
42
43
44
# File 'lib/net/sms/bulksms.rb', line 41

def initialize(username, password, country = INTER)
	@account = Account.new(username, password, country)
      @country=country
end

Instance Attribute Details

#accountObject (readonly)

returns an Account object for the credentials supplied to the service



39
40
41
# File 'lib/net/sms/bulksms.rb', line 39

def 
  @account
end

Class Method Details

.bulksms_gateway(country) ⇒ Object

Returns the gateway URL for the chosen country



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/net/sms/bulksms.rb', line 74

def self.bulksms_gateway(country)
  case country
  when 'uk'
    'www.bulksms.co.uk'
  when 'usa'
    'usa.bulksms.com'
  when 'international'
    'bulksms.vsms.net'
  when 'safrica'
    'bulksms.2way.co.za'
  when 'spain'
    'bulksms.com.es'
  end
end

Instance Method Details

#send(message, recipient) ⇒ Object

Creates a new Message object from the message text and recipient given and sends to the gateway using send_message()



68
69
70
71
# File 'lib/net/sms/bulksms.rb', line 68

def send(message, recipient)
	msg = Message.new(message, recipient)
	self.send_message(msg)
end

#send_message(msg) ⇒ Object

Sends the given Message object to the gateway for delivery



47
48
49
50
51
52
53
# File 'lib/net/sms/bulksms.rb', line 47

def send_message(msg)
	payload = [@account.to_http_query, msg.to_http_query].join('&')
	Net::HTTP.start(Service.bulksms_gateway(@country), MESSAGE_SERVICE_PORT) do |http|
		resp = http.post(MESSAGE_SERVICE_PATH, payload)
		Response.parse(resp.body)
	end
end

#send_multiple(messages) ⇒ Object

Openning single connection & sending an array of message objects



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/net/sms/bulksms.rb', line 55

def send_multiple(messages)
  responses=[]
  Net::HTTP.start(Service.bulksms_gateway(@country), MESSAGE_SERVICE_PORT) do |http|
    messages.each do |msg|
      payload = [@account.to_http_query, msg.to_http_query].join('&')
      resp = http.post(MESSAGE_SERVICE_PATH, payload)
      responses << Response.parse(resp.body)
    end
  end
  responses
end