exotel 0.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,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in exotel.gemspec
4
+ gemspec
@@ -0,0 +1,4 @@
1
+ exotel
2
+ ======
3
+
4
+ Exotel gem wrapper api
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.ruby_opts << "-rubygems"
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/exotel/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "exotel"
6
+ s.version = Exotel::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Vijendra Rao']
9
+ s.email = ['vijendrakarkala@gmail.com']
10
+ s.homepage = %q{https://github.com/vijendra/exotel}
11
+ s.summary = "Wrapper for exotel api"
12
+ s.description = "Exotel api wrapper."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "exotel"
16
+
17
+ s.add_development_dependency "bundler", ">= 1.0.0"
18
+ s.add_development_dependency "webmock"
19
+
20
+ s.add_dependency 'httparty', '>= 0.9.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
24
+ s.require_path = 'lib'
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'httparty'
2
+ require 'exotel/config'
3
+ require 'exotel/sms'
4
+ require 'exotel/response'
5
+
6
+ module Exotel
7
+
8
+ end
9
+
10
+
@@ -0,0 +1,15 @@
1
+ module Exotel
2
+ class << self
3
+ attr_accessor :exotel_sid, :exotel_token
4
+
5
+ def configure
6
+ yield self
7
+ end
8
+ end
9
+
10
+ class AuthenticationError < StandardError; end
11
+
12
+ class UnexpectedError < StandardError; end
13
+ end
14
+
15
+
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Exotel
3
+ class Response
4
+ attr_accessor :sid, :date_created, :date_updated, :status, :date_sent, :to, :from, :body
5
+
6
+ def initialize(response)
7
+ parsed_response = MultiXml.parse(response)
8
+ sms = parsed_response['TwilioResponse']['SMSMessage']
9
+ @sid = sms['Sid']
10
+ @date_created = sms['DateCreated']
11
+ @date_updated = sms['DateUpdated']
12
+ @status = sms['Status']
13
+ @date_sent = sms['DateSent']
14
+ @to = sms['To']
15
+ @from = sms['From']
16
+ @body = sms['Body']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'httparty'
3
+ module Exotel
4
+ class Sms
5
+ include HTTParty
6
+ base_uri "https://twilix.exotel.in/v1/Accounts/#{Exotel.exotel_sid}"
7
+
8
+ def initialize(params={})
9
+ @fields = {From: params[:from], To: params[:to], Body: params[:body]}
10
+ end
11
+
12
+ def send
13
+ options = {body: @fields, basic_auth: auth }
14
+ response = self.class.post('/Sms/send', options)
15
+ handle_response(response)
16
+ end
17
+
18
+ protected
19
+
20
+ def auth
21
+ {username: Exotel.exotel_sid, password: Exotel.exotel_token}
22
+ end
23
+
24
+ def handle_response(response)
25
+ case response.code.to_i
26
+ when 200...300 then Exotel::Response.new(response)
27
+ when 401 then raise Exotel::AuthenticationError, "#{response.body} Verify your sid and token."
28
+ else
29
+ raise Exotel::UnexpectedError, response.body
30
+ end
31
+ 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
+ end
38
+ end
39
+
40
+
41
+
@@ -0,0 +1,3 @@
1
+ module Exotel
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ describe Exotel do
4
+ it 'should have a version' do
5
+ Exotel::VERSION.wont_be_nil
6
+ end
7
+
8
+ it 'should have exotel_sid class variable' do
9
+ Exotel.respond_to?('exotel_sid').must_equal true
10
+ Exotel.respond_to?('exotel_sid=').must_equal true
11
+ end
12
+
13
+ it 'should have exotel_token class variable' do
14
+ Exotel.respond_to?('exotel_token').must_equal true
15
+ Exotel.respond_to?('exotel_token=').must_equal true
16
+ end
17
+
18
+ describe '.configure' do
19
+ it 'should set the class variable values' do
20
+ Exotel.exotel_sid.must_equal "test_sid"
21
+ Exotel.exotel_token.must_equal "test_token"
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ describe Exotel::Sms do
4
+ it 'should have a version' do
5
+ Exotel::Sms.must_include HTTParty
6
+ end
7
+
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}"
10
+ end
11
+
12
+ describe '#initialize' do
13
+ it "should set the fields hash as required by exotel" do
14
+ sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
15
+ fields_hash = {From: '1234', To: '4321', Body: 'Test sms'}
16
+ sms.instance_variable_get(:@fields).must_equal fields_hash
17
+ end
18
+ end
19
+
20
+ describe '#send' do
21
+ describe 'success' do
22
+ before do
23
+ 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
+ with(:body => "From=1234&To=4321&Body=Test%20sms").
26
+ to_return(:status => 200, :body => File.new(base_path + '/fixtures/sms.xml'))
27
+ end
28
+
29
+ it "should return the response object" do
30
+ sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
31
+ response = sms.send
32
+ response.class.must_equal Exotel::Response
33
+ end
34
+
35
+ it "should set the response object values" do
36
+ sms = Exotel::Sms.new(from: '1234', to: '4321', body: 'Test sms')
37
+ response = sms.send
38
+ response.sid.must_equal 'SM872fb94e3b358913777cdb313f25b46f'
39
+ response.date_created.must_equal 'Sun, 09 Dec 2012 03:48:08'
40
+ response.date_updated.must_equal 'Sun, 09 Dec 2012 03:48:10'
41
+ response.date_sent.must_equal 'Sun, 09 Dec 2012 03:48:10'
42
+ response.status.must_equal 'sent'
43
+ response.to.must_equal '4321'
44
+ response.from.must_equal '1234'
45
+ response.body.must_equal 'Test sms'
46
+ end
47
+ end
48
+
49
+ describe 'autentication failed' do
50
+ before do
51
+ 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
+ with(:body => "From=1234&To=4321&Body=Test%20sms").
54
+ to_return(:status=>401, :body => 'Authentication is required to view this page.')
55
+ end
56
+
57
+ 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
60
+ end
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,14 @@
1
+ <TwilioResponse>
2
+ <SMSMessage>
3
+ <Sid>SM872fb94e3b358913777cdb313f25b46f</Sid>
4
+ <DateCreated>Sun, 09 Dec 2012 03:48:08</DateCreated>
5
+ <DateUpdated>Sun, 09 Dec 2012 03:48:10</DateUpdated>
6
+ <DateSent>Sun, 09 Dec 2012 03:48:10</DateSent>
7
+ <AccountSid>AC5ea872f6da5a21de157d80997a64bd33</AccountSid>
8
+ <To>4321</To>
9
+ <From>1234</From>
10
+ <Body>Test sms</Body>
11
+ <Status>sent</Status>
12
+ <Flags>2</Flags>
13
+ </SMSMessage>
14
+ </TwilioResponse>
@@ -0,0 +1,9 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'exotel'
5
+
6
+ Exotel.configure do |c|
7
+ c.exotel_sid = "test_sid"
8
+ c.exotel_token = "test_token"
9
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exotel
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Vijendra Rao
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2012-12-09 00:00:00 +05:30
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: bundler
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: webmock
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 9
58
+ - 0
59
+ version: 0.9.0
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Exotel api wrapper.
63
+ email:
64
+ - vijendrakarkala@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - Gemfile
74
+ - README.md
75
+ - Rakefile
76
+ - exotel.gemspec
77
+ - lib/exotel.rb
78
+ - lib/exotel/config.rb
79
+ - lib/exotel/response.rb
80
+ - lib/exotel/sms.rb
81
+ - lib/exotel/version.rb
82
+ - test/exotel/exotel_test.rb
83
+ - test/exotel/sms_test.rb
84
+ - test/fixtures/sms.xml
85
+ - test/helper.rb
86
+ has_rdoc: true
87
+ homepage: https://github.com/vijendra/exotel
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 1
110
+ - 3
111
+ - 6
112
+ version: 1.3.6
113
+ requirements: []
114
+
115
+ rubyforge_project: exotel
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Wrapper for exotel api
120
+ test_files: []
121
+