Class: SMSTradeRB
- Inherits:
-
Object
- Object
- SMSTradeRB
- Defined in:
- lib/smstraderb/server.rb,
lib/smstraderb.rb,
lib/smstraderb/response.rb,
lib/smstraderb/constants.rb
Overview
This class tries to emulate the smstrade.de HTTP API v2.2. It provides a valid Rack endpoint.
Defined Under Namespace
Classes: InvalidFormat, InvalidOption, InvalidResponse, InvalidRoute, Response, Server, UnknownResponse
Constant Summary collapse
- VERSION =
'0.1.0'
- HTTP_GATEWAY =
'http://gateway.smstrade.de/'
- HTTPS_GATEWAY =
'https://gateway.smstrade.de/'
- ROUTES =
[:basic, :economy, :gold, :direct]
- DEFAULT_ROUTE =
:basic
- MESSAGE_TYPES =
[:flash, :unicode, :binary, :voice]
- RESPONSE_CODES =
{ 10 => 'Invalid recipient number', 20 => 'Invalid sender number', 30 => 'Invalid message format', 31 => 'Invalid message type', 40 => 'Invalid route', 50 => 'Authentication failed', 60 => 'Insufficient funds', 70 => 'Network not covered by route', 71 => 'Invalid feature for selected route', 80 => 'Handover to SMS-C failed', 100 => 'Message accepted and sent', 999 => 'Internal test response' }.freeze
Instance Attribute Summary collapse
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SMSTradeRB
constructor
A new instance of SMSTradeRB.
- #send(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SMSTradeRB
Returns a new instance of SMSTradeRB.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/smstraderb.rb', line 12 def initialize( = {}) @charset = 'UTF-8' @key = [:key] @message = [:message] @to = check_phone_number([:to]) @route = check_route([:route]) || SMSTradeRB::DEFAULT_ROUTE @from = [:from] @debug = [:debug] ? 1 : 0 check_from_allowed(@from, @route) check_value_length(@from, 11) if @from @message = escape(@message) @from = escape(@from) end |
Instance Attribute Details
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def charset @charset end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def debug @debug end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def from @from end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def key @key end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def @message end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def route @route end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
10 11 12 |
# File 'lib/smstraderb.rb', line 10 def to @to end |
Instance Method Details
#send(options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/smstraderb.rb', line 29 def send() @to = escape(check_phone_number([:to])) @message = escape([:message]) uri = URI.parse(SMSTradeRB::HTTP_GATEWAY) http = Net::HTTP.new(uri.host, uri.port) #http.use_ssl = true if uri.scheme == "https" # enable SSL/TLS response = http.start do http.request_get(build_request) end SMSTradeRB::Response.new(response.body) end |