Module: SmsghSms

Defined in:
lib/smsgh_sms.rb,
lib/smsgh_sms/version.rb

Constant Summary collapse

VERSION =
"1.0.6"
@@api_username =
nil
@@api_password =
nil
@@api_client_id =
nil
@@api_client_secret =
nil
@@api_senderid =
"SMSGHAPI"

Class Method Summary collapse

Class Method Details

.api_client_idObject



45
# File 'lib/smsgh_sms.rb', line 45

def self.api_client_id; @@api_client_id; end

.api_client_id=(api_client_id) ⇒ Object



44
# File 'lib/smsgh_sms.rb', line 44

def self.api_client_id=(api_client_id); @@api_client_id = api_client_id; end

.api_client_secretObject



48
# File 'lib/smsgh_sms.rb', line 48

def self.api_client_secret; @@api_client_secret; end

.api_client_secret=(api_client_secret) ⇒ Object



47
# File 'lib/smsgh_sms.rb', line 47

def self.api_client_secret=(api_client_secret); @@api_client_secret = api_client_secret; end

.api_passwordObject



42
# File 'lib/smsgh_sms.rb', line 42

def self.api_password; @@api_password; end

.api_password=(api_password) ⇒ Object



41
# File 'lib/smsgh_sms.rb', line 41

def self.api_password=(api_password); @@api_password = api_password; end

.api_senderidObject



51
# File 'lib/smsgh_sms.rb', line 51

def self.api_senderid; @@api_senderid; end

.api_senderid=(api_senderid) ⇒ Object



50
# File 'lib/smsgh_sms.rb', line 50

def self.api_senderid=(api_senderid); @@api_senderid = api_senderid; end

.api_usernameObject



39
# File 'lib/smsgh_sms.rb', line 39

def self.api_username; @@api_username; end

.api_username=(api_username) ⇒ Object



38
# File 'lib/smsgh_sms.rb', line 38

def self.api_username=(api_username); @@api_username = api_username; end

.push(options = {}) ⇒ Object

Expects :msg, :to and an optional :from param The :from param defaults to @@api_senderid when its omitted

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smsgh_sms.rb', line 15

def self.push(options={})

  sender_id = options[:from].nil? ? @@api_senderid : options[:from]
  response = nil
  message = options[:msg]

  raise ArgumentError, ':msg and :to params expected' if message.nil? || options[:to].nil?

  message = Nokogiri::HTML.parse(message).text

  if @@api_username != nil && @@api_password != nil
    response = CurbFu.get({:host => 'api.smsgh.com', :path => '/v2/messages/send'}, { :from => sender_id, :to => options[:to], :text => message, :username => @@api_username, :password => @@api_password })
  end

  if @@api_client_id != nil && @@api_client_secret != nil
    response = CurbFu.get({:host => 'api.smsgh.com', :path => '/v3/messages/send', :protocol => 'http'}, { :From => sender_id, :To => options[:to], :Content => message, :ClientId => @@api_client_id, :ClientSecret => @@api_client_secret })
  end

  {:status => response.status, :notice => response.body}

end