moceansdk 1.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6afe87fef5a9c54ffd8fa33c4762ea50515918ec4049276e2d2e41fd510153a
4
- data.tar.gz: b5af61783dbe5ceaa491de065a52608a2bd9a7399088797ec5bbf31d105f1e8b
3
+ metadata.gz: b0b4c0c5f19f708f2e1d0f255eed1341244f64922b75cde574d9765cadc570f6
4
+ data.tar.gz: 628465a50f969494c965a77b5f0868c89ac11d0b1f0be7f2b0d17c0ac786cc8c
5
5
  SHA512:
6
- metadata.gz: a0093116366cf6d19fce9d0b39f7e194098899a4d7dd195cfef71875d709498fe03da51b0a3c2bf1f2d97e1d5e9ac75288b94ad83fa54e4c4a23342b7c930166
7
- data.tar.gz: c9931cd1bf804cbccf4d0f0f3d25597efb403a114e42c5d8324f55b8aa103913386b7f51ac513d9a004a7da72f2df9f52b384f6210129b0652eaa6c9c7d7e3c0
6
+ metadata.gz: a1a3f349fdf7127a1157272a7cb56cac46a03d139ff8a03f756218f5697f936ac35bb4a20ec2056de93dda42100649e88ed789d2c55f9aed375f0828d9ff0f52
7
+ data.tar.gz: 38ba32440b25ad20da427f5e5242eaf0ab03ba22b273344a140d02e887424fbb216b6a5faacdb82cf4a5b0d44926f24c49f182446b1e1a366cfe827a2c1fbff8
data/README.md CHANGED
@@ -2,6 +2,7 @@ MoceanAPI Client Library for Ruby
2
2
  ============================
3
3
  [![Gem Version](https://img.shields.io/gem/v/moceansdk.svg)](https://rubygems.org/gems/moceansdk)
4
4
  [![build status](https://img.shields.io/travis/com/MoceanAPI/mocean-sdk-ruby.svg)](https://travis-ci.com/MoceanAPI/mocean-sdk-ruby)
5
+ [![Github build status](https://github.com/MoceanAPI/mocean-sdk-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/MoceanAPI/mocean-sdk-ruby/actions/workflows/build.yml)
5
6
  [![codecov](https://img.shields.io/codecov/c/github/MoceanAPI/mocean-sdk-ruby.svg)](https://codecov.io/gh/MoceanAPI/mocean-sdk-ruby)
6
7
  [![codacy](https://img.shields.io/codacy/grade/7564ecfa8e7948a7ba15cb7634258c7e.svg)](https://app.codacy.com/project/MoceanAPI/mocean-sdk-ruby/dashboard)
7
8
  [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
@@ -68,7 +69,7 @@ Kindly visit [MoceanApi Docs][doc_main] for more usage
68
69
 
69
70
  This library is released under the [MIT License][license]
70
71
 
71
- [signup]: https://dashboard.moceanapi.com/register?medium=github&campaign=sdk-ruby
72
+ [signup]: https://dashboard.moceanapi.com/register?medium=github&campaign=ruby-sdk
72
73
  [doc_main]: https://moceanapi.com/docs/?ruby
73
74
  [doc_sms]: https://moceanapi.com/docs/?ruby#send-sms
74
75
  [license]: LICENSE.txt
data/lib/moceansdk.rb CHANGED
@@ -34,6 +34,19 @@ require 'moceansdk/modules/voice/mc'
34
34
  require 'moceansdk/modules/voice/mc_builder'
35
35
  require 'moceansdk/modules/voice/voice'
36
36
 
37
+ require 'moceansdk/modules/command/mc_object/abstract_mc'
38
+ require 'moceansdk/modules/command/mc_object/tg_send_text'
39
+ require 'moceansdk/modules/command/mc_object/tg_send_audio'
40
+ require 'moceansdk/modules/command/mc_object/tg_send_animation'
41
+ require 'moceansdk/modules/command/mc_object/tg_send_photo'
42
+ require 'moceansdk/modules/command/mc_object/tg_send_video'
43
+ require 'moceansdk/modules/command/mc_object/tg_send_document'
44
+ require 'moceansdk/modules/command/mc_object/tg_request_contact'
45
+ require 'moceansdk/modules/command/mc_object/send_sms'
46
+ require 'moceansdk/modules/command/mc'
47
+ require 'moceansdk/modules/command/mc_builder'
48
+ require 'moceansdk/modules/command/command'
49
+
37
50
  require 'moceansdk/utils'
38
51
  require 'moceansdk/version'
39
52
  require 'moceansdk/client'
@@ -61,6 +61,10 @@ module Moceansdk
61
61
  def voice
62
62
  Modules::Voice::Voice.new(@obj_auth, @transmitter)
63
63
  end
64
+
65
+ def command
66
+ Modules::Command::Command.new(@obj_auth, @transmitter)
67
+ end
64
68
  end
65
69
 
66
70
  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
@@ -0,0 +1,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgSendPhoto < 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'] = 'photo'
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 TgSendText < 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(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,41 @@
1
+ module Moceansdk
2
+ module Modules
3
+ module Command
4
+ module McObject
5
+
6
+ class TgSendVideo < 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'] = 'video'
34
+ return self
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -5,6 +5,7 @@ module Moceansdk
5
5
  class Channel
6
6
  AUTO = 1
7
7
  SMS = 2
8
+ TELEGRAM = 3
8
9
  end
9
10
 
10
11
  end
@@ -63,6 +63,8 @@ module Moceansdk
63
63
 
64
64
  if @channel == Channel::SMS
65
65
  verify_request_url += '/sms'
66
+ elsif @channel == Channel::TELEGRAM
67
+ verify_request_url += '/telegram'
66
68
  end
67
69
 
68
70
  @transmitter.post(verify_request_url, @params)
@@ -1,3 +1,3 @@
1
1
  module Moceansdk
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/moceansdk.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.description = 'Mocean SDK for Ruby'
12
12
  s.summary = 'This is a Mocean SDK written in Ruby, to use it you will need a mocean account. Signup for free at https://moceanapi.com'
13
13
  s.files = Dir.glob('lib/**/*.rb') + %w(LICENSE.txt README.md moceansdk.gemspec)
14
- s.required_ruby_version = '>= 2.2.0'
14
+ s.required_ruby_version = '>= 2.3.0'
15
15
  s.add_dependency('hash_dot', '~> 2.4')
16
16
  s.add_dependency('http', '>= 3', '< 5')
17
17
  s.add_dependency('xml-simple', '~> 1.1')
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.1.0
4
+ version: 1.1.1
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-14 00:00:00.000000000 Z
11
+ date: 2021-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_dot
@@ -132,6 +132,18 @@ files:
132
132
  - lib/moceansdk/modules/abstact_client.rb
133
133
  - lib/moceansdk/modules/account/balance.rb
134
134
  - lib/moceansdk/modules/account/pricing.rb
135
+ - lib/moceansdk/modules/command/command.rb
136
+ - lib/moceansdk/modules/command/mc.rb
137
+ - lib/moceansdk/modules/command/mc_builder.rb
138
+ - lib/moceansdk/modules/command/mc_object/abstract_mc.rb
139
+ - lib/moceansdk/modules/command/mc_object/send_sms.rb
140
+ - lib/moceansdk/modules/command/mc_object/tg_request_contact.rb
141
+ - lib/moceansdk/modules/command/mc_object/tg_send_animation.rb
142
+ - lib/moceansdk/modules/command/mc_object/tg_send_audio.rb
143
+ - lib/moceansdk/modules/command/mc_object/tg_send_document.rb
144
+ - lib/moceansdk/modules/command/mc_object/tg_send_photo.rb
145
+ - lib/moceansdk/modules/command/mc_object/tg_send_text.rb
146
+ - lib/moceansdk/modules/command/mc_object/tg_send_video.rb
135
147
  - lib/moceansdk/modules/message/channel.rb
136
148
  - lib/moceansdk/modules/message/message_status.rb
137
149
  - lib/moceansdk/modules/message/sms.rb
@@ -167,15 +179,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
179
  requirements:
168
180
  - - ">="
169
181
  - !ruby/object:Gem::Version
170
- version: 2.2.0
182
+ version: 2.3.0
171
183
  required_rubygems_version: !ruby/object:Gem::Requirement
172
184
  requirements:
173
185
  - - ">="
174
186
  - !ruby/object:Gem::Version
175
187
  version: '0'
176
188
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.7.7
189
+ rubygems_version: 3.1.4
179
190
  signing_key:
180
191
  specification_version: 4
181
192
  summary: This is a Mocean SDK written in Ruby, to use it you will need a mocean account.