smsified 0.1.4 → 0.1.5

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/README.md CHANGED
@@ -28,6 +28,18 @@ Find a subscription:
28
28
  subscriptions = Smsified::Subscriptions.new(:username => 'user', :password => 'bug.fungus24')
29
29
  subscriptions.inbound_subscriptions('17177455076')
30
30
 
31
+ Parse the JSON for a callback Incoming Message:
32
+
33
+ require 'rubygems'
34
+ require 'smsified'
35
+ # Also require your favorite web framework such as Rails or Sinatra
36
+ incoming_message = Smsified::IncomingMessage.new json_body
37
+ puts incoming_message.date_time # Wed May 11 18:05:54 UTC 2011
38
+ puts incoming_message.destination_address # '16575550100'
39
+ puts incoming_message.message # 'Inbound test'
40
+ puts incoming_message.message_id # 'ef795d3dac56a62fef3ff1852b0c123a'
41
+ puts incoming_message.sender_address # '14075550100'
42
+
31
43
  Documentation
32
44
  -------------
33
45
 
@@ -23,7 +23,7 @@ module Smsified
23
23
  end
24
24
 
25
25
  if options[:callback_data]
26
- params[:callbackData] = options[:callback_data]
26
+ options[:callbackData] = options[:callback_data]
27
27
  options.delete(:callback_data)
28
28
  end
29
29
 
@@ -0,0 +1,33 @@
1
+ module Smsified
2
+ class IncomingMessage
3
+ attr_reader :date_time, :destination_address, :message, :message_id, :sender_address, :json
4
+
5
+ ##
6
+ # Intantiate a new object to provide convenience methods on an Incoming Message
7
+ # http://www.smsified.com/sms-api-documentation/receiving
8
+ #
9
+ # @param [required, String] valid JSON for an Incoming Message to be parsed
10
+ # @return [Object] the parsed incoming message
11
+ # @raise [ArgumentError] if json is not valid JSON or an Incoming Message type
12
+ # @example
13
+ # incoming_message = IncomingMessage.new(json)
14
+ # puts incoming_message.message # foobar
15
+ def initialize(json)
16
+ begin
17
+ @json = JSON.parse json
18
+
19
+ contents = @json['inboundSMSMessageNotification']['inboundSMSMessage']
20
+
21
+ @date_time = Time.parse contents['dateTime']
22
+ @destination_address = contents['destinationAddress']
23
+ @message = contents['message']
24
+ @message_id = contents['messageId']
25
+ @sender_address = contents['senderAddress']
26
+ rescue => error
27
+ raise MessageError, "Not valid JSON or IncomingMessage"
28
+ end
29
+ end
30
+
31
+ class MessageError < StandardError; end
32
+ end
33
+ end
data/lib/smsified.rb CHANGED
@@ -1,2 +1,12 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- %w(cgi httparty smsified/helpers smsified/oneapi smsified/subscriptions smsified/reporting smsified/response).each { |lib| require lib }
2
+ %w(
3
+ cgi
4
+ httparty
5
+ time
6
+ smsified/helpers
7
+ smsified/oneapi
8
+ smsified/subscriptions
9
+ smsified/reporting
10
+ smsified/response
11
+ smsified/incoming_message
12
+ ).each { |lib| require lib }
@@ -11,6 +11,30 @@ describe "Smsified" do
11
11
  @sender_address = '13035551212'
12
12
  end
13
13
 
14
+ describe "Helpers" do
15
+ it 'Should camelcase the appropriate keys' do
16
+ class Foo
17
+ include Smsified::Helpers
18
+
19
+ attr_reader :keys
20
+
21
+ def initialize(hash)
22
+ @keys = camelcase_keys(hash)
23
+ end
24
+ end
25
+
26
+ camelcased_keys = Foo.new({ :destination_address => 'foo',
27
+ :notify_url => 'bar',
28
+ :client_correlator => 'baz',
29
+ :callback_data => 'donkey' }).keys
30
+
31
+ camelcased_keys[:destinationAddress].should eql 'foo'
32
+ camelcased_keys[:notifyURL].should eql 'bar'
33
+ camelcased_keys[:clientCorrelator].should eql 'baz'
34
+ camelcased_keys[:callbackData].should eql 'donkey'
35
+ end
36
+ end
37
+
14
38
  describe "OneAPI" do
15
39
  before(:all) do
16
40
  @one_api = Smsified::OneAPI.new :username => @username, :password => @password, :debug => true
@@ -254,6 +278,7 @@ describe "Smsified" do
254
278
 
255
279
  describe 'Updated subscriptions' do
256
280
  before(:all) do
281
+ @inbound_subscription = { "resourceReference" => { "resourceURL" => "https://api.smsified.com/v1/smsmessaging/inbound/subscriptions/e636368b7fddac0e93e34ae03bad33dd" } }
257
282
  @outbound_subscription = { "resourceReference" => { "resourceURL" => "https://api.smsified.com/v1/smsmessaging/outbound/subscriptions/4bc465cd394c9f5e78802af5ad6bb442" } }
258
283
 
259
284
  FakeWeb.register_uri(:post,
@@ -263,11 +288,10 @@ describe "Smsified" do
263
288
  end
264
289
 
265
290
  it 'Should update an inbound subscription' do
266
- pending('udpate resources being deployed')
267
291
  result = @subscriptions.update_inbound_subscription('c880c96f161f6220d4977b29b4bfc111', :notify_url => 'http://foobar1.com')
268
292
 
269
293
  result.http.code.should eql '200'
270
- result.data.should eql nil
294
+ result.data.should eql @inbound_subscription
271
295
  end
272
296
 
273
297
  it 'Should update an outbound subscription' do
@@ -443,4 +467,35 @@ describe "Smsified" do
443
467
  sms_message.data.should eql @message
444
468
  end
445
469
  end
470
+
471
+ describe 'IncomingMessage' do
472
+ it 'Should parse an incoming message from SMSified' do
473
+ json = '{
474
+ "inboundSMSMessageNotification": {
475
+ "inboundSMSMessage": {
476
+ "dateTime": "2011-05-11T18:05:54.546Z",
477
+ "destinationAddress": "16575550100",
478
+ "message": "Inbound test",
479
+ "messageId": "ef795d3dac56a62fef3ff1852b0c123a",
480
+ "senderAddress": "14075550100"
481
+ }
482
+ }
483
+ }'
484
+
485
+ incoming_message = Smsified::IncomingMessage.new json
486
+ incoming_message.date_time.should eql Time.parse '2011-05-11T18:05:54.546Z'
487
+ incoming_message.destination_address.should eql '16575550100'
488
+ incoming_message.message.should eql 'Inbound test'
489
+ incoming_message.message_id.should eql 'ef795d3dac56a62fef3ff1852b0c123a'
490
+ incoming_message.sender_address.should eql '14075550100'
491
+ end
492
+
493
+ it "Should raise an error if JSON not passed" do
494
+ lambda { Smsified::IncomingMessage.new 'foobar' }.should raise_error(Smsified::IncomingMessage::MessageError)
495
+ end
496
+
497
+ it "Should raise an error if a different type than an IncomingMessage is passed" do
498
+ lambda { Smsified::IncomingMessage.new "{ 'foo': 'bar'}" }.should raise_error(Smsified::IncomingMessage::MessageError)
499
+ end
500
+ end
446
501
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsified
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Goecke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-24 00:00:00 -07:00
18
+ date: 2011-07-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -165,6 +165,7 @@ files:
165
165
  - README.md
166
166
  - lib/smsified.rb
167
167
  - lib/smsified/helpers.rb
168
+ - lib/smsified/incoming_message.rb
168
169
  - lib/smsified/oneapi.rb
169
170
  - lib/smsified/reporting.rb
170
171
  - lib/smsified/response.rb