Class: SoftersSms::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Returns a new instance of Client.



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

def initialize(username, password)
  @username, @password = username, password

  @headers = {'Content-Type' => 'application/x-www-form-urlencoded'}

  @http = Net::HTTP.new('www.softers.net', Net::HTTP.https_default_port)
  @http.use_ssl = true
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



18
19
20
# File 'lib/softers-sms.rb', line 18

def headers
  @headers
end

#httpObject

Returns the value of attribute http.



18
19
20
# File 'lib/softers-sms.rb', line 18

def http
  @http
end

#passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/softers-sms.rb', line 18

def password
  @password
end

#usernameObject

Returns the value of attribute username.



18
19
20
# File 'lib/softers-sms.rb', line 18

def username
  @username
end

Instance Method Details

#encode(data) ⇒ Object



31
32
33
# File 'lib/softers-sms.rb', line 31

def encode(data)
  URI.encode_www_form data.merge(:username => @username, :password => @password)
end

#send_message(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/softers-sms.rb', line 20

def send_message(data)
  data[:message] = data[:message].encode('ISO-8859-1')
  response = @http.post('/messaging/smsclient.php?type=send', encode(data), headers)
  if response.body.strip == "200 OK"
    Success.new(true)
  else
    Failure.new(Error.new("#{response.body}"))
  end

end