kazoo-rb 0.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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ kazoo.yml
2
+ examples/private_conf
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'nestful', :git => 'git://github.com/zlu/nestful.git'
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ GIT
2
+ remote: git://github.com/zlu/nestful.git
3
+ revision: c6e3d981545d5054778e40d7b573a521ba1a600a
4
+ specs:
5
+ nestful (0.0.8)
6
+ activesupport (>= 3.0.0.beta)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ kazoo-rb (0.0.1)
12
+ nestful
13
+
14
+ GEM
15
+ remote: http://rubygems.org/
16
+ specs:
17
+ activesupport (3.2.8.rc2)
18
+ i18n (~> 0.6)
19
+ multi_json (~> 1.0)
20
+ addressable (2.2.8)
21
+ crack (0.1.8)
22
+ diff-lcs (1.1.3)
23
+ i18n (0.6.0)
24
+ multi_json (1.3.6)
25
+ rake (0.9.2.2)
26
+ rspec (2.11.0)
27
+ rspec-core (~> 2.11.0)
28
+ rspec-expectations (~> 2.11.0)
29
+ rspec-mocks (~> 2.11.0)
30
+ rspec-core (2.11.1)
31
+ rspec-expectations (2.11.2)
32
+ diff-lcs (~> 1.1.3)
33
+ rspec-mocks (2.11.1)
34
+ webmock (1.8.8)
35
+ addressable (~> 2.2.8)
36
+ crack (>= 0.1.7)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ kazoo-rb!
43
+ nestful!
44
+ rake
45
+ rspec
46
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 Zhao Lu
2
+ http://zlu.me
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ [![Build Status](https://secure.travis-ci.org/zlu/kazoo-rb.png)](http://travis-ci.org/zlu/kazoo-rb)
2
+
3
+ Kazoo-rb
4
+ ====
5
+
6
+ Ruby library for [Kazoo](http://www.2600hz.com/platform.html)
7
+
8
+ First, copy lib/kazoo.yml.sample to lib/kazoo.yml and fill in your Kazoo credentials
9
+
10
+ ## Conference
11
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new do |spec|
5
+ spec.rspec_opts = '--color'
6
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'kazoo'
6
+
7
+ def init_config
8
+ YAML.load(File.open(File.join(File.expand_path("../../lib", __FILE__), 'kazoo.yml')))
9
+ end
10
+
11
+ phone_number = []
12
+ ARGV.each do |number|
13
+ phone_number << number
14
+ end
15
+
16
+ auth = Kazoo::Auth.new(init_config)
17
+ conf = Kazoo::Conference.new(auth)
18
+ conf.create_callflow(phone_number)
19
+ conf.create_room('test conf room', ['1234'])
20
+
data/kazoo.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kazoo/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "kazoo-rb"
7
+ s.version = Kazoo::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Zhao Lu"]
10
+ s.email = %q{zlu@me.com}
11
+ s.date = %q{2012-07-30}
12
+ s.homepage = "https://github.com/zlu/kazoo-rb"
13
+ s.summary = %q{Ruby wrapper for Kazoo}
14
+ s.description = %q{Ruby wrapper for Kazoo, a powerful telephony platform}
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+
20
+ s.rdoc_options = %w{--charset=UTF-8}
21
+ s.extra_rdoc_files = %w{README.md}
22
+
23
+ s.add_dependency("nestful")
24
+
25
+ s.add_development_dependency('rake')
26
+ s.add_development_dependency("rspec")
27
+ s.add_development_dependency("webmock")
28
+ end
data/lib/kazoo.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+ require 'nestful'
3
+
4
+ $:.unshift(File.dirname(__FILE__))
5
+ require 'kazoo/auth'
6
+ require 'kazoo/conference'
7
+ require 'kazoo/connection_error'
8
+
9
+ module Kazoo
10
+ extend self
11
+ end
@@ -0,0 +1,5 @@
1
+ api_key: 'your_kazoo_developer_api_key'
2
+ account_id: 'your_account_id'
3
+ host: 'api.2600hz.com'
4
+ port: '8000'
5
+ version: 'v1'
data/lib/kazoo/auth.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Kazoo
2
+ class Auth
3
+ attr_reader :api_key, :host, :port, :version, :token, :account_id
4
+
5
+ def initialize(kazoo_config)
6
+ @api_key = kazoo_config['api_key']
7
+ @host = kazoo_config['host']
8
+ @port = kazoo_config['port']
9
+ @version = kazoo_config['version']
10
+ @account_id = kazoo_config['account_id']
11
+ get_token
12
+ end
13
+
14
+ def get_token
15
+ unless token
16
+ base_uri = 'http://' + host + ":" + port + '/' + version + '/'
17
+ auth_url = base_uri + 'api_auth'
18
+ payload = {'data' => {'api_key' => api_key}}
19
+ response = Nestful.json_put(auth_url, {:params => payload})
20
+ @token = response['auth_token']
21
+ end
22
+
23
+ @token
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Kazoo
2
+ class Conference
3
+ attr_reader :auth
4
+
5
+ def initialize(auth)
6
+ instance_variable_set :@auth, auth
7
+ @base_uri = 'http://' + @auth.host + ":" + @auth.port + '/' + @auth.version + '/' + 'accounts/' + @auth.account_id
8
+ end
9
+
10
+ def create_callflow(phone_numbers)
11
+ callflow_url = @base_uri + '/callflows?auth_token=' + @auth.token
12
+ payload = {'data' => {'numbers' => phone_numbers, 'flow' => {'module' => "conference", 'data' => {}, 'children' => {}}}}
13
+ Nestful.json_put(callflow_url, {:params => payload})
14
+ end
15
+
16
+ def create_room(name, conference_numbers)
17
+ room_url = @base_uri + '/conferences?auth_token=' + @auth.token
18
+ payload = {'data' => {'name' => name, 'conference_numbers' => conference_numbers}}
19
+ Nestful.json_put(room_url, {:params => payload})
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Nestful
2
+ class ConnectionError
3
+ attr_reader :response
4
+
5
+ def initialize(response, message = nil)
6
+ @body = response.body if response.respond_to?(:body)
7
+ @response = response
8
+ @message = message
9
+ end
10
+
11
+ def to_s
12
+ message = "Failed."
13
+ message << " Response code = #{response.code}." if response.respond_to?(:code)
14
+ message << " Response message = #{response.message}." if response.respond_to?(:message)
15
+ message << " Response data = #{JSON.parse(@body)['data']}"
16
+ message
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Kazoo
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kazoo::Auth do
4
+ before do
5
+ @auth_token = "eca9233822a03ef9da0adf207db64d48"
6
+ stub_request(:put, "http://api.2600hz.com:8000/v1/api_auth").
7
+ with(:headers => {'Accept' => '*/*', 'User-Agent' => 'Ruby', 'Content-Type' => 'application/json'},
8
+ :body => {:data => {:api_key => /.*/}}).
9
+ to_return(:body => {"auth_token" => @auth_token,
10
+ "status" => "success",
11
+ "data" => {"account_id" => "my_test_account_id"}}.to_json)
12
+ @auth = Kazoo::Auth.new(kazoo_config)
13
+ end
14
+
15
+ describe '#initialize' do
16
+ specify { @auth.api_key.length.should eq 64 }
17
+ specify { @auth.host.should eq 'api.2600hz.com' }
18
+ specify { @auth.port.should eq '8000' }
19
+ specify { @auth.version.should eq 'v1' }
20
+ specify { @auth.account_id.length.should eq 32 }
21
+ specify { @auth.token.length.should eq 32 }
22
+ end
23
+
24
+ describe '#get_token' do
25
+ context 'where there is not an existing auth token' do
26
+ specify { @auth.get_token.should eq @auth_token }
27
+ specify { @auth.get_token.length.should eq 32 }
28
+ end
29
+
30
+ context 'when there is an auth token' do
31
+ it 'should not make request if auth_token exists' do
32
+ auth = Kazoo::Auth.new(kazoo_config)
33
+ auth.should_receive(:token).and_return("a valid auth token")
34
+ Nestful.should_not_receive(:put)
35
+ auth.get_token
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kazoo::Conference do
4
+ before do
5
+ Kazoo::Auth.any_instance.should_receive(:token).any_number_of_times.and_return('valid-token')
6
+ @auth = Kazoo::Auth.new(kazoo_config)
7
+ @phone_numbers = ['+14151112222']
8
+ @name = 'my super duper conference'
9
+ @conference_numbers = ['1234']
10
+ end
11
+
12
+ subject { Kazoo::Conference.new(@auth) }
13
+ specify { subject.auth.should eq @auth }
14
+
15
+ describe '#create_callflow' do
16
+ it 'should return an error if phone numbers are not array' do
17
+ pending
18
+ end
19
+
20
+ it 'should create a new call flow' do
21
+ expected_response = {"auth_token" => @auth.token,
22
+ "status" => "success",
23
+ "data" => {"numbers" => @phone_numbers,
24
+ "flow" => {"module" => "conference",
25
+ "data" => {},
26
+ "children" => {}},
27
+ "id" => "ae16f443d8ce3a5b70716d0dbd4d0fc2"},
28
+ "revision" => "1-eda087bf61f19b37dab1cc14404c7034"}
29
+
30
+ stub_request(:put, "http://api.2600hz.com:8000/v1/accounts/#{@auth.account_id}/callflows").
31
+ with(:headers => {'Accept' => '*/*', 'User-Agent' => 'Ruby', 'Content-Type' => 'application/json'},
32
+ :body => {:data => {:numbers => @phone_numbers, :flow => {:module => "conference", :data => {}, :children => {}}}, :auth_token => @auth.token}).
33
+ to_return(:body => expected_response.to_json)
34
+
35
+ subject.create_callflow(@phone_numbers).should eq expected_response
36
+ end
37
+
38
+ context 'and fails' do
39
+ it 'should raise error' do
40
+ pending 'need to think about how to test error cases'
41
+ response = mock('response')
42
+ response.body = {:data => 'some error'}.to_json
43
+ stub_request(:put, "http://api.2600hz.com:8000/v1/accounts/#{@auth.account_id}/callflows").
44
+ with(:headers => {'Accept' => '*/*', 'User-Agent' => 'Ruby', 'Content-Type' => 'application/json'},
45
+ :body => {:data => {:numbers => @phone_numbers, :flow => {:module => "conference", :data => {}, :children => {}}}, :auth_token => @auth.token}).
46
+ to_raise(Nestful::ConnectionError.new(response))
47
+
48
+ lambda {
49
+ subject.create_callflow(@phone_numbers)
50
+ }.should raise_error
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#create_room' do
56
+ context 'and succeeds' do
57
+ it 'should create a new conference room' do
58
+ expected_response =
59
+ {"auth_token" => "555555c8d6f213098729999999999999",
60
+ "status" => "success",
61
+ "data" => {"name" => @name,
62
+ "conference_numbers" => @conference_numbers,
63
+ "member" => {"pins" => [], "numbers" => [], "play_name" => false, "join_muted" => true, "join_deaf" => false},
64
+ "moderator" => {"pins" => [], "numbers" => [], "play_name" => false, "join_muted" => true, "join_deaf" => false},
65
+ "require_moderator" => false,
66
+ "wait_for_moderator" => true,
67
+ "max_members" => 15,
68
+ "id" => "5eb2aac8d6f21309872920aedccbf885"},
69
+ "revision" => "1-d832f5497369796e1e0f0482584678ee"}
70
+
71
+ stub_request(:put, "http://api.2600hz.com:8000/v1/accounts/#{@auth.account_id}/conferences").
72
+ with(:headers => {'Accept' => '*/*', 'User-Agent' => 'Ruby', 'Content-Type' => 'application/json'},
73
+ :body => {:data => {:name => @name, :conference_numbers => @conference_numbers}, :auth_token => @auth.token}).
74
+ to_return(:body => expected_response.to_json)
75
+
76
+ subject.create_room(@name, @conference_numbers).should eq expected_response
77
+ end
78
+ end
79
+
80
+ context 'and fails' do
81
+ it 'should return with error for conference numbers not in array' do
82
+ pending
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kazoo do
4
+ end
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ require 'webmock/rspec'
3
+ require 'kazoo'
4
+
5
+ RSpec.configure do |config|
6
+ config.include RSpec::Matchers
7
+ end
8
+
9
+ def kazoo_config
10
+ { 'api_key' => 'your_kazoo_developer_api_key' + '*' * 36,
11
+ 'account_id' => 'your_account_id' + '*' * 17,
12
+ 'host' => 'api.2600hz.com',
13
+ 'port' => '8000',
14
+ 'version' => 'v1',
15
+ }
16
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kazoo-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zhao Lu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nestful
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Ruby wrapper for Kazoo, a powerful telephony platform
79
+ email: zlu@me.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - README.md
84
+ files:
85
+ - .gitignore
86
+ - .travis.yml
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - examples/conference.rb
93
+ - kazoo.gemspec
94
+ - lib/kazoo.rb
95
+ - lib/kazoo.yml.sample
96
+ - lib/kazoo/auth.rb
97
+ - lib/kazoo/conference.rb
98
+ - lib/kazoo/connection_error.rb
99
+ - lib/kazoo/version.rb
100
+ - spec/kazoo/auth_spec.rb
101
+ - spec/kazoo/conference_spec.rb
102
+ - spec/kazoo_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/zlu/kazoo-rb
105
+ licenses: []
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.24
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Ruby wrapper for Kazoo
129
+ test_files: []