boundioV2 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/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boundioV2.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 joohoun
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # BoundioV2
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'boundioV2'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install boundioV2
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ end
data/bin/boundioV2 ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'boundioV2'
7
+
8
+ BoundioV2::Application.start
data/boundioV2.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "boundioV2/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "boundioV2"
7
+ s.version = BoundioV2::VERSION
8
+ s.authors = ["joohoun"]
9
+ s.email = ["joohoun@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Wrapper for BoundioV2 API}
12
+ s.description = %q{Boundio is KDDI's telephony API. This is a simple wrapper for it.}
13
+
14
+ s.rubyforge_project = "boundioV2"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "minitest"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "webmock"
24
+ s.add_runtime_dependency "activesupport"
25
+ s.add_runtime_dependency "json"
26
+ s.add_runtime_dependency "rest-client"
27
+ s.add_runtime_dependency "thor"
28
+ end
data/lib/boundioV2.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "json"
3
+ require "rest-client"
4
+ require "thor"
5
+ require "active_support/core_ext/string/inflections"
6
+
7
+ module BoundioV2
8
+ %w[audio_file application call cast exception resource tel_status version].each do |s|
9
+ autoload s.camelize.to_sym, "boundioV2/#{s}"
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ module BoundioV2
2
+ class Application < Thor
3
+ desc "call", "Call the specified number with the specified cast"
4
+ method_options :tel_to => :string, :cast => :string
5
+ def call
6
+ call = Call.create(options)
7
+ puts call.id
8
+ end
9
+
10
+ desc "status", "Look up the status of the specified call"
11
+ method_options :tel_id => :string, :start => :string, :end => :string
12
+ def status
13
+ if options[:tel_id]
14
+ puts TelStatus.find(options[:tel_id])
15
+ else
16
+ puts TelStatus.find_all(options)
17
+ end
18
+ end
19
+
20
+ desc "file", "Create a file for use with boundioV2"
21
+ method_options :convtext => :string, :file => :string
22
+ def file
23
+ file = AudioFile.create(options[:file] ? {:file => File.new(options[:file], "rb")} : options)
24
+ puts file.id
25
+ end
26
+
27
+ private
28
+
29
+ def client
30
+ @client ||= BoundioV2::Client.new(ENV["BOUNDIO_USER_SERIAL_ID"], ENV["BOUNDIO_API_KEY"])
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module BoundioV2
2
+ class AudioFile < Resource
3
+ attr_accessor :convtext, :id, :file
4
+
5
+ def self.api_version
6
+ "vd2"
7
+ end
8
+
9
+ def self.exceptions
10
+ super.merge(2 => InsufficientParametersOrTooBigFile, 6 => VoiceConversionError)
11
+ end
12
+
13
+ def save
14
+ args = if file
15
+ { :file => file, :filename => File.basename(file.path) }
16
+ else
17
+ { :convtext => convtext, :filename => convtext }
18
+ end
19
+ res = self.class.request :post, "/file/post", args
20
+ self.id = res["fileid"]
21
+ true
22
+ end
23
+
24
+ def +(file)
25
+ BoundioV2::Cast.new(self, file)
26
+ end
27
+
28
+ class InsufficientParametersOrTooBigFile < BoundioV2::Exception; end
29
+ class VoiceConversionError < BoundioV2::Exception; end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module BoundioV2
2
+ class Call < Resource
3
+ attr_accessor :tel_to, :cast, :id
4
+ def self.exceptions
5
+ super.merge(3 => NoVoiceFile, 4 => NotEnoughPoints)
6
+ end
7
+
8
+ def save
9
+ res = self.class.request :post, "/call", :tel_to => tel_to, :cast => cast
10
+ self.id = res["_id"]
11
+ true
12
+ end
13
+
14
+ def status
15
+ TelStatus.find(id)
16
+ end
17
+
18
+ class NotEnoughPoints < BoundioV2::Exception; end
19
+ class NoVoiceFile < BoundioV2::Exception; end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module BoundioV2
2
+ class Cast
3
+ attr_reader :files
4
+
5
+ def initialize(*files)
6
+ @files = files
7
+ end
8
+
9
+ def +(file)
10
+ self.class.new(*(files + [file]))
11
+ end
12
+
13
+ def to_s
14
+ files.map {|f| "file(#{f.id})" }
15
+ end
16
+
17
+ def ==(other)
18
+ other.is_a?(self.class) ? files == other.files : super
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module BoundioV2
2
+ class Exception < StandardError
3
+ end
4
+ end
@@ -0,0 +1,46 @@
1
+ module BoundioV2
2
+ class Resource
3
+ class << self
4
+ def create(args)
5
+ o = new(args)
6
+ o.save
7
+ o
8
+ end
9
+
10
+ def api_version
11
+ "vd2"
12
+ end
13
+
14
+ %w[user_serial_id api_key user_key].each do |s|
15
+ var = "BOUNDIOV2_#{s.upcase}"
16
+ define_method(s) do
17
+ ENV[var] || raise("Please export #{var}")
18
+ end
19
+ end
20
+
21
+ def request(method, path, params)
22
+ params = params.merge(:key => api_key, :auth => user_key)
23
+ res = RestClient.send method,
24
+ File.join("https://boundio.jp/api/", api_version, user_serial_id, path),
25
+ method == :get ? { :params => params } : params
26
+ res = JSON.parse(res)
27
+ res = res.first if res.is_a?(Array)
28
+ unless res["success"] == "true"
29
+ raise exceptions[res["error"].to_i] || BoundioV2::Exception.new("Error Code #{res["error"]}")
30
+ end
31
+ res
32
+ end
33
+
34
+ def exceptions
35
+ { 1 => Unauthorized }
36
+ end
37
+ end
38
+
39
+ def initialize(args = {})
40
+ args.each {|k,v| send("#{k}=", v) }
41
+ end
42
+
43
+ class Unauthorized < BoundioV2::Exception
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ module BoundioV2
3
+ class TelStatus < Resource
4
+ attr_accessor :id, :from, :to, :start, :end, :duration, :status
5
+ class << self
6
+ def find(id)
7
+ res = request :get, "/tel_status", :tel_id => id
8
+ parse(res["result"].first)
9
+ end
10
+
11
+ def find_all(options)
12
+ res = request :get, "/tel_status", options
13
+ res["result"].map {|h| parse(h)}
14
+ end
15
+
16
+ private
17
+
18
+ def parse(res)
19
+ new(res.map {|k,v| [k.sub(/^_/, ""), v] })
20
+ end
21
+ end
22
+
23
+ def processing?
24
+ status == "架電待機"
25
+ end
26
+
27
+ def to_s
28
+ "TelStatus (#{id}): #{from} -> #{to}, #{start} - #{self.end}, #{status}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module BoundioV2
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boundioV2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - joohoun
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
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: webmock
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: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rest-client
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: thor
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Boundio is KDDI's telephony API. This is a simple wrapper for it.
127
+ email:
128
+ - joohoun@gmail.com
129
+ executables:
130
+ - boundioV2
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .DS_Store
135
+ - .gitignore
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - bin/boundioV2
141
+ - boundioV2.gemspec
142
+ - lib/boundioV2.rb
143
+ - lib/boundioV2/application.rb
144
+ - lib/boundioV2/audio_file.rb
145
+ - lib/boundioV2/call.rb
146
+ - lib/boundioV2/cast.rb
147
+ - lib/boundioV2/exception.rb
148
+ - lib/boundioV2/resource.rb
149
+ - lib/boundioV2/tel_status.rb
150
+ - lib/boundioV2/version.rb
151
+ homepage: ''
152
+ licenses: []
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project: boundioV2
171
+ rubygems_version: 1.8.24
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: Wrapper for BoundioV2 API
175
+ test_files: []