Add compatibility with ruby 1.9.3
parent
6767b99b4a
commit
e1e7be5d98
|
@ -26,7 +26,10 @@ module Biju
|
||||||
wait(length: 0, timeout: 0)
|
wait(length: 0, timeout: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait(length: 0, timeout: 10)
|
def wait(options = {})
|
||||||
|
length = options[:length] || 0
|
||||||
|
timeout = options[:timeout] || 10
|
||||||
|
|
||||||
buffer = ''
|
buffer = ''
|
||||||
Timeout.timeout(timeout) do
|
Timeout.timeout(timeout) do
|
||||||
while IO.select([connection], [], [], 0.25) || buffer.length < length
|
while IO.select([connection], [], [], 0.25) || buffer.length < length
|
||||||
|
|
|
@ -11,7 +11,9 @@ require 'biju/pdu/type_of_address'
|
||||||
|
|
||||||
module Biju
|
module Biju
|
||||||
module PDU
|
module PDU
|
||||||
def self.encode(phone_number, message, type_of_address: :international)
|
def self.encode(phone_number, message, options = {})
|
||||||
|
type_of_address = options[:type_of_address] || :international
|
||||||
|
|
||||||
phone_number = PhoneNumber.encode(phone_number)
|
phone_number = PhoneNumber.encode(phone_number)
|
||||||
user_data = UserData.encode(message)
|
user_data = UserData.encode(message)
|
||||||
first_octet = FirstOctet.new.message_type_indicator!(:sms_submit)
|
first_octet = FirstOctet.new.message_type_indicator!(:sms_submit)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
module Biju
|
module Biju
|
||||||
module PDU
|
module PDU
|
||||||
module Encoding
|
module Encoding
|
||||||
|
@ -28,7 +30,9 @@ module Biju
|
||||||
0x65 => '€',
|
0x65 => '€',
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.decode(string, length: 0)
|
def self.decode(string, options = {})
|
||||||
|
length = options[:length] || 0
|
||||||
|
|
||||||
res = ''
|
res = ''
|
||||||
next_char = 0
|
next_char = 0
|
||||||
current_length = 0
|
current_length = 0
|
||||||
|
@ -98,7 +102,9 @@ module Biju
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_septet(char, escape: false)
|
def self.get_septet(char, options = {})
|
||||||
|
escape = options[:escape] || false
|
||||||
|
|
||||||
char = (!escape ? BASIC_7BIT_CHARACTER_SET.index(char) : BASIC_7BIT_CHARACTER_SET_EXTENSION.key(char))
|
char = (!escape ? BASIC_7BIT_CHARACTER_SET.index(char) : BASIC_7BIT_CHARACTER_SET_EXTENSION.key(char))
|
||||||
|
|
||||||
return nil unless char
|
return nil unless char
|
||||||
|
|
|
@ -2,7 +2,9 @@ module Biju
|
||||||
module PDU
|
module PDU
|
||||||
module Encoding
|
module Encoding
|
||||||
class UCS2
|
class UCS2
|
||||||
def self.decode(string, length: 0)
|
def self.decode(string, options = {})
|
||||||
|
length = options[:length] || 0
|
||||||
|
|
||||||
string.scan(/.{4}/).map { |char| char.hex.chr('UCS-2BE') }.join
|
string.scan(/.{4}/).map { |char| char.hex.chr('UCS-2BE') }.join
|
||||||
.encode('UTF-8', 'UCS-2BE')
|
.encode('UTF-8', 'UCS-2BE')
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,9 @@ module Biju
|
||||||
class PhoneNumber
|
class PhoneNumber
|
||||||
attr_accessor :type_of_address, :number
|
attr_accessor :type_of_address, :number
|
||||||
|
|
||||||
def self.encode(number, type_of_address: :international)
|
def self.encode(number, options = {})
|
||||||
|
type_of_address = options[:type_of_address] || :international
|
||||||
|
|
||||||
number = number + 'F' if number.length.odd?
|
number = number + 'F' if number.length.odd?
|
||||||
new(
|
new(
|
||||||
number.scan(/../).map(&:reverse).join,
|
number.scan(/../).map(&:reverse).join,
|
||||||
|
@ -11,7 +13,9 @@ module Biju
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(number, type_of_address: :international)
|
def initialize(number, options = {})
|
||||||
|
type_of_address = options[:type_of_address] || :international
|
||||||
|
|
||||||
self.number = number
|
self.number = number
|
||||||
self.type_of_address = TypeOfAddress.new(type_of_address)
|
self.type_of_address = TypeOfAddress.new(type_of_address)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,10 +6,10 @@ module Biju
|
||||||
ucs2: Encoding::UCS2,
|
ucs2: Encoding::UCS2,
|
||||||
}
|
}
|
||||||
|
|
||||||
attr_accessor :encoding, :message, :length
|
attr_accessor :encoding, :message, :length, :user_data_header
|
||||||
|
|
||||||
def self.encode(message, encoding: nil)
|
def self.encode(message, options = {})
|
||||||
encoding = DataCodingScheme.autodetect(message) if encoding.nil?
|
encoding = options[:encoding] || DataCodingScheme.autodetect(message)
|
||||||
|
|
||||||
raise ArgumentError, 'Unknown encoding' unless ENCODING.has_key?(encoding)
|
raise ArgumentError, 'Unknown encoding' unless ENCODING.has_key?(encoding)
|
||||||
res = ENCODING[encoding].encode(message)
|
res = ENCODING[encoding].encode(message)
|
||||||
|
@ -17,10 +17,13 @@ module Biju
|
||||||
new(message: res[0], length: res[1][:length], encoding: encoding)
|
new(message: res[0], length: res[1][:length], encoding: encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(message: '', length: 0, encoding: :gsm7bit)
|
def initialize(options = {})
|
||||||
self.encoding = DataCodingScheme.new(encoding)
|
self.encoding = DataCodingScheme.new(options[:encoding] || :gsm7bit)
|
||||||
self.message = message
|
self.message = options[:message] || ''
|
||||||
self.length = length
|
|
||||||
|
self.length = options[:length] || 0
|
||||||
|
|
||||||
|
self.user_data_header = options[:user_data_header] || false
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode
|
def decode
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'biju/pdu'
|
require 'biju/pdu'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'biju/pdu/encoding/gsm7bit'
|
require 'biju/pdu/encoding/gsm7bit'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'biju/pdu/encoding/ucs2'
|
require 'biju/pdu/encoding/ucs2'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue