voximplant_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6690d5560e90499ba2be773ffc4da8ec6f7ebba7
4
+ data.tar.gz: 2630a669cf5678790777402614241404aff6cd60
5
+ SHA512:
6
+ metadata.gz: 0e854c45065a6d95d335b4030588a400dccd98bfe1641fe06ec766fe29a8437b38dc3c63d8f3f0701009922e5e01c7792eb5359670c20711c07aea0b67804b5f
7
+ data.tar.gz: 45ffa13e8073eeffa8b30ec5720745f2f62a8286826ff776729c9e0db1805c01a2756979bdf1782c270eb6dc4ab797a4c670a7dec437bcd4e660d336db5bfc6e
@@ -0,0 +1,77 @@
1
+ require 'rest_client'
2
+
3
+ module VoximplantApi
4
+ NO_METHOD_ERROR_CODE = 103
5
+
6
+ class Error < StandardError
7
+ attr_reader :code
8
+
9
+ def initialize(error)
10
+ super error["msg"]
11
+ @code = error["code"]
12
+ end
13
+ end
14
+
15
+ class Client
16
+
17
+ def initialize(options)
18
+ @account_id = options[:account_id]
19
+ @api_key = options[:api_key]
20
+ end
21
+
22
+ def create_child_account(options)
23
+ perform_request_as_parent("AddAccount", options)
24
+ end
25
+
26
+ def method_missing(name, *args)
27
+ method_name = name.to_s.split('_').collect(&:capitalize).join
28
+ options = args.first || {}
29
+ perform_request method_name, options
30
+
31
+ rescue VoximplantApi::Error => e
32
+ if e.code == NO_METHOD_ERROR_CODE
33
+ raise NoMethodError.new("unknown command '#{method_name}'.")
34
+ else
35
+ raise
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ def auth_params
42
+ {account_id: @account_id,
43
+ api_key: @api_key}
44
+ end
45
+
46
+ def parent_auth_params
47
+ {parent_account_id: @account_id,
48
+ parent_account_api_key: @api_key}
49
+ end
50
+
51
+ def perform_request(name, params = {})
52
+ params = auth_params.merge params
53
+ self.class.perform_request(name, params)
54
+ end
55
+
56
+ def perform_request_as_parent(name, params = {})
57
+ params = parent_auth_params.merge params
58
+ self.class.perform_request(name, params)
59
+ end
60
+
61
+ class << self
62
+ def api_basic_url
63
+ "https://api.voximplant.com/platform_api"
64
+ end
65
+
66
+ def perform_request(name, params)
67
+ result = JSON.parse (RestClient.post "#{self.api_basic_url}/#{name}", params)
68
+ if result["error"]
69
+ raise Error.new(result["error"])
70
+ end
71
+ result
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1 @@
1
+ require_relative 'voximplant_api/client'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voximplant_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Shushlin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: VoxImplant.com HTTP API client
28
+ email: v.shushlin@insales.ru
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/voximplant_api.rb
34
+ - lib/voximplant_api/client.rb
35
+ homepage: https://github.com/insales/voximplant_api
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.4.5
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: VoxImplant.com HTTP API client
58
+ test_files: []