Class: Smshelper::Api::Smswarehouse

Inherits:
Base
  • Object
show all
Defined in:
lib/smshelper/api/smswarehouse.rb

Instance Attribute Summary

Attributes inherited from Base

#extra_options, #sent_message_ids, #sent_message_statuses

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Smswarehouse

base_uri “websms.smswarehouse.com:7800” endpoint “websms”



7
8
9
10
11
12
# File 'lib/smshelper/api/smswarehouse.rb', line 7

def initialize(*args)
  config = args.shift
  @uname, @passwd = config.smswarehouse[:uname], config.smswarehouse[:passwd]
  add_request_options! :skip_endpoint => true
  super
end

Instance Method Details

#get_balanceObject



41
42
43
44
45
# File 'lib/smshelper/api/smswarehouse.rb', line 41

def get_balance
  opts = {:userid => @uname, :password => @passwd}
  url = 'http://websms.smswarehouse.com:7800/websms/balanceReport'
  {'EUR' => (post url, :extra_query => opts).split(/\n/).last.split('::').last.strip}
end

#get_callback_response(args = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/smshelper/api/smswarehouse.rb', line 58

def get_callback_response(args = {})
  if args['notificationType'] == 'MessageReceived'
    InboundMessage.new(
                       :message_id => args['id'],
                       :sender => args['originator'],
                       :recipient => args['recipient'],
                       :text => args['body'],
                       :timestamp => Time.now,
                       :original_params => args
                       )
  elsif args['notificationType'] == 'MessageEvent'
    DeliveryReport.new(
                       :message_id => args['id'],
                       :timestamp => Time.now,
                       :delivered => ((args['eventType'] == 'Delivered') ? true : false),
                       :original_params => args
                       )
  else
    UnknownReply.new(args)
  end
end

#get_status(message_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/smshelper/api/smswarehouse.rb', line 47

def get_status(message_id)
  url = 'http://websms.smswarehouse.com:7800/websms/websmsstatus'
  options = {:userid => @uname, :password => @passwd}
  resp = (post url, :extra_query => {:respid => message_id.to_s}.merge(options)).split('-')[1].strip
  @sent_message_statuses[message_id] = []
  [resp].each_with_index do |status, index|
    @sent_message_statuses[message_id] << {"part #{index}" => resp}
  end
  {message_id => @sent_message_statuses[message_id]}
end

#send_message(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smshelper/api/smswarehouse.rb', line 14

def send_message(message)

  if message.utf_8
    message.to_hex_be
    q = {:type => '0', :esm => '64', :dcs => '8'}
    # raise NotImplementedError, "UTF-8 unsupported by #{self.class.name}"
  else
    #q = {:type => '5', :esm => '64', :dcs => '0'}
    q = {:type => '1', :esm => '0', :dcs => '0'}
  end

  options = {
    :user => @uname,
    :pass => @passwd,
    :mno => message.recipient,
    :text => message.text,
    :sid => message.sender}

  options.merge!(@extra_options) unless @extra_options.nil?

  url = 'http://websms.smswarehouse.com:7800/websms/webmsg'
  resp = (post url, :extra_query => q.merge(options)) #.split('::').last.strip
  @sent_message_ids << resp
  pp resp
  resp
end