moceansdk 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,18 @@
1
- module Moceansdk
2
- module Exceptions
3
-
4
- class MoceanError < StandardError
5
- attr_reader :error_response
6
-
7
- def initialize(msg, error_response = nil)
8
- if error_response.nil?
9
- super(msg)
10
- else
11
- super(error_response['err_msg'])
12
- @error_response = error_response
13
- end
14
- end
15
- end
16
-
17
- end
18
- end
1
+ module Moceansdk
2
+ module Exceptions
3
+
4
+ class MoceanError < StandardError
5
+ attr_reader :error_response
6
+
7
+ def initialize(msg, error_response = nil)
8
+ if error_response.nil?
9
+ super(msg)
10
+ else
11
+ super(error_response['err_msg'])
12
+ @error_response = error_response
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -1,8 +1,8 @@
1
- module Moceansdk
2
- module Exceptions
3
-
4
- class RequiredFieldException < MoceanError
5
- end
6
-
7
- end
8
- end
1
+ module Moceansdk
2
+ module Exceptions
3
+
4
+ class RequiredFieldException < MoceanError
5
+ end
6
+
7
+ end
8
+ end
@@ -1,54 +1,54 @@
1
- module Moceansdk
2
- module Modules
3
-
4
- class AbstractClient
5
- attr_accessor :params
6
-
7
- def initialize(obj_auth, transmitter)
8
- @params = obj_auth.params
9
- @transmitter = transmitter
10
- end
11
-
12
- def create(params = {})
13
- @params = @params.merge(params) if params.is_a? Hash
14
- end
15
-
16
- def create_final_params
17
- final_params = {}
18
- @params.each do |key, value|
19
- unless value.nil?
20
- param_prefix_set?(key) ? final_params[key] = value : final_params["mocean-#{key}"] = value
21
- end
22
- end
23
-
24
- # convert string hash to symbol hash
25
- @params = final_params.inject({}) {|memo, (k, v)| memo[k.to_sym] = v; memo}
26
- end
27
-
28
- def param_prefix_set?(key)
29
- cloned_key = if key.is_a? String
30
- key
31
- else
32
- key.to_s
33
- end
34
-
35
- return false if cloned_key.scan(/^mocean-/i).empty?
36
-
37
- true
38
- end
39
-
40
- def required_field_set?
41
- if @required_fields.is_a?(Array) && !@required_fields.empty?
42
- @required_fields.each do |field|
43
- if @params[:"#{field}"].nil?
44
- raise Moceansdk::Exceptions::RequiredFieldException, "#{field} is mandatory field, can't leave empty"
45
- end
46
- end
47
- end
48
-
49
- true
50
- end
51
- end
52
-
53
- end
1
+ module Moceansdk
2
+ module Modules
3
+
4
+ class AbstractClient
5
+ attr_accessor :params
6
+
7
+ def initialize(obj_auth, transmitter)
8
+ @params = obj_auth.params
9
+ @transmitter = transmitter
10
+ end
11
+
12
+ def create(params = {})
13
+ @params = @params.merge(params) if params.is_a? Hash
14
+ end
15
+
16
+ def create_final_params
17
+ final_params = {}
18
+ @params.each do |key, value|
19
+ unless value.nil?
20
+ param_prefix_set?(key) ? final_params[key] = value : final_params["mocean-#{key}"] = value
21
+ end
22
+ end
23
+
24
+ # convert string hash to symbol hash
25
+ @params = final_params.inject({}) {|memo, (k, v)| memo[k.to_sym] = v; memo}
26
+ end
27
+
28
+ def param_prefix_set?(key)
29
+ cloned_key = if key.is_a? String
30
+ key
31
+ else
32
+ key.to_s
33
+ end
34
+
35
+ return false if cloned_key.scan(/^mocean-/i).empty?
36
+
37
+ true
38
+ end
39
+
40
+ def required_field_set?
41
+ if @required_fields.is_a?(Array) && !@required_fields.empty?
42
+ @required_fields.each do |field|
43
+ if @params[:"#{field}"].nil?
44
+ raise Moceansdk::Exceptions::RequiredFieldException, "#{field} is mandatory field, can't leave empty"
45
+ end
46
+ end
47
+ end
48
+
49
+ true
50
+ end
51
+ end
52
+
53
+ end
54
54
  end
@@ -1,26 +1,26 @@
1
- module Moceansdk
2
- module Modules
3
- module Account
4
-
5
- class Balance < 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 resp_format=(param)
12
- @params['mocean-resp-format'] = param
13
- end
14
-
15
- def inquiry(params = {})
16
- create(params)
17
- create_final_params
18
- required_field_set?
19
-
20
- @transmitter.get('/account/balance', @params)
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
1
+ module Moceansdk
2
+ module Modules
3
+ module Account
4
+
5
+ class Balance < 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 resp_format=(param)
12
+ @params['mocean-resp-format'] = param
13
+ end
14
+
15
+ def inquiry(params = {})
16
+ create(params)
17
+ create_final_params
18
+ required_field_set?
19
+
20
+ @transmitter.get('/account/balance', @params)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -1,38 +1,38 @@
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
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
@@ -1,12 +1,12 @@
1
- module Moceansdk
2
- module Modules
3
- module Message
4
-
5
- class Channel
6
- AUTO = 1
7
- SMS = 2
8
- end
9
-
10
- end
11
- end
1
+ module Moceansdk
2
+ module Modules
3
+ module Message
4
+
5
+ class Channel
6
+ AUTO = 1
7
+ SMS = 2
8
+ end
9
+
10
+ end
11
+ end
12
12
  end
@@ -1,30 +1,30 @@
1
- module Moceansdk
2
- module Modules
3
- module Message
4
-
5
- class MessageStatus < Moceansdk::Modules::AbstractClient
6
- def initialize(obj_auth, transmitter)
7
- super(obj_auth, transmitter)
8
- @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-msgid']
9
- end
10
-
11
- def msgid=(param)
12
- @params['mocean-msgid'] = param
13
- end
14
-
15
- def resp_format=(param)
16
- @params['mocean-resp-format'] = param
17
- end
18
-
19
- def inquiry(params = {})
20
- create(params)
21
- create_final_params
22
- required_field_set?
23
-
24
- @transmitter.get('/report/message', @params)
25
- end
26
- end
27
-
28
- end
29
- end
1
+ module Moceansdk
2
+ module Modules
3
+ module Message
4
+
5
+ class MessageStatus < Moceansdk::Modules::AbstractClient
6
+ def initialize(obj_auth, transmitter)
7
+ super(obj_auth, transmitter)
8
+ @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-msgid']
9
+ end
10
+
11
+ def msgid=(param)
12
+ @params['mocean-msgid'] = param
13
+ end
14
+
15
+ def resp_format=(param)
16
+ @params['mocean-resp-format'] = param
17
+ end
18
+
19
+ def inquiry(params = {})
20
+ create(params)
21
+ create_final_params
22
+ required_field_set?
23
+
24
+ @transmitter.get('/report/message', @params)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
30
  end
@@ -1,74 +1,74 @@
1
- module Moceansdk
2
- module Modules
3
- module Message
4
-
5
- class Sms < AbstractClient
6
- def initialize(obj_auth, transmitter)
7
- super(obj_auth, transmitter)
8
- @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-from', 'mocean-to', 'mocean-text']
9
- end
10
-
11
- def from=(param)
12
- @params['mocean-from'] = param
13
- end
14
-
15
- def to=(param)
16
- @params['mocean-to'] = param
17
- end
18
-
19
- def text=(param)
20
- @params['mocean-text'] = param
21
- end
22
-
23
- def udh=(param)
24
- @params['mocean-udh'] = param
25
- end
26
-
27
- def coding=(param)
28
- @params['mocean-coding'] = param
29
- end
30
-
31
- def dlr_mask=(param)
32
- @params['mocean-dlr-mask'] = param
33
- end
34
-
35
- def dlr_url=(param)
36
- @params['mocean-dlr-url'] = param
37
- end
38
-
39
- def schedule=(param)
40
- @params['mocean-schedule'] = param
41
- end
42
-
43
- def mclass=(param)
44
- @params['mocean-mclass'] = param
45
- end
46
-
47
- def alt_dcs=(param)
48
- @params['mocean-alt-dcs'] = param
49
- end
50
-
51
- def charset=(param)
52
- @params['mocean-charset'] = param
53
- end
54
-
55
- def validity=(param)
56
- @params['mocean-validity'] = param
57
- end
58
-
59
- def resp_format=(param)
60
- @params['mocean-resp-format'] = param
61
- end
62
-
63
- def send(params = {})
64
- create(params)
65
- create_final_params
66
- required_field_set?
67
-
68
- @transmitter.post('/sms', @params)
69
- end
70
- end
71
-
72
- end
73
- end
74
- end
1
+ module Moceansdk
2
+ module Modules
3
+ module Message
4
+
5
+ class Sms < AbstractClient
6
+ def initialize(obj_auth, transmitter)
7
+ super(obj_auth, transmitter)
8
+ @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-from', 'mocean-to', 'mocean-text']
9
+ end
10
+
11
+ def from=(param)
12
+ @params['mocean-from'] = param
13
+ end
14
+
15
+ def to=(param)
16
+ @params['mocean-to'] = param
17
+ end
18
+
19
+ def text=(param)
20
+ @params['mocean-text'] = param
21
+ end
22
+
23
+ def udh=(param)
24
+ @params['mocean-udh'] = param
25
+ end
26
+
27
+ def coding=(param)
28
+ @params['mocean-coding'] = param
29
+ end
30
+
31
+ def dlr_mask=(param)
32
+ @params['mocean-dlr-mask'] = param
33
+ end
34
+
35
+ def dlr_url=(param)
36
+ @params['mocean-dlr-url'] = param
37
+ end
38
+
39
+ def schedule=(param)
40
+ @params['mocean-schedule'] = param
41
+ end
42
+
43
+ def mclass=(param)
44
+ @params['mocean-mclass'] = param
45
+ end
46
+
47
+ def alt_dcs=(param)
48
+ @params['mocean-alt-dcs'] = param
49
+ end
50
+
51
+ def charset=(param)
52
+ @params['mocean-charset'] = param
53
+ end
54
+
55
+ def validity=(param)
56
+ @params['mocean-validity'] = param
57
+ end
58
+
59
+ def resp_format=(param)
60
+ @params['mocean-resp-format'] = param
61
+ end
62
+
63
+ def send(params = {})
64
+ create(params)
65
+ create_final_params
66
+ required_field_set?
67
+
68
+ @transmitter.post('/sms', @params)
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end