pdu_tools 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6225fad4da69e410d036d30768c0505b4c8b8e98
4
- data.tar.gz: 3e4dcfdf46d80c94c9eee50a7911217b6d553f4c
3
+ metadata.gz: 06ded51dcb3fdfb9d87daaef9a8c02ef5e19de63
4
+ data.tar.gz: 3efee7cc8d604557a5fa21a1d4df903d91a4d530
5
5
  SHA512:
6
- metadata.gz: d1a190e95d0316c6fda4734a583b09cb5fce298a8778647282422afb6680fb18baa88559fd6286de7a35024de26548e2d5c776a4b4a94ba32d417202648e6f69
7
- data.tar.gz: e7e81536dbce8028fca9a5f8e4b176e0e54f7b87b93e0b562be6caa70e17a01e882ec5082f12155d4c5dff8eac96ef7e717fc293580f4b1abc5fc12153cca13d
6
+ metadata.gz: fb25dcbe8ac3bdb520903503e76b2fe6737e1440cc3ba4b9db71afed3047c3307ba7aa84b8cbba4155d12a01c142d673fc7156a8977416183d761105a725b0db
7
+ data.tar.gz: ed46a7682758a220c4b26ce19611b2f93327f7b4d04768faabeea086b38b51d7c4380abd36d785bc96a2168755ddbe10d6100558d0536a7831a016863efcc469
@@ -12,16 +12,16 @@ module PDUTools
12
12
  @sca_length = take(2, :integer) * 2 # Service center address length
13
13
  if @sca_length > 0
14
14
  @sca_type = parse_address_type take(2) # Service center address type
15
- @sca = parse_address take(@sca_length - 2), @sca_type # Service center address
15
+ @sca = parse_address take(@sca_length - 2), @sca_type, @sca_length # Service center address
16
16
  end
17
17
  @pdu_type = parse_pdu_type take(2, :binary) # PDU type octet
18
18
  @message_reference = take(2) if @pdu_type[:mti] == :sms_submit
19
19
  @address_length = take(2, :integer)
20
20
  @address_type = parse_address_type take(2)
21
- @address = parse_address take(@address_length), @address_type
21
+ @address = parse_address take(@address_length), @address_type, @address_length
22
22
  @pid = take(2)
23
23
  @data_coding_scheme = parse_data_coding_scheme take(2, :binary)
24
- @sc_timestamp = parse_7byte_timestamp take(14) if @pdu_type[:mti] == :sms_deliver
24
+ @sc_timestamp = parse_7byte_timestamp take(14) if [:sms_deliver, :sms_deliver_report].include? @pdu_type[:mti]
25
25
  case @pdu_type[:vpf]
26
26
  when :absolute
27
27
  @validity_period = parse_7byte_timestamp take(14)
@@ -68,14 +68,22 @@ module PDUTools
68
68
  when "81"
69
69
  :national
70
70
  else
71
- raise StandardError, "unknown address type"
71
+ if type.to_i(16).to_s(2)[1,3] == "101"
72
+ :a7bit
73
+ else
74
+ raise StandardError, "unknown address type: #{type}"
75
+ end
72
76
  end
73
77
  end
74
78
 
75
- def parse_address address, type
76
- address = swapped2normal address
77
- if type == :international
78
- address.prepend "+"
79
+ def parse_address address, type, length
80
+ if type == :a7bit
81
+ address = decode7bit address, length
82
+ else
83
+ address = swapped2normal address
84
+ if type == :international
85
+ address.prepend "+"
86
+ end
79
87
  end
80
88
  address
81
89
  end
@@ -101,7 +101,6 @@ module PDUTools
101
101
 
102
102
  def prepare_recipient recipient
103
103
  Phoner::Phone.default_country_code ||= "421"
104
-
105
104
  address_type = "91" # International
106
105
  address = Phoner::Phone.parse(recipient).format("%c%a%n")
107
106
  address_length = "%02X" % address.length
data/spec/decoder_spec.rb CHANGED
@@ -32,4 +32,14 @@ describe PDUTools::Decoder do
32
32
  expect(message_part.user_data_header[:part_number]).to eq 1
33
33
  end
34
34
  end
35
+
36
+ context "GSM PLMNS address type" do
37
+ let(:pdu) { "07912491500030592414D044241354C4C3E5E5F91C00004190200180108095D6B0BEECCE83F4E17558EF4EAF5920B2BB3C0759C36D10485C27D741E4B7BC3E7EDBC3EE32481F9EA7CBEC751E0485324132980D0793C96EB7196E0792C16C38984C76BBCD6E3B900C66C3C164B2DB6D666381C86F71BA2C5F8741319A2CC7CA818A75B90BB47CBBE9E1351D0482E568B4D94D768BDD5C202292092AE2E1F2F27C0E02" }
38
+ it do
39
+ message_part = decoder.decode
40
+ expect(message_part.address).to eq("DHL Express")
41
+ expect(message_part.body).to match /^Vazeny zakaznik/
42
+ end
43
+ end
44
+
35
45
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,6 @@
1
- require 'pdu_tools'
1
+ require 'pdu_tools'
2
+ require 'pry'
3
+ RSpec.configure do |config|
4
+ config.filter_run focus: true
5
+ config.run_all_when_everything_filtered = true
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdu_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Zachar