Class: Sisal::Providers::TimweProvider

Inherits:
Provider
  • Object
show all
Defined in:
lib/sisal/providers/timwe_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TimweProvider

Returns a new instance of TimweProvider.



11
12
13
14
15
16
# File 'lib/sisal/providers/timwe_provider.rb', line 11

def initialize(options = {})
  @partner_role_id  = options[:partner_role_id]
  @password         = options[:password]
  @product_id       = options[:product_id]
  @price_point_id   = options[:price_point_id]
end

Instance Method Details

#send(message, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sisal/providers/timwe_provider.rb', line 18

def send(message, options = {})
  params = {
    PartnerRoleId:  @partner_role_id,
    Password:       @password,
    ProductId:      @product_id,
    PricePointId:   @price_point_id,
    Destination:    message.to,
    Text:           message.text,
    ExtTxId:        options[:exttxid] || Time.now.to_i,
    OpId:           options[:opid]    || "1"
  }

  begin
    response = RestClient.get(API_URL, params: params)
    code = response.to_s.dup.to_i

    Sisal::Response.new((code > 0), code, status_code(code))
  rescue ::SocketError, ::Errno::ETIMEDOUT, ::RestClient::Exception => e
    Sisal::Response.new(false, nil, e.message)
  end
end