Class: Jung::Drivers::Infobip::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/jung/drivers/infobip/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Api

Returns a new instance of Api.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jung/drivers/infobip/api.rb', line 10

def initialize(config)
  @username = config.options["username"]
  @password = config.options["password"]
  @api_url = config.options["api_url"]
  @errors = []

  @error_messages = {
    -2 => "Not enough credits",
    -3 => "Network not covered",
    -5 => "Invalid username or password",
    -6 => "Missing destination address",
    -7 => "Missing SMS text",
    -8 => "Missing sender name",
    -9 => "Invalid format of destination address",
    -10 => "Missing username",
    -11 => "Missing password",
    -13 => "Invalid destination address"
  }
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



7
8
9
# File 'lib/jung/drivers/infobip/api.rb', line 7

def api_url
  @api_url
end

#error_messagesObject (readonly)

Returns the value of attribute error_messages.



7
8
9
# File 'lib/jung/drivers/infobip/api.rb', line 7

def error_messages
  @error_messages
end

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/jung/drivers/infobip/api.rb', line 8

def errors
  @errors
end

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/jung/drivers/infobip/api.rb', line 7

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



7
8
9
# File 'lib/jung/drivers/infobip/api.rb', line 7

def username
  @username
end

Instance Method Details

#send_sms(address, message, sender, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jung/drivers/infobip/api.rb', line 30

def send_sms(address, message, sender, options = {})
  count = Jung::Drivers::Infobip::SmsCounter.count message.to_s

  type = count[:messages] > 1 ? 'LongSMS' : nil
  if count[:encoding] == :utf16
    data_coding = 8
    encoding = 'UTF-8'
  else
    data_coding = 1
    encoding = nil
    message = GSMEncoder.encode message
  end

  do_get_request :sendsms, {
    :GSM => address, 
    :SMSText => message, 
    :sender => sender, 
    :Type => type, 
    :DataCoding => data_coding, 
    :encoding => encoding,
  }.merge(options)
end