cardboardfish 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/cardboardfish.gemspec +1 -1
- data/lib/cardboardfish.rb +36 -0
- data/spec/cardboardfish_spec.rb +22 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/cardboardfish.gemspec
CHANGED
data/lib/cardboardfish.rb
CHANGED
@@ -35,8 +35,44 @@ module Cardboardfish
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.parse(receipt)
|
39
|
+
parts = receipt.split("#")
|
40
|
+
count = parts.shift
|
41
|
+
receipts = []
|
42
|
+
parts.each do |p|
|
43
|
+
receipts << self.parse_fragment(p)
|
44
|
+
end
|
45
|
+
return receipts
|
46
|
+
end
|
47
|
+
|
38
48
|
private
|
39
49
|
|
50
|
+
def self.parse_fragment(part)
|
51
|
+
fragments = part.split(":")
|
52
|
+
msg = {
|
53
|
+
:id => fragments[0],
|
54
|
+
:source => fragments[1],
|
55
|
+
:destination => fragments[2],
|
56
|
+
:status => delivery_receipt_codes[fragments[3]],
|
57
|
+
:gsm_error_code => fragments[4],
|
58
|
+
:time => Time.at(fragments[5].to_i),
|
59
|
+
:ref => fragments[6]
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.delivery_receipt_codes
|
64
|
+
codes = {}
|
65
|
+
codes["1"] = "DELIVERED"
|
66
|
+
codes["2"] = "BUFFERED"
|
67
|
+
codes["3"] = "FAILED"
|
68
|
+
codes["5"] = "EXPIRED"
|
69
|
+
codes["6"] = "REJECTED"
|
70
|
+
codes["7"] = "ERROR"
|
71
|
+
codes["11"] = "UNKNOWN"
|
72
|
+
codes["12"] = "UNKNOWN"
|
73
|
+
return codes
|
74
|
+
end
|
75
|
+
|
40
76
|
def self.defaults
|
41
77
|
defaults = {}
|
42
78
|
defaults[:system_type] = 'H'
|
data/spec/cardboardfish_spec.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Cardboardfish" do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
it "should parse a single receipt" do
|
6
|
+
fixture = {
|
7
|
+
:id => "361520192",
|
8
|
+
:source => "Jane",
|
9
|
+
:destination => "353868442660",
|
10
|
+
:status => "FAILED",
|
11
|
+
:gsm_error_code => "000",
|
12
|
+
#:time => Time.new("Thu, 04 Nov 2010 03:44:01 GMT +00:00"),
|
13
|
+
:ref => nil
|
14
|
+
}
|
15
|
+
receipts = Cardboardfish.parse("1#361520192:Jane:353868442660:3:000:1288842241::")
|
16
|
+
receipts.kind_of?(Array).should be_true
|
17
|
+
|
18
|
+
receipt = receipts.first
|
19
|
+
|
20
|
+
receipt[:id].should == fixture[:id]
|
21
|
+
receipt[:source].should == fixture[:source]
|
22
|
+
receipt[:destination].should == fixture[:destination]
|
23
|
+
receipt[:status].should == fixture[:status]
|
24
|
+
receipt[:gsm_error_code].should == fixture[:gsm_error_code]
|
25
|
+
receipt[:ref].should == fixture[:ref]
|
6
26
|
end
|
7
27
|
end
|