Class: SMSTradeRB

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  @charset = 'UTF-8'

  @key = options[:key]
  @message = options[:message]
  @to = check_phone_number(options[:to])
  @route = check_route(options[:route]) || SMSTradeRB::DEFAULT_ROUTE
  @from = options[:from]
  @debug = options[: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

#charsetObject (readonly)

Returns the value of attribute charset.



10
11
12
# File 'lib/smstraderb.rb', line 10

def charset
  @charset
end

#debugObject (readonly)

Returns the value of attribute debug.



10
11
12
# File 'lib/smstraderb.rb', line 10

def debug
  @debug
end

#fromObject (readonly)

Returns the value of attribute from.



10
11
12
# File 'lib/smstraderb.rb', line 10

def from
  @from
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/smstraderb.rb', line 10

def key
  @key
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/smstraderb.rb', line 10

def message
  @message
end

#routeObject (readonly)

Returns the value of attribute route.



10
11
12
# File 'lib/smstraderb.rb', line 10

def route
  @route
end

#toObject (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(options)
  @to = escape(check_phone_number(options[:to]))
  @message = escape(options[: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