moceansdk 0.1.6 → 1.1.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.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +75 -57
  4. data/lib/moceansdk.rb +51 -5
  5. data/lib/moceansdk/auth/abstract_auth.rb +15 -0
  6. data/lib/moceansdk/auth/basic.rb +29 -0
  7. data/lib/moceansdk/client.rb +70 -14
  8. data/lib/moceansdk/exceptions/mocean_error.rb +18 -0
  9. data/lib/moceansdk/exceptions/required_field_exception.rb +8 -0
  10. data/lib/moceansdk/modules/abstact_client.rb +54 -0
  11. data/lib/moceansdk/modules/account/balance.rb +26 -22
  12. data/lib/moceansdk/modules/account/pricing.rb +37 -37
  13. data/lib/moceansdk/modules/command/command.rb +47 -0
  14. data/lib/moceansdk/modules/command/mc.rb +40 -0
  15. data/lib/moceansdk/modules/command/mc_builder.rb +30 -0
  16. data/lib/moceansdk/modules/command/mc_object/abstract_mc.rb +36 -0
  17. data/lib/moceansdk/modules/command/mc_object/send_sms.rb +41 -0
  18. data/lib/moceansdk/modules/command/mc_object/tg_request_contact.rb +49 -0
  19. data/lib/moceansdk/modules/command/mc_object/tg_send_animation.rb +41 -0
  20. data/lib/moceansdk/modules/command/mc_object/tg_send_audio.rb +41 -0
  21. data/lib/moceansdk/modules/command/mc_object/tg_send_document.rb +41 -0
  22. data/lib/moceansdk/modules/command/mc_object/tg_send_photo.rb +41 -0
  23. data/lib/moceansdk/modules/command/mc_object/tg_send_text.rb +41 -0
  24. data/lib/moceansdk/modules/command/mc_object/tg_send_video.rb +41 -0
  25. data/lib/moceansdk/modules/message/channel.rb +13 -0
  26. data/lib/moceansdk/modules/message/message_status.rb +29 -24
  27. data/lib/moceansdk/modules/message/sms.rb +74 -96
  28. data/lib/moceansdk/modules/message/verify_request.rb +83 -58
  29. data/lib/moceansdk/modules/message/verify_validate.rb +33 -37
  30. data/lib/moceansdk/modules/number_lookup/number_lookup.rb +34 -0
  31. data/lib/moceansdk/modules/response_factory.rb +50 -0
  32. data/lib/moceansdk/modules/transmitter.rb +112 -0
  33. data/lib/moceansdk/modules/voice/mc.rb +63 -0
  34. data/lib/moceansdk/modules/voice/mc_builder.rb +30 -0
  35. data/lib/moceansdk/modules/voice/mc_object/abstract_mc.rb +38 -0
  36. data/lib/moceansdk/modules/voice/mc_object/collect.rb +39 -0
  37. data/lib/moceansdk/modules/voice/mc_object/dial.rb +31 -0
  38. data/lib/moceansdk/modules/voice/mc_object/play.rb +31 -0
  39. data/lib/moceansdk/modules/voice/mc_object/record.rb +19 -0
  40. data/lib/moceansdk/modules/voice/mc_object/say.rb +43 -0
  41. data/lib/moceansdk/modules/voice/mc_object/sleep.rb +23 -0
  42. data/lib/moceansdk/modules/voice/voice.rb +84 -0
  43. data/lib/moceansdk/utils.rb +15 -0
  44. data/lib/moceansdk/version.rb +1 -1
  45. data/moceansdk.gemspec +13 -6
  46. metadata +97 -19
  47. data/lib/moceansdk/init.rb +0 -4
  48. data/lib/moceansdk/mocean.rb +0 -52
  49. data/lib/moceansdk/modules/abstract.rb +0 -142
@@ -1,38 +1,38 @@
1
- require_relative "../abstract"
2
-
3
- class Pricing < MoceanFactory
4
-
5
- def initialize client
6
- super(client)
7
- required_fields = ['mocean-api-key','mocean-api-secret']
8
- end
9
-
10
- def setMcc param
11
- @params['mocean-mcc'] = param
12
- return self
13
- end
14
-
15
- def setMnc param
16
- @params['mocean-mnc'] = param
17
- return self
18
- end
19
-
20
- def setDelimiter param
21
- @params['mocean-delimiter'] = param
22
- return self
23
- end
24
-
25
- def setRespFormat param
26
- @params['mocean-resp-format'] = param
27
- return self
28
- end
29
-
30
- def inquiry params = {}
31
- create(params)
32
- createFinalParams
33
- isRequiredFieldsSet
34
- response = Transmitter.new('/rest/1/account/pricing','get',@params)
35
- reset
36
- return response.getResponse()
37
- end
1
+ module Moceansdk
2
+ module Modules
3
+ module Account
4
+
5
+ class Pricing < Moceansdk::Modules::AbstractClient
6
+ def initialize(obj_auth, transmitter)
7
+ super(obj_auth, transmitter)
8
+ @required_fields = ['mocean-api-key', 'mocean-api-secret']
9
+ end
10
+
11
+ def mcc=(param)
12
+ @params['mocean-mcc'] = param
13
+ end
14
+
15
+ def mnc=(param)
16
+ @params['mocean-mnc'] = param
17
+ end
18
+
19
+ def delimiter=(param)
20
+ @params['mocean-delimiter'] = param
21
+ end
22
+
23
+ def resp_format=(param)
24
+ @params['mocean-resp-format'] = param
25
+ end
26
+
27
+ def inquiry(params = {})
28
+ create(params)
29
+ create_final_params
30
+ required_field_set?
31
+
32
+ @transmitter.get('/account/pricing', @params)
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
38
  end
@@ -0,0 +1,47 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+
5
+ class Command < Moceansdk::Modules::AbstractClient
6
+ def initialize(obj_auth, transmitter)
7
+ super(obj_auth, transmitter)
8
+ @required_fields = ['mocean-api-key', 'mocean-api-secret','mocean-command']
9
+ end
10
+
11
+ def event_url=(param)
12
+ @params['mocean-event-url'] = param
13
+ end
14
+
15
+ def mocean_command=(param)
16
+ if param.is_a? McBuilder
17
+ @params['mocean-command'] = JSON.generate(param.build)
18
+ elsif param.is_a? McObject::AbstractMc
19
+ @params['mocean-command'] = JSON.generate([param.get_request_data])
20
+ elsif param.is_a? Array
21
+ @params['mocean-command'] = JSON.generate(param)
22
+ else
23
+ @params['mocean-command'] = param
24
+ end
25
+ end
26
+
27
+
28
+ def execute(params = {})
29
+ sym_params = Moceansdk::Utils.convert_to_symbol_hash(params)
30
+
31
+ unless sym_params[:'mocean-command'].nil?
32
+ mc = sym_params[:'mocean-command']
33
+ sym_params.delete(:'mocean-command')
34
+ self.mocean_command = mc
35
+ end
36
+
37
+ create(sym_params)
38
+ create_final_params
39
+ required_field_set?
40
+
41
+ # @sym_params[:'mocean-command'] = JSON.generate(@sym_params[:'mocean-command'].build)
42
+ @transmitter.post('/send-message', @params)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+
5
+ class Mc
6
+ def self.tg_send_text()
7
+ McObject::TgSendText.new
8
+ end
9
+
10
+ def self.tg_send_audio()
11
+ McObject::TgSendAudio.new
12
+ end
13
+
14
+ def self.tg_send_animation()
15
+ McObject::TgSendAnimation.new
16
+ end
17
+
18
+ def self.tg_send_document()
19
+ McObject::TgSendDocument.new
20
+ end
21
+
22
+ def self.tg_send_photo()
23
+ McObject::TgSendPhoto.new
24
+ end
25
+
26
+ def self.tg_send_video()
27
+ McObject::TgSendVideo.new
28
+ end
29
+
30
+ def self.tg_request_contact()
31
+ McObject::TgRequestContact.new
32
+ end
33
+
34
+ def self.send_sms()
35
+ McObject::SendSMS.new
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
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,36 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class AbstractMc
7
+ def initialize(params = nil)
8
+ @params = {}
9
+ @params = Moceansdk::Utils.convert_to_symbol_hash(params) unless params.nil?
10
+ end
11
+
12
+ def get_request_data
13
+ @params = Moceansdk::Utils.convert_to_symbol_hash(@params)
14
+ required_key.each do |key|
15
+ if @params[:"#{key}"].nil?
16
+ raise Moceansdk::Exceptions::RequiredFieldException, "#{key} is mandatory field, can't leave empty (#{self})"
17
+ end
18
+ end
19
+ @params[:action] = action
20
+ @params
21
+ end
22
+
23
+ def required_key
24
+ raise NotImplementedError, 'AbstractMc is a abstract class'
25
+ end
26
+
27
+ def action
28
+ raise NotImplementedError, 'AbstractMc is a abstract class'
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class SendSMS < AbstractMc
7
+ def action
8
+ 'send-sms'
9
+ end
10
+
11
+ def required_key
12
+ ['from','to','content']
13
+ end
14
+
15
+ def from(from, contact_type = 'phone_num')
16
+ @params[:'from'] = {}
17
+ @params[:'from'][:'id'] = from
18
+ @params[:'from'][:'type'] = contact_type
19
+ return self
20
+ end
21
+
22
+ def to(to, contact_type = "phone_num")
23
+ @params[:'to'] = {}
24
+ @params[:'to'][:'id'] = to
25
+ @params[:'to'][:'type'] = contact_type
26
+ return self
27
+ end
28
+
29
+ def content(text)
30
+ @params[:'content'] = {}
31
+ @params[:'content'][:'text'] = text
32
+ @params[:'content'][:'type'] = 'text'
33
+ return self
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgRequestContact < AbstractMc
7
+ def action
8
+ 'send-telegram'
9
+ end
10
+
11
+ def required_key
12
+ ['from', 'to', 'content', 'tg_keyboard']
13
+ end
14
+
15
+ def from(from, contact_type = 'bot_username')
16
+ @params[:'from'] = {}
17
+ @params[:'from'][:'id'] = from
18
+ @params[:'from'][:'type'] = contact_type
19
+ return self
20
+ end
21
+
22
+ def to(to, contact_type = "chat_id")
23
+ @params[:'to'] = {}
24
+ @params[:'to'][:'id'] = to
25
+ @params[:'to'][:'type'] = contact_type
26
+ return self
27
+ end
28
+
29
+ def content(text)
30
+ @params[:'content'] = {}
31
+ @params[:'content'][:'text'] = text
32
+ @params[:'content'][:'type'] = 'text'
33
+ return self
34
+ end
35
+
36
+ def button(text)
37
+ @params[:'tg_keyboard'] = {
38
+ :'button_text' => text,
39
+ :'button_request' => 'contact'
40
+ }
41
+ return self
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgSendAnimation < AbstractMc
7
+ def action
8
+ 'send-telegram'
9
+ end
10
+
11
+ def required_key
12
+ ['from','to','content']
13
+ end
14
+
15
+ def from(from, contact_type = 'bot_username')
16
+ @params[:'from'] = {}
17
+ @params[:'from'][:'id'] = from
18
+ @params[:'from'][:'type'] = contact_type
19
+ return self
20
+ end
21
+
22
+ def to(to, contact_type = "chat_id")
23
+ @params[:'to'] = {}
24
+ @params[:'to'][:'id'] = to
25
+ @params[:'to'][:'type'] = contact_type
26
+ return self
27
+ end
28
+
29
+ def content(url,text)
30
+ @params[:'content'] = {}
31
+ @params[:'content'][:'rich_media_url'] = url
32
+ @params[:'content'][:'text'] = text
33
+ @params[:'content'][:'type'] = 'animation'
34
+ return self
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgSendAudio < AbstractMc
7
+ def action
8
+ 'send-telegram'
9
+ end
10
+
11
+ def required_key
12
+ ['from','to','content']
13
+ end
14
+
15
+ def from(from, contact_type = 'bot_username')
16
+ @params[:'from'] = {}
17
+ @params[:'from'][:'id'] = from
18
+ @params[:'from'][:'type'] = contact_type
19
+ return self
20
+ end
21
+
22
+ def to(to, contact_type = "chat_id")
23
+ @params[:'to'] = {}
24
+ @params[:'to'][:'id'] = to
25
+ @params[:'to'][:'type'] = contact_type
26
+ return self
27
+ end
28
+
29
+ def content(url, text)
30
+ @params[:'content'] = {}
31
+ @params[:'content'][:'rich_media_url'] = url
32
+ @params[:'content'][:'text'] = text
33
+ @params[:'content'][:'type'] = 'audio'
34
+ return self
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgSendDocument < AbstractMc
7
+ def action
8
+ 'send-telegram'
9
+ end
10
+
11
+ def required_key
12
+ ['from','to','content']
13
+ end
14
+
15
+ def from(from, contact_type = 'bot_username')
16
+ @params[:'from'] = {}
17
+ @params[:'from'][:'id'] = from
18
+ @params[:'from'][:'type'] = contact_type
19
+ return self
20
+ end
21
+
22
+ def to(to, contact_type = "chat_id")
23
+ @params[:'to'] = {}
24
+ @params[:'to'][:'id'] = to
25
+ @params[:'to'][:'type'] = contact_type
26
+ return self
27
+ end
28
+
29
+ def content(url,text)
30
+ @params[:'content'] = {}
31
+ @params[:'content'][:'rich_media_url'] = url
32
+ @params[:'content'][:'text'] = text
33
+ @params[:'content'][:'type'] = 'document'
34
+ return self
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end