moceansdk 0.1.2

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: 998cc0538b41009c84ef1b496953b91b435c4e06
4
+ data.tar.gz: cbc6985ad042e3f163505e6507d3f6097525f822
5
+ SHA512:
6
+ metadata.gz: 4d43cf606822e08b9a3748cd86f388624dd080124d0e7be7094ff7dcb4f809060c2fef88201f6bf33f70a1fe3ea112389666892ee88fc7e2909c080523fdfdfc
7
+ data.tar.gz: 0c51c50fd2925f847a738a74c0b77145345173cd3ed8a8f9faf28b9d7d766a844bfe0e277558ff8cffabedb9696effebc7cf5c52f31e1a314a569b6d308c0666
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Micro Ocean Technologies Sdn Bhd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ MoceanAPI Client Library for Ruby
2
+ ============================
3
+
4
+ This is the Ruby client library for use Mocean's API. To use this, you'll need a Mocean account. Sign up [for free at
5
+ moceanapi.com][signup].
6
+
7
+ * [Installation](#installation)
8
+ * [Usage](#usage)
9
+ * [Example](#example)
10
+
11
+ ## Installation
12
+
13
+ To use the client library you'll need to have [created a Mocean account][signup].
14
+
15
+ To install the Ruby client library using Gem.
16
+
17
+ ```bash
18
+ gem install moceansdk
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Create a client with your API key and secret:
24
+
25
+ ```ruby
26
+ require "moceanapi/init"
27
+
28
+ token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
29
+ mocean = Mocean.new(token)
30
+ ```
31
+
32
+ ## Example
33
+
34
+ To use [Mocean's SMS API][doc_sms] to send an SMS message, call the `mocean.sms.create().send()` method.
35
+
36
+ The API can be called directly, using a simple array of parameters, the keys match the [parameters of the API][doc_sms].
37
+
38
+ ```ruby
39
+ res = mocean.sms.create({
40
+ "mocean-text"=>'Hello World',
41
+ "mocean-from"=>'MOCEAN',
42
+ "mocean-to"=>'60123456789'
43
+ }).send()
44
+
45
+ puts res
46
+ ```
47
+
48
+ ## License
49
+
50
+ This library is released under the [MIT License][license]
51
+
52
+ [signup]: https://dashboard.moceanapi.com/register?medium=github&campaign=sdk-ruby
53
+ [doc_sms]: https://docs.moceanapi.com/?ruby#send-sms
54
+ [doc_inbound]: https://docs.moceanapi.com/?ruby#receive-sms
55
+ [doc_verify]: https://docs.moceanapi.com/?ruby#overview-3
56
+ [license]: LICENSE.txt
@@ -0,0 +1,14 @@
1
+ class Client
2
+ attr_reader :api_key,:api_secret
3
+ def initialize api_key = '',api_secret = ''
4
+ @api_key = api_key
5
+ @api_secret = api_secret
6
+ end
7
+
8
+ def set_api_key(api_key)
9
+ @api_key = api_key
10
+ end
11
+ def set_api_secret(api_secret)
12
+ @api_secret = api_secret
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module Deno92
2
+ require_relative "./mocean"
3
+ require_relative "./client"
4
+ end
@@ -0,0 +1,52 @@
1
+ class Mocean
2
+
3
+ attr_reader :obj_auth
4
+
5
+ def initialize client = Client
6
+ if client.class == Client
7
+ @obj_auth = client
8
+ elsif client.api_key == nil || client.api_secret == nil
9
+ raise Exception.new("Api key and api secret can't be empty")
10
+ else
11
+ raise Exception.new("Arguement pass into Mocean object must be Client object")
12
+ end
13
+ end
14
+
15
+ def sms
16
+ require_relative "modules/message/sms"
17
+ return Sms.new(@obj_auth)
18
+
19
+ end
20
+
21
+ def flashSms
22
+ require_relative "modules/message/sms"
23
+ _sms = Sms.new(@obj_auth)
24
+ _sms.flashSms = true
25
+ return _sms
26
+ end
27
+
28
+ def pricing_list
29
+ require_relative "modules/account/pricing"
30
+ return Pricing.new(@obj_auth)
31
+ end
32
+
33
+ def balance
34
+ require_relative "modules/account/balance"
35
+ return Balance.new(@obj_auth)
36
+ end
37
+
38
+ def message_status
39
+ require_relative "modules/message/message_status"
40
+ return Message_status.new(@obj_auth)
41
+ end
42
+
43
+ def verify_request
44
+ require_relative "modules/message/verify_request"
45
+ return Verify_request.new(@obj_auth)
46
+ end
47
+
48
+ def verify_validate
49
+ require_relative "modules/message/verify_validate"
50
+ return Verify_validate.new(@obj_auth)
51
+ end
52
+ end
@@ -0,0 +1,139 @@
1
+ require "net/http"
2
+ require "uri"
3
+
4
+ class MoceanFactory
5
+ attr_accessor :params
6
+
7
+ def initialize client
8
+ @params = {}
9
+ @params['mocean-api-key'] = client.api_key
10
+ @params['mocean-api-secret'] = client.api_secret
11
+ end
12
+
13
+ def create params = {}
14
+ if params.class != Hash
15
+ raise Exception.new('Params past into create must be hash.')
16
+ end
17
+ tmp_params = params
18
+ tmp_params.each do |key,value|
19
+ if !isParamPrefixSet(key)
20
+ params["mocean-"+key] = value
21
+ params.delete(k)
22
+ end
23
+ end
24
+ tmp_params = nil
25
+ @params = @params.merge(params)
26
+ end
27
+
28
+ def createFinalParams
29
+ final_params = {}
30
+ @params.each do |key,value|
31
+ unless value.nil? || (value.class != Integer && value.empty?)
32
+ final_params[key] = value
33
+ end
34
+ end
35
+ @params = final_params
36
+ end
37
+
38
+ def createResponse response
39
+ end
40
+
41
+ def isParamPrefixSet param
42
+ if param.class != String
43
+ raise Exception.new("Parameter key must be string, "+param.class+" given.")
44
+ end
45
+ if param.scan(/^mocean-/i).empty?
46
+ return false
47
+ end
48
+ return true
49
+ end
50
+
51
+ def isRequiredFieldsSet
52
+ if @required_fields.class == 'Array' && !@required_fields.empty?
53
+ @required_fields.each do |field|
54
+ if @params[field] == nil
55
+ raise Exception.new("#{field} is mandatory field, can't leave empty")
56
+ end
57
+ end
58
+ end
59
+ return true
60
+ end
61
+
62
+ def reset()
63
+ @params.each do |key,value|
64
+ if key == 'mocean-api-key' || key == 'mocean-api-secret'
65
+ next
66
+ end
67
+ @params[key] = nil
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ class Transmitter
74
+
75
+ def initialize uri,method,params
76
+ @URL = 'rest-api.moceansms.com'
77
+ @uri = uri
78
+ @params = params
79
+
80
+ begin
81
+ @http = Net::HTTP.new(@URL,443)
82
+ @http.use_ssl = true
83
+ rescue Exception
84
+ raise Exception.new('Unable to create connection, please contact SDK provider.')
85
+ end
86
+
87
+ case method.downcase
88
+ when 'get'
89
+ @response = __get
90
+ when 'post'
91
+ @response = __post
92
+ when 'put'
93
+ @response = __put
94
+ when 'delete'
95
+ @response = __delete
96
+ else
97
+ raise Exception.new("Unknown request method, please contact SDK provider.")
98
+ end
99
+
100
+ end
101
+
102
+ def __get
103
+ form_data = ''
104
+ if @params.size > 0
105
+ form_data = URI.encode_www_form(@params)
106
+ end
107
+ request = Net::HTTP::Get.new(@uri+"?"+form_data)
108
+ return @http.request(request)
109
+ end
110
+
111
+ def __post
112
+ request = Net::HTTP::Post.new(@uri)
113
+ if @params.size > 0
114
+ request.form_data = @params
115
+ end
116
+ return @http.request(request)
117
+ end
118
+
119
+ def __put
120
+ request = Net::HTTP::Put.new(@uri)
121
+ if @params.size > 0
122
+ request.form_data = @params
123
+ end
124
+ return @http.request(request)
125
+ end
126
+
127
+ def __delete
128
+ request = Net::HTTP::Delete.new(@uri)
129
+ if @params.size > 0
130
+ request.form_data = @params
131
+ end
132
+ return @http.request(request)
133
+ end
134
+
135
+ def getResponse
136
+ @response.body || nil
137
+ end
138
+
139
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "../abstract"
2
+
3
+ class Balance < MoceanFactory
4
+ def initialize client
5
+ super(client)
6
+ @required_fields = ['mocean-api-key','mocean-api-secret']
7
+ end
8
+
9
+ def setRespFormat param
10
+ @params['mocean-resp-format'] = param
11
+ return self
12
+ end
13
+
14
+ def inquiry params = {}
15
+ create(params)
16
+ createFinalParams
17
+ isRequiredFieldsSet
18
+ response = Transmitter.new('/rest/1/account/balance','get', @params)
19
+ reset
20
+ return response.getResponse()
21
+ end
22
+ end
@@ -0,0 +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
38
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../abstract"
2
+
3
+ class Message_status < MoceanFactory
4
+ def initialize client
5
+ super(client)
6
+ @required_fields = ['mocean-api-key','mocean-api-secret','mocean-msgid']
7
+ end
8
+
9
+ def setMsgid param
10
+ @params['mocean-msgid'] = param
11
+ end
12
+
13
+ def setRespFormat param
14
+ @params['mocean-resp-format'] = param
15
+ end
16
+
17
+ def inquiry params
18
+ create(params)
19
+ createFinalParams
20
+ isRequiredFieldsSet
21
+ response = Transmitter.new('/rest/1/report/message','get',@params)
22
+ reset
23
+ return response.getResponse()
24
+ end
25
+ end
@@ -0,0 +1,96 @@
1
+ require_relative "../abstract"
2
+
3
+ class Sms < MoceanFactory
4
+
5
+ attr_writer :flashSms
6
+
7
+ def initialize client
8
+ super(client)
9
+ @flashSms = false
10
+ @required_fileds = ['mocean-api-key','mocean-api-secret','mocean-from','mocean-to','mocean-text']
11
+ end
12
+
13
+ def setFrom param
14
+ @params['mocean-from'] = param
15
+ return self
16
+ end
17
+
18
+ def setTo param
19
+ @params['mocean-to'] = param
20
+ return self
21
+ end
22
+
23
+ def setText param
24
+ @params['mocean-text'] = param
25
+ return self
26
+ end
27
+
28
+ def setUdh param
29
+ @params['mocean-udh'] = param
30
+ return self
31
+ end
32
+
33
+ def setCoding param
34
+ @params['mocean-coding'] = param
35
+ return self
36
+ end
37
+
38
+ def setDlrMask param
39
+ @params['mocean-dlr-mask'] = param
40
+ return self
41
+ end
42
+
43
+ def setDlrUrl param
44
+ @params['mocean-dlr-url'] = param
45
+ return self
46
+ end
47
+
48
+ def setSchedule param
49
+ @params['mocean-schedule'] = param
50
+ return self
51
+ end
52
+
53
+ def setMclass param
54
+ @params['mocean-mclass'] = param
55
+ return self
56
+ end
57
+
58
+ def setAltDcs param
59
+ @params['mocean-alt-dcs'] = param
60
+ return self
61
+ end
62
+
63
+ def setCharset param
64
+ @params['mocean-charset'] = param
65
+ return self
66
+ end
67
+
68
+ def setValidity param
69
+ @params['mocean-validity'] = param
70
+ return self
71
+ end
72
+
73
+ def setRespFormat param
74
+ @params['mocean-resp-format'] = param
75
+ return self
76
+ end
77
+
78
+ def create params = {}
79
+ reset
80
+ super(params)
81
+ return self
82
+ end
83
+
84
+ def send
85
+ if @flashSms == true
86
+ setMclass(1)
87
+ setAltDcs(1)
88
+ end
89
+ createFinalParams
90
+ isRequiredFieldsSet
91
+ response = Transmitter.new('/rest/1/sms','post',@params)
92
+ return response.getResponse()
93
+ end
94
+
95
+
96
+ end
@@ -0,0 +1,59 @@
1
+ require_relative "../abstract"
2
+
3
+ class Verify_request < MoceanFactory
4
+
5
+ def __init__ client
6
+ super(client)
7
+ @required_fields = ['mocean-api-key','mocean-api-secret','mocean-to','mocean-brand']
8
+ end
9
+
10
+ def setTo param
11
+ @params['mocean-to'] = param
12
+ return self
13
+ end
14
+
15
+ def setBrand
16
+ @params['mocean-brand'] = param
17
+ return self;
18
+ end
19
+
20
+ def setFrom param
21
+ @params['mocean-from'] = param
22
+ return self;
23
+ end
24
+
25
+ def setTemplate param
26
+ @params['mocean-template'] = param
27
+ return self;
28
+ end
29
+
30
+ def setPinValidate param
31
+ @params['mocean-pin-validate'] = param
32
+ return self
33
+ end
34
+
35
+ def setNextEventWait param
36
+ @params['mocean-next-event-wait'] = param
37
+ return self
38
+ end
39
+
40
+ def setRespFormat param
41
+ @params['mocean-resp-format'] = param
42
+ return self
43
+ end
44
+
45
+ def create params = {}
46
+ reset
47
+ super(params)
48
+ return self
49
+ end
50
+
51
+ def send
52
+ createFinalParams
53
+ isRequiredFieldsSet
54
+ response = Transmitter.new('/rest/1/verify/req','post',@params)
55
+ return response.getResponse()
56
+ end
57
+
58
+
59
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "../abstract"
2
+
3
+ class Verify_validate < MoceanFactory
4
+
5
+ def __init__ client
6
+ super(client)
7
+ @required_fields = ['mocean-api-key','mocean-api-secret','mocean-reqid','mocean-otp-code']
8
+ end
9
+
10
+ def setReqid param
11
+ @params['mocean-reqid'] = param
12
+ return self
13
+ end
14
+
15
+ def setOtpCode param
16
+ @params['mocean-otp-code'] = param
17
+ return self
18
+ end
19
+
20
+ def setRespFormat param
21
+ @params['mocean-resp-format'] = param
22
+ return self
23
+ end
24
+
25
+ def create params = {}
26
+ reset
27
+ super(param)
28
+ return self
29
+ end
30
+
31
+ def send
32
+ createFinalParams
33
+ isRequiredFieldsSet
34
+ response = Transmitter.new('/rest/1/verify/check','post',@params)
35
+ return response.getResponse()
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ module Moceansdk
2
+ VERSION = "0.1.2"
3
+ end
data/lib/moceansdk.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "moceansdk/version"
2
+ require "moceansdk/init"
3
+
4
+ module Moceansdk
5
+
6
+ end
data/moceansdk.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ require File.expand_path('lib/moceansdk/version', File.dirname(__FILE__))
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'moceansdk'
5
+ s.version = Moceansdk::VERSION
6
+ s.license = 'MIT'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Micro Ocean Technologies Sdn Bhd']
9
+ s.email = ['support@moceanapi.com']
10
+ s.homepage = 'https://github.com/moceanapi/mocean-sdk-ruby'
11
+ s.description = 'Mocean SDK for Ruby'
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
+ s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md moceansdk.gemspec)
14
+ s.required_ruby_version = '>= 2.0.0'
15
+ s.add_dependency('openssl')
16
+ s.add_development_dependency('rake', '~> 12.0')
17
+ s.add_development_dependency('minitest', '~> 5.0')
18
+ s.add_development_dependency('webmock', '~> 3.0')
19
+ s.require_path = 'lib'
20
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moceansdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Micro Ocean Technologies Sdn Bhd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openssl
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
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Mocean SDK for Ruby
70
+ email:
71
+ - support@moceanapi.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/moceansdk.rb
79
+ - lib/moceansdk/client.rb
80
+ - lib/moceansdk/init.rb
81
+ - lib/moceansdk/mocean.rb
82
+ - lib/moceansdk/modules/abstract.rb
83
+ - lib/moceansdk/modules/account/balance.rb
84
+ - lib/moceansdk/modules/account/pricing.rb
85
+ - lib/moceansdk/modules/message/message_status.rb
86
+ - lib/moceansdk/modules/message/sms.rb
87
+ - lib/moceansdk/modules/message/verify_request.rb
88
+ - lib/moceansdk/modules/message/verify_validate.rb
89
+ - lib/moceansdk/version.rb
90
+ - moceansdk.gemspec
91
+ homepage: https://github.com/moceanapi/mocean-sdk-ruby
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.14.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: This is a Mocean SDK written in Ruby, to use it you will need a mocean account.
115
+ Signup for free at https://moceanapi.com
116
+ test_files: []