cardboardfish 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cardboardfish}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Rice"]
@@ -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'
@@ -1,7 +1,27 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Cardboardfish" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Rice