Class: SMS::Client::Moonshado

Inherits:
Object
  • Object
show all
Defined in:
lib/sms-client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/sms-client.rb', line 8

def api_key
  @api_key
end

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/sms-client.rb', line 8

def body
  @body
end

#device_addressObject

Returns the value of attribute device_address.



8
9
10
# File 'lib/sms-client.rb', line 8

def device_address
  @device_address
end

#keywordObject

Returns the value of attribute keyword.



8
9
10
# File 'lib/sms-client.rb', line 8

def keyword
  @keyword
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/sms-client.rb', line 8

def message
  @message
end

#originating_addressObject

Returns the value of attribute originating_address.



8
9
10
# File 'lib/sms-client.rb', line 8

def originating_address
  @originating_address
end

#reporting_keyObject

Returns the value of attribute reporting_key.



8
9
10
# File 'lib/sms-client.rb', line 8

def reporting_key
  @reporting_key
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/sms-client.rb', line 8

def response
  @response
end

Class Method Details

.send_message(&block) ⇒ Object



10
11
12
13
14
15
# File 'lib/sms-client.rb', line 10

def self.send_message(&block)
  request = SMS::Client::Moonshado.new
  request.instance_eval(&block)
  request.send_sms

end

Instance Method Details

#send_smsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sms-client.rb', line 17

def send_sms
  begin
    d = {
        :api_key => self.api_key,
        :message => {
            :reporting_key => self.reporting_key,
            :originating_address => self.originating_address,
            :device_address => self.device_address,
            :keyword => self.keyword,
            :body => self.body
        }
    }
    r = RestClient.post 'http://api.moonshado.com/gateway/sms', d

    #TODO We should do something about these statuses!
    code = Crack::XML.parse(r)["status"]["code"] rescue nil
    info = Crack::XML.parse(r)["status"]["info"] rescue nil
    puts "code:#{code} info:#{info}"
  rescue Exception => e
    Rails.logger.info  e.response
    raise e
  end

end