mblox 0.2.9 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODgwZjU3MWFlNWUzYjI1OTAxNzBlY2MwMmI0NTNhZmE0Y2M1YjMxMw==
4
+ NDhiNjUwZDE4N2YyOTU3MGI3NWQ2MjBmYmUxODYzOTAzZjdjOGNjMA==
5
5
  data.tar.gz: !binary |-
6
- OGVkNTE1ZWRmZjY1ZmRkN2JlMmJlYmU2MTQ1ZmQyMjEzODExYzdmMg==
6
+ MDc4NzYxYWE4MjhkZGJiNDE5OTZiNGUyODBhODNhMWZkZDZlOGQ4NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGYyYjhlNjQxNjljM2Q5M2I3NDZjZGZmZmMzNGU4Y2I0ZDdmZDQ5ZmMzN2Y3
10
- YzlmODE1YjFmZTI1YWU2M2I5MmEwMWJiYTM0ZjRlNmRmMjlhMzQ0M2NmZjFk
11
- MDdjMmQyMjY4OTgxMmJjOWI1MWJhNDRmOThjOTg0NmRkNjk5ZWM=
9
+ OGNhNjBjYjI0NWUxMGJmZGU3ODQxZTIyMDNiNjIwNjk1NzNkNDdkNzQ3Zjc3
10
+ OTc1NWI5MDk3ZjU0OTAzZTE4YTE0YjY4YTAwZjEzOTM1YjJjZDllNWUyMDEz
11
+ NmUxMzQ2YjJmZWVhZjgyZTVlODA4YmNkMjZjY2U3ZjZiYmVjN2I=
12
12
  data.tar.gz: !binary |-
13
- NWUyMTNkZTVjZDYxOTg2MTVmNTdlMTdlYjZhZDNmNWY5YjgyMGQ5NDBkZDli
14
- ZWNlN2I4OWYwMWUxMzY2N2IwYzhiMjI1OGZmNWY5ZDcyYzU5NTMzMWJjNjFk
15
- ZGM0MDI1MTFlYTdhOGM4NmM5MjQ5YTQzY2M1MDAwMjY0YjA1YTc=
13
+ MTNiMThhMDMzZTRkZTJlZmIyNGQ0OWVjMzIxNTNkYzJiN2Y4YWY5NzdmYTdm
14
+ MmIxNjE5NDI3NDZkYWY3MTlmMmUzODAwYzgwYzg4NTAwNTY5ZWNiNTBmODU1
15
+ ZTJhYTRjNWRiOTkzZTk1ZWY0MTFiZTFmMWIwYjRhMGE0OGMzY2U=
@@ -1,15 +1,11 @@
1
- require 'active_model/serialization'
2
- require 'active_model/serializers/xml.rb'
1
+ require 'nokogiri'
3
2
 
4
3
  module Mblox
5
4
  class MissingExpectedXmlContentError < StandardError; end
6
-
7
5
  class << self
8
6
  def from_xml(xml)
9
- begin
10
- Hash.from_xml(xml)
11
- rescue REXML::ParseException
12
- raise MissingExpectedXmlContentError, "'#{xml}' is not parseable as XML"
7
+ Nokogiri::XML(xml) { |config| config.nonet }.tap do |_|
8
+ raise MissingExpectedXmlContentError, "'#{xml}' is not parseable as XML" unless _.errors.empty?
13
9
  end
14
10
  end
15
11
  end
@@ -2,38 +2,49 @@ require 'mblox/from_xml'
2
2
 
3
3
  module Mblox
4
4
  class SmsReceipt
5
- attr_reader :batch_id, :subscriber_number, :timestamp, :msg_reference, :status, :reason
5
+ attr_reader :batch_id, :subscriber_number, :timestamp, :msg_reference, :status, :reason, :operator
6
6
  def initialize(xml)
7
- data = Mblox.from_xml(xml)['NotificationService']
7
+ data = Mblox.from_xml(xml).xpath '//NotificationService'
8
8
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' node, but was #{xml}" if data.blank?
9
9
 
10
- data = data['NotificationList']
10
+ data = data.xpath '//NotificationList'
11
11
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' node, but was #{xml}" if data.blank?
12
12
 
13
- data = data['Notification']
13
+ data = data.xpath '//Notification'
14
14
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' -> 'Notification' node, but was #{xml}" if data.blank?
15
+ @batch_id = data.attribute('BatchID').value.to_i
15
16
 
16
- @batch_id = data['BatchID'].to_i
17
-
18
- data = data['Subscriber']
17
+ data = data.xpath '//Subscriber'
19
18
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' -> 'Notification' -> 'Subscriber' node, but was #{xml}" if data.blank?
20
19
 
21
- @subscriber_number = data['SubscriberNumber']
20
+ @subscriber_number = value_at(:SubscriberNumber, data)
22
21
  @subscriber_number = @subscriber_number[1..-1] if '1' == @subscriber_number[0]
23
22
 
24
- unless data['TimeStamp'].blank?
23
+ timestamp = value_at(:TimeStamp, data)
24
+ unless timestamp.blank?
25
25
  @timestamp = begin
26
- Time.strptime("#{data['TimeStamp']}+0000", '%Y%m%d%H%M%z')
26
+ Time.strptime("#{timestamp}+0000", '%Y%m%d%H%M%z')
27
27
  rescue ArgumentError
28
28
  nil
29
29
  end
30
30
  end
31
31
 
32
32
  @timestamp = @timestamp.to_datetime if @timestamp
33
-
34
- @msg_reference = data['MsgReference']
35
- @status = data['Status']
36
- @reason = data['Reason'].blank? ? nil : data['Reason'].to_i
33
+ @msg_reference = value_at(:MsgReference, data)
34
+ @status = value_at(:Status, data)
35
+ reason = value_at(:Reason, data)
36
+ @reason = reason.blank? ? nil : reason.to_i
37
+ data = data.xpath('//Tags').xpath('//Tag')
38
+ return if data.empty?
39
+ data.each do |d|
40
+ @operator = d.child.content.to_i if "Operator" == data.attribute('Name').content
41
+ return if @operator
42
+ end
37
43
  end
44
+ private
45
+ def value_at(path, data)
46
+ data = data.xpath("//#{path}")
47
+ (data.empty? || data.children.empty?) ? nil : data.first.child.content
48
+ end
38
49
  end
39
50
  end
@@ -19,6 +19,11 @@ module Mblox
19
19
  @code, @text = (code.to_i.to_s == code ? code.to_i : code), text
20
20
  end
21
21
 
22
+ def self.from_xml(xml, xpath)
23
+ code, text = xml.xpath("//#{xpath}Code"), xml.xpath("//#{xpath}Text")
24
+ new(code.first.child.content, text.first.child.content)
25
+ end
26
+
22
27
  def ok?
23
28
  0 == @code
24
29
  end
@@ -33,25 +38,25 @@ module Mblox
33
38
 
34
39
  attr_reader :request, :result, :subscriber_result
35
40
  def initialize(xml)
36
- data = Mblox.from_xml(xml)['NotificationRequestResult']
41
+ data = Mblox.from_xml(xml).xpath '//NotificationRequestResult'
37
42
 
38
43
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' node, but was #{xml}" if data.blank?
39
- header = data['NotificationResultHeader']
44
+ header = data.xpath '//NotificationResultHeader'
40
45
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultHeader' node, but was #{xml}" if header.blank?
41
- @request = Result.new(header['RequestResultCode'], header['RequestResultText'])
46
+ @request = Result.from_xml(header, :RequestResult)
42
47
  @request = nil unless @request.valid?
43
48
 
44
- result_list = data['NotificationResultList']
49
+ result_list = data.xpath '//NotificationResultList'
45
50
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' node, but was #{xml}" if result_list.blank?
46
- result_list = result_list['NotificationResult']
51
+ result_list = result_list.xpath '//NotificationResult'
47
52
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' -> 'NotificationResult' node, but was #{xml}" if result_list.blank?
48
- @result = Result.new(result_list['NotificationResultCode'], result_list['NotificationResultText'])
53
+ @result = Result.from_xml(result_list, :NotificationResult)
49
54
  @result = nil unless @result.valid?
50
55
 
51
56
  if @result.ok?
52
- result_list = result_list['SubscriberResult']
57
+ result_list = result_list.xpath '//SubscriberResult'
53
58
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' -> 'NotificationResult' -> 'SubscriberResult' node, but was #{xml}" if result_list.blank?
54
- @subscriber_result = Result.new(result_list['SubscriberResultCode'], result_list['SubscriberResultText'])
59
+ @subscriber_result = Result.from_xml(result_list, :SubscriberResult)
55
60
  @subscriber_result = nil unless @subscriber_result.valid?
56
61
  end
57
62
  end
data/lib/mblox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mblox
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
data/mblox.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency 'activesupport'
27
27
  spec.add_runtime_dependency 'addressable'
28
28
  spec.add_runtime_dependency 'builder'
29
+ spec.add_runtime_dependency "nokogiri", ">= 1.5.0"
29
30
  end
@@ -33,6 +33,9 @@ describe Mblox::SmsReceipt do
33
33
  s.MsgReference(msg_reference)
34
34
  s.Status(status)
35
35
  s.Reason(reason)
36
+ s.Tags do |t|
37
+ t.Tag(10487, :Name => :Operator)
38
+ end
36
39
  end
37
40
  end
38
41
  end
@@ -105,6 +108,7 @@ describe Mblox::SmsReceipt do
105
108
  target.msg_reference.should == msg_reference
106
109
  target.status.should == status
107
110
  target.reason.should == reason
111
+ target.operator.should == 10487
108
112
  end
109
113
 
110
114
  it "should raise error when missing root node" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Betesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.5.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.5.0
111
125
  description: Send SMS messages
112
126
  email:
113
127
  - iybetesh@gmail.com