exotel 0.1 → 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: "rake test"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ree
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exotel (0.1)
5
+ httparty (>= 0.9.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.3.2)
11
+ crack (0.3.1)
12
+ httparty (0.9.0)
13
+ multi_json (~> 1.0)
14
+ multi_xml
15
+ multi_json (1.5.0)
16
+ multi_xml (0.5.1)
17
+ webmock (1.9.0)
18
+ addressable (>= 2.2.7)
19
+ crack (>= 0.1.7)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (>= 1.0.0)
26
+ exotel!
27
+ webmock
data/README.md CHANGED
@@ -1,4 +1,30 @@
1
- exotel
1
+ # exotel - A ruby wrapper for the Exotel API
2
+ [![Build Status](https://travis-ci.org/vijendra/exotel.png?branch=master)](https://travis-ci.org/vijendra/exotel)
2
3
  ======
4
+ # Installation
5
+ gem install exotel
3
6
 
4
- Exotel gem wrapper api
7
+ ======
8
+ # Usage
9
+ # Configure authentication keys
10
+ Exotel.configure do |c|
11
+ c.exotel_sid = "Your exotel sid"
12
+ c.exotel_token = "Your exotel token"
13
+ end
14
+
15
+ #To send SMS
16
+ sms = Exotel::Sms.new
17
+ response = sms.send(from: 'FROM_NUMBER', to: 'TO_NUMBER', body: 'MESSAGE BODY')
18
+ sms_id = response.sid
19
+
20
+ #To get the details
21
+ sms = Exotel::Sms.new
22
+ response = sms.details(sms_id)
23
+ status = response.status
24
+ ======
25
+ # Run tests
26
+ rake test
27
+
28
+ ======
29
+ # TODO
30
+ Cover exotel call
@@ -16,6 +16,9 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_development_dependency "bundler", ">= 1.0.0"
18
18
  s.add_development_dependency "webmock"
19
+ if RUBY_VERSION == "1.8.7"
20
+ s.add_development_dependency 'minitest', '3.2.0'
21
+ end
19
22
 
20
23
  s.add_dependency 'httparty', '>= 0.9.0'
21
24
 
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'exotel/version'
2
3
  require 'exotel/config'
3
4
  require 'exotel/sms'
4
5
  require 'exotel/response'
@@ -4,8 +4,10 @@ module Exotel
4
4
  attr_accessor :sid, :date_created, :date_updated, :status, :date_sent, :to, :from, :body
5
5
 
6
6
  def initialize(response)
7
- parsed_response = MultiXml.parse(response)
8
- sms = parsed_response['TwilioResponse']['SMSMessage']
7
+ #To handle unexpected parsing from httparty
8
+ response = MultiXml.parse(response) unless response.is_a?(Hash)
9
+
10
+ sms = response['TwilioResponse']['SMSMessage']
9
11
  @sid = sms['Sid']
10
12
  @date_created = sms['DateCreated']
11
13
  @date_updated = sms['DateUpdated']
@@ -3,22 +3,27 @@ require 'httparty'
3
3
  module Exotel
4
4
  class Sms
5
5
  include HTTParty
6
- base_uri "https://twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}"
6
+ base_uri "https://twilix.exotel.in/v1/Accounts"
7
7
 
8
- def initialize(params={})
9
- @fields = {From: params[:from], To: params[:to], Body: params[:body]}
8
+ def initialize
10
9
  end
11
10
 
12
- def send
13
- options = {body: @fields, basic_auth: auth }
14
- response = self.class.post('/Sms/send', options)
11
+ def send(params={})
12
+ fields = {:From => params[:from], :To => params[:to], :Body => params[:body]}
13
+ options = {:body => fields, :basic_auth => auth }
14
+ response = self.class.post("/#{Exotel.exotel_sid}/Sms/send", options)
15
15
  handle_response(response)
16
16
  end
17
-
17
+
18
+ def details(sid)
19
+ response = self.class.get("/#{Exotel.exotel_sid}/Sms/Messages/#{sid}", :basic_auth => auth)
20
+ handle_response(response)
21
+ end
22
+
18
23
  protected
19
24
 
20
25
  def auth
21
- {username: Exotel.exotel_sid, password: Exotel.exotel_token}
26
+ {:username => Exotel.exotel_sid, :password => Exotel.exotel_token}
22
27
  end
23
28
 
24
29
  def handle_response(response)
@@ -29,11 +34,6 @@ module Exotel
29
34
  raise Exotel::UnexpectedError, response.body
30
35
  end
31
36
  end
32
-
33
- #TODO check how to remove this. Now it is not setting the correct url, if removed
34
- def self.base_uri
35
- "https://twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}"
36
- end
37
37
  end
38
38
  end
39
39
 
@@ -1,3 +1,3 @@
1
1
  module Exotel
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -6,9 +6,9 @@ describe Exotel::Sms do
6
6
  end
7
7
 
8
8
  it 'should have the correct base_uri' do
9
- Exotel::Sms.base_uri.must_equal "https://twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}"
9
+ Exotel::Sms.base_uri.must_equal "https://twilix.exotel.in/v1/Accounts"
10
10
  end
11
-
11
+ =begin
12
12
  describe '#initialize' do
13
13
  it "should set the fields hash as required by exotel" do
14
14
  sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
@@ -16,25 +16,26 @@ describe Exotel::Sms do
16
16
  sms.instance_variable_get(:@fields).must_equal fields_hash
17
17
  end
18
18
  end
19
+ =end
19
20
 
20
21
  describe '#send' do
21
22
  describe 'success' do
22
23
  before do
23
24
  base_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
24
- stub_request(:post, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/Sms/send").
25
+ stub_request(:post, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}/Sms/send").
25
26
  with(:body => "From=1234&To=4321&Body=Test%20sms").
26
27
  to_return(:status => 200, :body => File.new(base_path + '/fixtures/sms.xml'))
27
28
  end
28
29
 
29
30
  it "should return the response object" do
30
- sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
31
- response = sms.send
31
+ sms = Exotel::Sms.new
32
+ response = sms.send(:from => '1234', :to => '4321', :body => 'Test sms')
32
33
  response.class.must_equal Exotel::Response
33
34
  end
34
35
 
35
36
  it "should set the response object values" do
36
- sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
37
- response = sms.send
37
+ sms = Exotel::Sms.new
38
+ response = sms.send(:from => '1234', :to => '4321', :body => 'Test sms')
38
39
  response.sid.must_equal 'SM872fb94e3b358913777cdb313f25b46f'
39
40
  response.date_created.must_equal 'Sun, 09 Dec 2012 03:48:08'
40
41
  response.date_updated.must_equal 'Sun, 09 Dec 2012 03:48:10'
@@ -49,14 +50,58 @@ describe Exotel::Sms do
49
50
  describe 'autentication failed' do
50
51
  before do
51
52
  base_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
52
- stub_request(:post, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/Sms/send").
53
+ stub_request(:post, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}/Sms/send").
53
54
  with(:body => "From=1234&To=4321&Body=Test%20sms").
54
- to_return(:status=>401, :body => 'Authentication is required to view this page.')
55
+ to_return(:status => 401, :body => 'Authentication is required to view this page.')
56
+ end
57
+
58
+ it "should return the response object" do
59
+ sms = Exotel::Sms.new
60
+ proc{sms.send(:from => '1234', :to => '4321', :body => 'Test sms')}.
61
+ must_raise Exotel::AuthenticationError
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#details' do
67
+ describe 'success' do
68
+ before do
69
+ base_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
70
+ stub_request(:get, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}/Sms/Messages/SM872fb94e3b358913777cdb313f25b46f").
71
+ to_return(:status => 200, :body => File.new(base_path + '/fixtures/sms.xml'))
72
+ end
73
+
74
+ it "should return the response object" do
75
+ sms = Exotel::Sms.new
76
+ response = sms.details('SM872fb94e3b358913777cdb313f25b46f')
77
+ response.class.must_equal Exotel::Response
78
+ end
79
+
80
+ it "should set the response object values" do
81
+ sms = Exotel::Sms.new
82
+ response = sms.details('SM872fb94e3b358913777cdb313f25b46f')
83
+ response.sid.must_equal 'SM872fb94e3b358913777cdb313f25b46f'
84
+ response.date_created.must_equal 'Sun, 09 Dec 2012 03:48:08'
85
+ response.date_updated.must_equal 'Sun, 09 Dec 2012 03:48:10'
86
+ response.date_sent.must_equal 'Sun, 09 Dec 2012 03:48:10'
87
+ response.status.must_equal 'sent'
88
+ response.to.must_equal '4321'
89
+ response.from.must_equal '1234'
90
+ response.body.must_equal 'Test sms'
91
+ end
92
+ end
93
+
94
+ describe 'autentication failed' do
95
+ before do
96
+ base_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
97
+ stub_request(:get, "https://test_sid:test_token@twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}/Sms/Messages/SM872fb94e3b358913777cdb313f25b46f").
98
+ to_return(:status => 401, :body => 'Authentication is required to view this page.')
55
99
  end
56
100
 
57
101
  it "should return the response object" do
58
- sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
59
- proc{sms.send}.must_raise Exotel::AuthenticationError
102
+ sms = Exotel::Sms.new
103
+ proc{sms.details('SM872fb94e3b358913777cdb313f25b46f')}.
104
+ must_raise Exotel::AuthenticationError
60
105
  end
61
106
  end
62
107
  end
metadata CHANGED
@@ -1,11 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exotel
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- version: "0.1"
4
+ prerelease:
5
+ version: 0.1.1
9
6
  platform: ruby
10
7
  authors:
11
8
  - Vijendra Rao
@@ -13,8 +10,7 @@ autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
12
 
16
- date: 2012-12-09 00:00:00 +05:30
17
- default_executable:
13
+ date: 2012-12-21 00:00:00 Z
18
14
  dependencies:
19
15
  - !ruby/object:Gem::Dependency
20
16
  name: bundler
@@ -24,10 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 0
30
- - 0
31
23
  version: 1.0.0
32
24
  type: :development
33
25
  version_requirements: *id001
@@ -39,8 +31,6 @@ dependencies:
39
31
  requirements:
40
32
  - - ">="
41
33
  - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
34
  version: "0"
45
35
  type: :development
46
36
  version_requirements: *id002
@@ -52,10 +42,6 @@ dependencies:
52
42
  requirements:
53
43
  - - ">="
54
44
  - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- - 9
58
- - 0
59
45
  version: 0.9.0
60
46
  type: :runtime
61
47
  version_requirements: *id003
@@ -70,7 +56,9 @@ extra_rdoc_files: []
70
56
 
71
57
  files:
72
58
  - .gitignore
59
+ - .travis.yml
73
60
  - Gemfile
61
+ - Gemfile.lock
74
62
  - README.md
75
63
  - Rakefile
76
64
  - exotel.gemspec
@@ -83,7 +71,6 @@ files:
83
71
  - test/exotel/sms_test.rb
84
72
  - test/fixtures/sms.xml
85
73
  - test/helper.rb
86
- has_rdoc: true
87
74
  homepage: https://github.com/vijendra/exotel
88
75
  licenses: []
89
76
 
@@ -97,23 +84,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
84
  requirements:
98
85
  - - ">="
99
86
  - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
87
  version: "0"
103
88
  required_rubygems_version: !ruby/object:Gem::Requirement
104
89
  none: false
105
90
  requirements:
106
91
  - - ">="
107
92
  - !ruby/object:Gem::Version
108
- segments:
109
- - 1
110
- - 3
111
- - 6
112
93
  version: 1.3.6
113
94
  requirements: []
114
95
 
115
96
  rubyforge_project: exotel
116
- rubygems_version: 1.3.7
97
+ rubygems_version: 1.8.24
117
98
  signing_key:
118
99
  specification_version: 3
119
100
  summary: Wrapper for exotel api