moceansdk 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moceansdk.rb +11 -0
- data/lib/moceansdk/client.rb +4 -0
- data/lib/moceansdk/modules/abstact_client.rb +1 -1
- data/lib/moceansdk/modules/transmitter.rb +30 -10
- data/lib/moceansdk/modules/voice/mc.rb +63 -0
- data/lib/moceansdk/modules/voice/mc_builder.rb +30 -0
- data/lib/moceansdk/modules/voice/mc_object/abstract_mc.rb +38 -0
- data/lib/moceansdk/modules/voice/mc_object/collect.rb +39 -0
- data/lib/moceansdk/modules/voice/mc_object/dial.rb +31 -0
- data/lib/moceansdk/modules/voice/mc_object/play.rb +31 -0
- data/lib/moceansdk/modules/voice/mc_object/record.rb +19 -0
- data/lib/moceansdk/modules/voice/mc_object/say.rb +43 -0
- data/lib/moceansdk/modules/voice/mc_object/sleep.rb +23 -0
- data/lib/moceansdk/modules/voice/voice.rb +84 -0
- data/lib/moceansdk/utils.rb +6 -0
- data/lib/moceansdk/version.rb +1 -1
- data/moceansdk.gemspec +1 -1
- metadata +14 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6afe87fef5a9c54ffd8fa33c4762ea50515918ec4049276e2d2e41fd510153a
|
4
|
+
data.tar.gz: b5af61783dbe5ceaa491de065a52608a2bd9a7399088797ec5bbf31d105f1e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0093116366cf6d19fce9d0b39f7e194098899a4d7dd195cfef71875d709498fe03da51b0a3c2bf1f2d97e1d5e9ac75288b94ad83fa54e4c4a23342b7c930166
|
7
|
+
data.tar.gz: c9931cd1bf804cbccf4d0f0f3d25597efb403a114e42c5d8324f55b8aa103913386b7f51ac513d9a004a7da72f2df9f52b384f6210129b0652eaa6c9c7d7e3c0
|
data/lib/moceansdk.rb
CHANGED
@@ -23,6 +23,17 @@ require 'moceansdk/modules/message/verify_validate'
|
|
23
23
|
|
24
24
|
require 'moceansdk/modules/number_lookup/number_lookup'
|
25
25
|
|
26
|
+
require 'moceansdk/modules/voice/mc_object/abstract_mc'
|
27
|
+
require 'moceansdk/modules/voice/mc_object/dial'
|
28
|
+
require 'moceansdk/modules/voice/mc_object/collect'
|
29
|
+
require 'moceansdk/modules/voice/mc_object/play'
|
30
|
+
require 'moceansdk/modules/voice/mc_object/record'
|
31
|
+
require 'moceansdk/modules/voice/mc_object/say'
|
32
|
+
require 'moceansdk/modules/voice/mc_object/sleep'
|
33
|
+
require 'moceansdk/modules/voice/mc'
|
34
|
+
require 'moceansdk/modules/voice/mc_builder'
|
35
|
+
require 'moceansdk/modules/voice/voice'
|
36
|
+
|
26
37
|
require 'moceansdk/utils'
|
27
38
|
require 'moceansdk/version'
|
28
39
|
require 'moceansdk/client'
|
data/lib/moceansdk/client.rb
CHANGED
@@ -13,16 +13,23 @@ module Moceansdk
|
|
13
13
|
def default_options
|
14
14
|
{
|
15
15
|
base_url: 'https://rest.moceanapi.com',
|
16
|
-
version: '2'
|
16
|
+
version: '2',
|
17
|
+
verify_ssl: true
|
17
18
|
}
|
18
19
|
end
|
19
20
|
|
20
21
|
def get(uri, params)
|
21
|
-
|
22
|
+
request_and_parse_body('get', uri, params)
|
22
23
|
end
|
23
24
|
|
24
25
|
def post(uri, params)
|
25
|
-
|
26
|
+
request_and_parse_body('post', uri, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_and_parse_body(method, uri, params)
|
30
|
+
res = request(method, uri, params)
|
31
|
+
|
32
|
+
format_response(res.to_s, params[:'mocean-resp-format'] == 'xml', uri)
|
26
33
|
end
|
27
34
|
|
28
35
|
def request(method, uri, params)
|
@@ -33,13 +40,11 @@ module Moceansdk
|
|
33
40
|
|
34
41
|
url = @options[:base_url] + '/rest/' + @options[:version] + uri
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
format_response(res.to_s, params[:'mocean-resp-format'] == 'xml', uri)
|
43
|
+
if method.casecmp('get').zero?
|
44
|
+
HTTP.follow.get(url, params: params, ssl_context: make_ssl_context)
|
45
|
+
else
|
46
|
+
HTTP.post(url, form: params, ssl_context: make_ssl_context)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def format_response(response_text, is_xml = false, uri = nil)
|
@@ -80,12 +85,27 @@ module Moceansdk
|
|
80
85
|
processed_response.messages.message = [processed_response.messages.message]
|
81
86
|
end
|
82
87
|
processed_response.messages = processed_response.messages.message
|
88
|
+
elsif uri == '/voice/dial'
|
89
|
+
unless processed_response.calls.call.is_a? Array
|
90
|
+
processed_response.calls.call = [processed_response.calls.call]
|
91
|
+
end
|
92
|
+
processed_response.calls = processed_response.calls.call
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
86
96
|
processed_response.raw_response = raw_response
|
87
97
|
processed_response
|
88
98
|
end
|
99
|
+
|
100
|
+
def make_ssl_context
|
101
|
+
if @options[:verify_ssl]
|
102
|
+
return nil
|
103
|
+
end
|
104
|
+
|
105
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
106
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
107
|
+
ctx
|
108
|
+
end
|
89
109
|
end
|
90
110
|
|
91
111
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
|
5
|
+
class Mc
|
6
|
+
def self.say(text = nil)
|
7
|
+
ins = McObject::Say.new
|
8
|
+
|
9
|
+
unless text.nil?
|
10
|
+
ins.text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
ins
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.play(file = nil)
|
17
|
+
ins = McObject::Play.new
|
18
|
+
|
19
|
+
unless file.nil?
|
20
|
+
ins.files = file
|
21
|
+
end
|
22
|
+
|
23
|
+
ins
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.dial(to = nil)
|
27
|
+
ins = McObject::Dial.new
|
28
|
+
|
29
|
+
unless to.nil?
|
30
|
+
ins.to = to
|
31
|
+
end
|
32
|
+
|
33
|
+
ins
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.collect(event_url = nil)
|
37
|
+
ins = McObject::Collect.new
|
38
|
+
|
39
|
+
unless event_url.nil?
|
40
|
+
ins.event_url = event_url
|
41
|
+
end
|
42
|
+
|
43
|
+
ins
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.sleep(duration = nil)
|
47
|
+
ins = McObject::Sleep.new
|
48
|
+
|
49
|
+
unless duration.nil?
|
50
|
+
ins.duration = duration
|
51
|
+
end
|
52
|
+
|
53
|
+
ins
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.record
|
57
|
+
McObject::Record.new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
|
5
|
+
class McBuilder
|
6
|
+
def initialize
|
7
|
+
@mc = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(mc)
|
11
|
+
unless mc.is_a? McObject::AbstractMc
|
12
|
+
raise Moceansdk::Exceptions::MoceanError, 'mc_object must extend AbstractMc'
|
13
|
+
end
|
14
|
+
|
15
|
+
@mc.push(mc)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def build
|
20
|
+
converted = []
|
21
|
+
@mc.each do |mc|
|
22
|
+
converted.push(mc.get_request_data)
|
23
|
+
end
|
24
|
+
converted
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class AbstractMc
|
7
|
+
def initialize(params = nil)
|
8
|
+
@params = {}
|
9
|
+
|
10
|
+
@params = Moceansdk::Utils.convert_to_symbol_hash(params) unless params.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_request_data
|
14
|
+
@params = Moceansdk::Utils.convert_to_symbol_hash(@params)
|
15
|
+
|
16
|
+
required_key.each do |key|
|
17
|
+
if @params[:"#{key}"].nil?
|
18
|
+
raise Moceansdk::Exceptions::RequiredFieldException, "#{key} is mandatory field, can't leave empty (#{self})"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@params[:action] = action
|
23
|
+
@params
|
24
|
+
end
|
25
|
+
|
26
|
+
def required_key
|
27
|
+
raise NotImplementedError, 'AbstractMc is a abstract class'
|
28
|
+
end
|
29
|
+
|
30
|
+
def action
|
31
|
+
raise NotImplementedError, 'AbstractMc is a abstract class'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class Collect < AbstractMc
|
7
|
+
def event_url=(param)
|
8
|
+
@params[:'event-url'] = param
|
9
|
+
end
|
10
|
+
|
11
|
+
def minimum=(param)
|
12
|
+
@params[:min] = param
|
13
|
+
end
|
14
|
+
|
15
|
+
def maximum=(param)
|
16
|
+
@params[:max] = param
|
17
|
+
end
|
18
|
+
|
19
|
+
def terminators=(param)
|
20
|
+
@params[:terminators] = param
|
21
|
+
end
|
22
|
+
|
23
|
+
def timeout=(param)
|
24
|
+
@params[:timeout] = param
|
25
|
+
end
|
26
|
+
|
27
|
+
def required_key
|
28
|
+
['event-url', 'min', 'max', 'timeout']
|
29
|
+
end
|
30
|
+
|
31
|
+
def action
|
32
|
+
'collect'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class Dial < AbstractMc
|
7
|
+
def to=(param)
|
8
|
+
@params[:to] = param
|
9
|
+
end
|
10
|
+
|
11
|
+
def from=(param)
|
12
|
+
@params[:from] = param
|
13
|
+
end
|
14
|
+
|
15
|
+
def dial_sequentially=(param)
|
16
|
+
@params[:'dial-sequentially'] = param
|
17
|
+
end
|
18
|
+
|
19
|
+
def required_key
|
20
|
+
['to']
|
21
|
+
end
|
22
|
+
|
23
|
+
def action
|
24
|
+
'dial'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class Play < AbstractMc
|
7
|
+
def files=(param)
|
8
|
+
@params[:file] = param
|
9
|
+
end
|
10
|
+
|
11
|
+
def barge_in=(param)
|
12
|
+
@params[:'barge-in'] = param
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear_digit_cache=(param)
|
16
|
+
@params[:'clear-digit-cache'] = param
|
17
|
+
end
|
18
|
+
|
19
|
+
def required_key
|
20
|
+
['file']
|
21
|
+
end
|
22
|
+
|
23
|
+
def action
|
24
|
+
'play'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class Say < AbstractMc
|
7
|
+
def initialize(params = nil)
|
8
|
+
super(params)
|
9
|
+
|
10
|
+
if @params[:language].nil?
|
11
|
+
@params[:language] = 'en-US'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def language=(param)
|
16
|
+
@params[:language] = param
|
17
|
+
end
|
18
|
+
|
19
|
+
def text=(param)
|
20
|
+
@params[:text] = param
|
21
|
+
end
|
22
|
+
|
23
|
+
def barge_in=(param)
|
24
|
+
@params[:'barge-in'] = param
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear_digit_cache=(param)
|
28
|
+
@params[:'clear-digit-cache'] = param
|
29
|
+
end
|
30
|
+
|
31
|
+
def required_key
|
32
|
+
['text', 'language']
|
33
|
+
end
|
34
|
+
|
35
|
+
def action
|
36
|
+
'say'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
module McObject
|
5
|
+
|
6
|
+
class Sleep < AbstractMc
|
7
|
+
def duration=(param)
|
8
|
+
@params[:duration] = param
|
9
|
+
end
|
10
|
+
|
11
|
+
def required_key
|
12
|
+
['duration']
|
13
|
+
end
|
14
|
+
|
15
|
+
def action
|
16
|
+
'sleep'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Moceansdk
|
2
|
+
module Modules
|
3
|
+
module Voice
|
4
|
+
|
5
|
+
class Voice < Moceansdk::Modules::AbstractClient
|
6
|
+
def initialize(obj_auth, transmitter)
|
7
|
+
super(obj_auth, transmitter)
|
8
|
+
@required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-to']
|
9
|
+
end
|
10
|
+
|
11
|
+
def to=(param)
|
12
|
+
@params['mocean-to'] = param
|
13
|
+
end
|
14
|
+
|
15
|
+
def event_url=(param)
|
16
|
+
@params['mocean-event-url'] = param
|
17
|
+
end
|
18
|
+
|
19
|
+
def mocean_command=(param)
|
20
|
+
if param.is_a? McBuilder
|
21
|
+
@params['mocean-command'] = JSON.generate(param.build)
|
22
|
+
elsif param.is_a? McObject::AbstractMc
|
23
|
+
@params['mocean-command'] = JSON.generate([param.get_request_data])
|
24
|
+
elsif param.is_a? Array
|
25
|
+
@params['mocean-command'] = JSON.generate(param)
|
26
|
+
else
|
27
|
+
@params['mocean-command'] = param
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def resp_format=(param)
|
32
|
+
@params['mocean-resp-format'] = param
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(params = {})
|
36
|
+
sym_params = Moceansdk::Utils.convert_to_symbol_hash(params)
|
37
|
+
|
38
|
+
unless sym_params[:'mocean-command'].nil?
|
39
|
+
mc = sym_params[:'mocean-command']
|
40
|
+
sym_params.delete(:'mocean-command')
|
41
|
+
self.mocean_command = mc
|
42
|
+
end
|
43
|
+
|
44
|
+
create(sym_params)
|
45
|
+
create_final_params
|
46
|
+
required_field_set?
|
47
|
+
|
48
|
+
@transmitter.post('/voice/dial', @params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def hangup(call_uuid)
|
52
|
+
@required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-call-uuid']
|
53
|
+
|
54
|
+
create({:'mocean-call-uuid' => call_uuid})
|
55
|
+
create_final_params
|
56
|
+
required_field_set?
|
57
|
+
|
58
|
+
@transmitter.post("/voice/hangup", @params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def recording(call_uuid)
|
62
|
+
@required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-call-uuid']
|
63
|
+
|
64
|
+
create({:'mocean-call-uuid' => call_uuid})
|
65
|
+
create_final_params
|
66
|
+
required_field_set?
|
67
|
+
|
68
|
+
response = @transmitter.request('get', '/voice/rec', @params)
|
69
|
+
|
70
|
+
if response['Content-Type'] === 'audio/mpeg'
|
71
|
+
hashed_res = HashExtended.new.merge({'recording_buffer': response.to_s, 'filename': "#{call_uuid}.mp3"})
|
72
|
+
return hashed_res.to_dot
|
73
|
+
end
|
74
|
+
|
75
|
+
# this method will raise exception if there's error
|
76
|
+
processed_response = Moceansdk::Modules::ResponseFactory.create_object(response.to_s)
|
77
|
+
processed_response.raw_response = response.to_s
|
78
|
+
raise Moceansdk::Exceptions::MoceanError.new(processed_response['err_msg'], processed_response)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/moceansdk/utils.rb
CHANGED
data/lib/moceansdk/version.rb
CHANGED
data/moceansdk.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency('xml-simple', '~> 1.1')
|
18
18
|
s.add_development_dependency('codecov', '>= 0.1.10')
|
19
19
|
s.add_development_dependency('minitest', '~> 5.0')
|
20
|
-
s.add_development_dependency('rake', '~>
|
20
|
+
s.add_development_dependency('rake', '~> 13.0')
|
21
21
|
s.add_development_dependency('webmock', '~> 3.6')
|
22
22
|
s.require_path = 'lib'
|
23
23
|
s.metadata = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moceansdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micro Ocean Technologies Sdn Bhd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hash_dot
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '13.0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '13.0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: webmock
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +140,16 @@ files:
|
|
140
140
|
- lib/moceansdk/modules/number_lookup/number_lookup.rb
|
141
141
|
- lib/moceansdk/modules/response_factory.rb
|
142
142
|
- lib/moceansdk/modules/transmitter.rb
|
143
|
+
- lib/moceansdk/modules/voice/mc.rb
|
144
|
+
- lib/moceansdk/modules/voice/mc_builder.rb
|
145
|
+
- lib/moceansdk/modules/voice/mc_object/abstract_mc.rb
|
146
|
+
- lib/moceansdk/modules/voice/mc_object/collect.rb
|
147
|
+
- lib/moceansdk/modules/voice/mc_object/dial.rb
|
148
|
+
- lib/moceansdk/modules/voice/mc_object/play.rb
|
149
|
+
- lib/moceansdk/modules/voice/mc_object/record.rb
|
150
|
+
- lib/moceansdk/modules/voice/mc_object/say.rb
|
151
|
+
- lib/moceansdk/modules/voice/mc_object/sleep.rb
|
152
|
+
- lib/moceansdk/modules/voice/voice.rb
|
143
153
|
- lib/moceansdk/utils.rb
|
144
154
|
- lib/moceansdk/version.rb
|
145
155
|
- moceansdk.gemspec
|