Class: SoftersSms::Client
- Inherits:
-
Object
- Object
- SoftersSms::Client
- Defined in:
- lib/softers-sms.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http ⇒ Object
Returns the value of attribute http.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #encode(data) ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #send_message(data) ⇒ Object
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
#headers ⇒ Object
Returns the value of attribute headers.
18 19 20 |
# File 'lib/softers-sms.rb', line 18 def headers @headers end |
#http ⇒ Object
Returns the value of attribute http.
18 19 20 |
# File 'lib/softers-sms.rb', line 18 def http @http end |
#password ⇒ Object
Returns the value of attribute password.
18 19 20 |
# File 'lib/softers-sms.rb', line 18 def password @password end |
#username ⇒ Object
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 (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 |