boundio 0.0.1 → 0.0.2

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 CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .rvmrc
data/bin/boundio CHANGED
@@ -5,5 +5,4 @@ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
5
 
6
6
  require 'boundio'
7
7
 
8
- client = Boundio::Client.new(ENV["BOUNDIO_USER_SERIAL_ID"], ENV["BOUNDIO_API_KEY"])
9
- puts client.call(ARGV[0], ARGV[1]).inspect
8
+ Boundio::Application.start
data/boundio.gemspec CHANGED
@@ -20,5 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "activesupport"
23
24
  s.add_runtime_dependency "rest-client"
25
+ s.add_runtime_dependency "thor"
24
26
  end
@@ -0,0 +1,35 @@
1
+ module Boundio
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.new(options)
7
+ call.save
8
+ puts call.id
9
+ end
10
+
11
+ desc "status", "Look up the status of the specified call"
12
+ method_options :tel_id => :string, :start => :string, :end => :string
13
+ def status
14
+ if options[:tel_id]
15
+ puts TelStatus.find(options[:tel_id])
16
+ else
17
+ puts TelStatus.find_all(options)
18
+ end
19
+ end
20
+
21
+ desc "file", "Create a file for use with boundio"
22
+ method_options :convtext => :string, :file => :string
23
+ def file
24
+ file = AudioFile.new(options[:file] ? {file: File.new(options[:file], "rb")} : options)
25
+ file.save
26
+ puts file.id
27
+ end
28
+
29
+ private
30
+
31
+ def client
32
+ @client ||= Boundio::Client.new(ENV["BOUNDIO_USER_SERIAL_ID"], ENV["BOUNDIO_API_KEY"])
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ module Boundio
2
+ class AudioFile < Resource
3
+ attr_accessor :convtext, :id, :file
4
+
5
+ def self.exceptions
6
+ super.merge(2 => ArgumentError.new("insufficient parameters or file to big"))
7
+ end
8
+
9
+ def save
10
+ args = if file
11
+ { :file => file, :filename => File.basename(file.path) }
12
+ else
13
+ { :convtext => convtext, :filename => convtext }
14
+ end
15
+ res = self.class.request :post, "/file/post", args
16
+ self.id = res["fileid"]
17
+ true
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Boundio
2
+ class Call < Resource
3
+ attr_accessor :tel_to, :cast, :id
4
+ def self.exceptions
5
+ super.merge(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
+ class NotEnoughPoints < Boundio::Exception
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Boundio
2
+ class Exception < StandardError
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ module Boundio
2
+ class Resource
3
+ class << self
4
+ def user_serial_id
5
+ ENV["BOUNDIO_USER_SERIAL_ID"]
6
+ end
7
+
8
+ def api_key
9
+ ENV["BOUNDIO_API_KEY"]
10
+ end
11
+
12
+ def user_authentication_key
13
+ ENV["BOUNDIO_USER_AUTHENTICATION_KEY"]
14
+ end
15
+
16
+ def request(method, path, params)
17
+ params = params.merge(key: api_key, auth: user_authentication_key)
18
+ res = RestClient.send method,
19
+ File.join("https://boundio.jp/api/vd1/#{user_serial_id}", path),
20
+ method == :get ? { :params => params } : params
21
+ res = JSON.parse(res)
22
+ res = res.first if res.is_a?(Array)
23
+ unless res["success"] == "true"
24
+ raise exceptions[res["error"].to_i] || Boundio::Exception.new("Error Code #{res["error"]}")
25
+ end
26
+ res
27
+ end
28
+
29
+ def exceptions
30
+ { 1 => Unauthorized }
31
+ end
32
+ end
33
+
34
+ def initialize(args)
35
+ args.each {|k,v| send("#{k}=", v) }
36
+ end
37
+
38
+ class Unauthorized < Boundio::Exception
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module Boundio
2
+ class TelStatus < Resource
3
+ attr_accessor :id, :from, :to, :start, :end, :duration, :status
4
+ class << self
5
+ def find(id)
6
+ res = request :get, "/tel_status", :tel_id => id
7
+ parse(res["result"].first)
8
+ end
9
+
10
+ def find_all(options)
11
+ res = request :get, "/tel_status", options
12
+ res["result"].map {|h| parse(h)}
13
+ end
14
+
15
+ private
16
+
17
+ def parse(res)
18
+ new(res.map {|k,v| [k.sub(/^_/, ""), v] })
19
+ end
20
+ end
21
+
22
+ def to_s
23
+ "TelStatus (#{id}): #{from} -> #{to}, #{start} - #{self.end}, #{status}"
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Boundio
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/boundio.rb CHANGED
@@ -1,7 +1,10 @@
1
- require "boundio/version"
2
- require "boundio/client"
1
+ require "json"
3
2
  require "rest-client"
3
+ require "thor"
4
+ require "active_support/core_ext/string/inflections"
4
5
 
5
6
  module Boundio
6
- # Your code goes here...
7
+ %w[audio_file application call exception resource tel_status version].each do |s|
8
+ autoload s.camelize.to_sym, "boundio/#{s}"
9
+ end
7
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boundio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-25 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &80009850 !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: *80009850
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rest-client
16
- requirement: &75284790 !ruby/object:Gem::Requirement
27
+ requirement: &80009620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *80009620
36
+ - !ruby/object:Gem::Dependency
37
+ name: thor
38
+ requirement: &80009390 !ruby/object:Gem::Requirement
17
39
  none: false
18
40
  requirements:
19
41
  - - ! '>='
@@ -21,7 +43,7 @@ dependencies:
21
43
  version: '0'
22
44
  type: :runtime
23
45
  prerelease: false
24
- version_requirements: *75284790
46
+ version_requirements: *80009390
25
47
  description: Boundio is KDDI's telephony API. This is a simple wrapper for it.
26
48
  email:
27
49
  - paul@mobalean.com
@@ -36,7 +58,12 @@ files:
36
58
  - bin/boundio
37
59
  - boundio.gemspec
38
60
  - lib/boundio.rb
39
- - lib/boundio/client.rb
61
+ - lib/boundio/application.rb
62
+ - lib/boundio/audio_file.rb
63
+ - lib/boundio/call.rb
64
+ - lib/boundio/exception.rb
65
+ - lib/boundio/resource.rb
66
+ - lib/boundio/tel_status.rb
40
67
  - lib/boundio/version.rb
41
68
  homepage: http://boundio.jp
42
69
  licenses: []
@@ -58,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
85
  version: '0'
59
86
  requirements: []
60
87
  rubyforge_project: boundio
61
- rubygems_version: 1.8.10
88
+ rubygems_version: 1.8.17
62
89
  signing_key:
63
90
  specification_version: 3
64
91
  summary: Wrapper for Boundio API
@@ -1,12 +0,0 @@
1
- module Boundio
2
- class Client
3
- def initialize(user_serial_id, api_key)
4
- @user_serial_id, @api_key = user_serial_id, api_key
5
- end
6
-
7
- def call(tel_to, cast)
8
- RestClient.post "https://boundio.jp/api/vd1/#{@user_serial_id}/call",
9
- :key => @api_key, :tel_to => tel_to, :cast => cast
10
- end
11
- end
12
- end