jnstq (owner)

Revisions

gist: 211275 Download_button fork
public
Public Clone URL: git://gist.github.com/211275.git
Embed All Files: show embed
snippet.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'httparty'
 
class SmsGateway
  module SmsResponse
    def ok?
      self.to_s =~ /^OK:\s*(.*)/i
    end
    def status
      $1 if self.to_s =~ /^(\w+)\s*/i
    end
    def tracking_ids
      if self.to_s =~ /^OK:\s*(.*)/i
        @tracking_ids = $1.split(',')
      else
        []
      end
    end
  end
 
  include HTTParty
  base_uri 'http://se-1.cellsynt.net'
  attr_reader :last_response
 
  def self.send_message(*args)
    new.send_message(*args)
  end
  
  def default_params
    {
      :type => 'text',
      :originatortype => 'alpha',
      :originator => 'RESTSMS'
    }
  end
  
  def send_message(params)
    options = { :body => default_params.merge(params) }
    @last_response = self.class.post('/sms.php', options)
    @last_response.extend SmsResponse
    @last_response
  end
 
end