sms-global 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25327c6100d51ea055fef798b8816e89a499dedf7b5f87474b26436e120aa2b4
4
+ data.tar.gz: ba25a2458cce7590b85073fe6bfaaee764fba984b902d4ed56a3b8b9135056a1
5
+ SHA512:
6
+ metadata.gz: '08cbf16efbe0c166da8aaa16059e83962487369bdaee5ddf513040e1729fa8e5183ff3e645bd83b5bb5e8bda33dde0ca80369d91794c9a30a73dadfcf763a9f4'
7
+ data.tar.gz: '078ab7f67428353ba6dae6e4a618d5ee7a016621f84f9498eafc2f65452643edc8d53a7cd11b305f90638719ce8b8a39e90d71ce0af290f19cdaf36a35048d53'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Jarrad M
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.
@@ -0,0 +1,56 @@
1
+ # SMS Global API Library
2
+
3
+ This library is designed to help your ruby/rails based application communicate with SMS global.
4
+
5
+ https://www.smsglobal.com/rest-api/
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sms-global'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sms-global
22
+
23
+ ## Usage
24
+
25
+ ```Ruby
26
+ require 'sms_global'
27
+
28
+ client = SmsGlobal::Client.new(
29
+ key: "<key>",
30
+ secret: "<secret>"
31
+ )
32
+
33
+ # Retrieve all SMS messages
34
+ client.sms.all
35
+
36
+ # Send SMS message
37
+ client.sms.send({
38
+ destination: '0411111111',
39
+ message: 'hello world',
40
+ origin: '0422222222'
41
+ })
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JDrizzy/sms-global.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,25 @@
1
+ class String
2
+ def blank?
3
+ empty? || /\A[[:space:]]*\z/.match?(self)
4
+ end
5
+
6
+ # Convert string to CamelCase
7
+ def to_camel_case(uppercase_first_letter = false)
8
+ string = self
9
+ if uppercase_first_letter
10
+ string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
11
+ else
12
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
13
+ end
14
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
15
+ end
16
+
17
+ # Convert string to snake_case
18
+ def to_snake_case
19
+ self.gsub(/::/, '/').
20
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
21
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
22
+ tr("-", "_").
23
+ downcase
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'core_ext/string'
2
+
3
+ require 'sms_global/object/helper'
4
+ require 'sms_global/object/base'
5
+ require 'sms_global/object/response'
6
+ require 'sms_global/object/request'
7
+
8
+ require 'sms_global/object/auto_topup'
9
+ require 'sms_global/object/contact'
10
+ require 'sms_global/object/group'
11
+ require 'sms_global/object/sms'
12
+ require 'sms_global/object/sms_incoming'
13
+ require 'sms_global/object/shared_pool'
14
+ require 'sms_global/object/dedicated_number'
15
+
16
+ require 'sms_global/exceptions'
17
+ require 'sms_global/client'
@@ -0,0 +1,28 @@
1
+ module SmsGlobal
2
+ class Client
3
+ extend SmsGlobal::Object::Helper
4
+
5
+ URL = 'api.smsglobal.com'.freeze
6
+
7
+ attr_reader :key,
8
+ :secret,
9
+ :url,
10
+ :api_version
11
+
12
+ object :auto_topup
13
+ object :contact
14
+ object :group
15
+ object :sms
16
+ object :sms_incoming
17
+ object :shared_pool
18
+ object :dedicated_number
19
+
20
+ def initialize(options = {})
21
+ opts = options.dup
22
+ @key = opts.delete(:key)
23
+ @secret = opts.delete(:secret)
24
+ @url = opts.delete(:url) || URL
25
+ @api_version = 'v2'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module SmsGlobal
2
+
3
+ class SmsGlobalError < StandardError; end
4
+
5
+ class ApiException < SmsGlobalError
6
+ def initialize(message)
7
+ @message = message
8
+ end
9
+
10
+ def message
11
+ @message
12
+ end
13
+ end
14
+
15
+ class UnauthorizedException < SmsGlobalError
16
+ def message
17
+ 'Unauthorized - The credentials provided are incorrect'
18
+ end
19
+ end
20
+
21
+ class NoSupportedMethod < SmsGlobalError
22
+ def initialize(method, allowed_methods)
23
+ @method = method
24
+ @allowed_methods = allowed_methods
25
+ end
26
+
27
+ def message
28
+ "#{method} method is currently not support. Allowed methods are: #{allowed_methods.join(', ')}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class AutoTopup < Base
4
+ OBJECT = 'auto-topup'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get,
8
+ :delete
9
+ ].freeze
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,98 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class Base
4
+ attr_reader :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def find(id)
11
+ get(id)
12
+ end
13
+
14
+ def all(params = {})
15
+ get(nil, params)
16
+ end
17
+
18
+ def create(params = {})
19
+ post(params)
20
+ end
21
+
22
+ def update(id, params = {})
23
+ patch(id, params)
24
+ end
25
+
26
+ def get(id, params = {})
27
+ if method_supported?(:get)
28
+ url, action = build_url(child_path: object_name, child_id: id)
29
+ Request.get(@client, url, action, params)
30
+ else
31
+ raise SmsGlobal::NoSupportedMethod.new(:get, object_methods)
32
+ end
33
+ end
34
+
35
+ def post(params = {})
36
+ if method_supported?(:post)
37
+ url, action = build_url(child_path: object_name)
38
+ Request.post(@client, url, action, params)
39
+ else
40
+ raise SmsGlobal::NoSupportedMethod.new(:post, object_methods)
41
+ end
42
+ end
43
+
44
+ def patch(id, params = {})
45
+ if method_supported?(:patch)
46
+ url, action = build_url(child_path: object_name, child_id: id)
47
+ Request.patch(@client, url, action, params)
48
+ else
49
+ raise SmsGlobal::NoSupportedMethod.new(:patch, object_methods)
50
+ end
51
+ end
52
+
53
+ def delete(id)
54
+ if method_supported?(:delete)
55
+ url, action = build_url(child_path: object_name, child_id: id)
56
+ Request.delete(@client, url, action)
57
+ else
58
+ raise SmsGlobal::NoSupportedMethod.new(:delete, object_methods)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def object_name
65
+ self.class.const_get(:OBJECT)
66
+ end
67
+
68
+ def object_methods
69
+ self.class.const_get(:OBJECT_METHODS)
70
+ end
71
+
72
+ def method_supported?(method)
73
+ return true if object_methods.include?(method)
74
+ return false
75
+ end
76
+
77
+ def build_url(child_path: '', child_id: '')
78
+ url = url_builder(child_path, child_id)
79
+ action = action_builder(child_path, child_id)
80
+ return url, action
81
+ end
82
+
83
+ def url_builder(child_path = '', child_id = '')
84
+ url = "#{@client.url}/#{client.api_version}"
85
+ url += "/#{child_path}" if !child_path.to_s.blank?
86
+ url += "/#{child_id}" if !child_id.to_s.blank?
87
+ return url
88
+ end
89
+
90
+ def action_builder(child_path = '', child_id = '')
91
+ action = "/#{client.api_version}"
92
+ action += "/#{child_path}" if !child_path.to_s.blank?
93
+ action += "/#{child_id}" if !child_id.to_s.blank?
94
+ return action
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,13 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class Contact < Base
4
+ OBJECT = 'contact'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get,
8
+ :patch,
9
+ :delete
10
+ ].freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class DedicatedNumber < Base
4
+ OBJECT = 'dedicated-number'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get
8
+ ].freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class Group < Base
4
+ OBJECT = 'group'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get,
8
+ :post,
9
+ :delete,
10
+ :patch
11
+ ].freeze
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module SmsGlobal
2
+ module Object
3
+ module Helper
4
+ def object(object_name, *params)
5
+ define_method(object_name) do |argument=nil|
6
+ object = "@#{object_name}_cache".to_sym
7
+ if !instance_variable_defined?(object)
8
+ instance_variable_set(object, SmsGlobal::Object.const_get("#{object_name.to_s.to_camel_case(true)}".to_sym).new(self))
9
+ end
10
+ instance_variable_get(object)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,83 @@
1
+ require 'net/http'
2
+ require 'digest'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module SmsGlobal
7
+ module Object
8
+ class Request
9
+
10
+ def self.get(client, url, action, params)
11
+ request(:get, client, url, action, params)
12
+ end
13
+
14
+ def self.post(client, url, action, params)
15
+ request(:post, client, url, action, params)
16
+ end
17
+
18
+ def self.patch(client, url, action, params)
19
+ request(:patch, client, url, action, params)
20
+ end
21
+
22
+ def self.delete(client, url, action)
23
+ request(:delete, client, url, action)
24
+ end
25
+
26
+ private
27
+
28
+ def self.request(method, client, url, action, params = {})
29
+ send do
30
+ uri = URI("https://#{url}")
31
+ https = Net::HTTP.new(uri.host, uri.port);
32
+ https.use_ssl = true
33
+ request = Object.const_get("Net::HTTP::#{method.to_s.capitalize}").new(uri)
34
+ request['Content-Type'] = 'application/json'
35
+ request['Accept'] = 'application/json'
36
+ request['Authorization'] = build_authorization(client, method, action)
37
+ request.body = convert(params) if method == :post || method == :patch
38
+
39
+ https.request(request)
40
+ end
41
+ end
42
+
43
+ # https://www.smsglobal.com/rest-api/#authentication
44
+ def self.build_authorization(client, method, action)
45
+ timestamp = Time.now.to_i
46
+ nonce = Digest::MD5.hexdigest((rand(36**7...36**8).to_s(36)))
47
+ raw = "#{timestamp}\n#{nonce}\n#{method.to_s.upcase}\n#{action}\n#{client.url}\n443\n\n"
48
+
49
+ sha_digest = OpenSSL::Digest.new("sha256")
50
+ hash = OpenSSL::HMAC.digest(sha_digest, client.secret, raw)
51
+ hash = Base64::strict_encode64(hash);
52
+
53
+ return "MAC id=\"%s\",ts=\"%s\",nonce=\"%s\",mac=\"%s\"" % [client.key, timestamp, nonce, hash]
54
+ end
55
+
56
+ def self.convert(request = {})
57
+ result = {}
58
+ request.each do |key, value|
59
+ result[key.to_s.to_camel_case] = value
60
+ end
61
+
62
+ return result.to_json
63
+ end
64
+
65
+ def self.send
66
+ begin
67
+ request = yield
68
+ response = Response.new(request.read_body.to_s).results
69
+
70
+ if Response.success?(request.code.to_i)
71
+ return response
72
+ elsif Response.deleted?(request.code.to_i)
73
+ return true
74
+ elsif Response.unauthorized?(request.code.to_i)
75
+ raise UnauthorizedException.new
76
+ else
77
+ raise ApiException.new("#{request.code} - API call failed")
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,62 @@
1
+ require 'json'
2
+
3
+ module SmsGlobal
4
+ module Object
5
+ class Response
6
+ attr_reader :results
7
+
8
+ def initialize(response)
9
+ @results = nil
10
+ if !response.blank?
11
+ @response = JSON.parse(response, symbolize_names: true)
12
+ if @response.has_key?(:value)
13
+ @response = @response[:value]
14
+ end
15
+ process
16
+ end
17
+ end
18
+
19
+ def self.success?(status)
20
+ status == 200 || status == 201
21
+ end
22
+
23
+ def self.deleted?(status)
24
+ status == 204
25
+ end
26
+
27
+ def self.unauthorized?(status)
28
+ status == 401
29
+ end
30
+
31
+ private
32
+
33
+ def process
34
+ if @response.is_a?(Array)
35
+ @results = []
36
+ @response.each do |data|
37
+ @results << convert(data)
38
+ end
39
+ elsif @response.is_a?(Hash)
40
+ @results = convert(@response)
41
+ end
42
+ end
43
+
44
+ def convert(data)
45
+ result = {}
46
+ data.each do |key, value|
47
+ if value.is_a?(Hash)
48
+ result[convert_to_snake_case_symbol(key)] = convert(value)
49
+ else
50
+ result[convert_to_snake_case_symbol(key)] = value
51
+ end
52
+ end
53
+
54
+ return result
55
+ end
56
+
57
+ def convert_to_snake_case_symbol(value)
58
+ value.to_s.to_snake_case.to_sym
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class SharedPool < Base
4
+ OBJECT = 'sharedpool'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get
8
+ ].freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class Sms < Base
4
+ OBJECT = 'sms'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get,
8
+ :post,
9
+ :delete
10
+ ].freeze
11
+
12
+ def send(params = {})
13
+ post(params)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module SmsGlobal
2
+ module Object
3
+ class SmsIncoming < Base
4
+ OBJECT = 'sms-incoming'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get,
8
+ :delete
9
+ ].freeze
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module SmsGlobal
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/auto_topup_test.rb
3
+
4
+ class SmsGlobal::Object::AutoTopupTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_all
13
+ stub_request(:get, /auto-topup/)
14
+ .to_return(
15
+ status: 200,
16
+ body: {
17
+ disabled: false,
18
+ balanceThreshold: 10,
19
+ balanceAmount: 100
20
+ }.to_json
21
+ )
22
+
23
+ response = @client.auto_topup.all
24
+ assert_equal response[:balance_threshold], 10
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/contact_test.rb
3
+
4
+ class SmsGlobal::Object::ContactTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_find
13
+ test_id = 1
14
+
15
+ stub_request(:get, /contact\/(#{test_id})/)
16
+ .to_return(
17
+ status: 200,
18
+ body: {
19
+ givenName: 'Jarrad',
20
+ familyName: 'Muir',
21
+ displayName: 'Jarrad Muir',
22
+ msisdn: '0411111111',
23
+ emailAddress: 'email@email.com'
24
+ }.to_json
25
+ )
26
+
27
+ response = @client.contact.find(test_id)
28
+ assert_equal response[:given_name], 'Jarrad'
29
+ end
30
+
31
+ def test_update
32
+ test_id = 1
33
+
34
+ stub_request(:patch, /contact\/(#{test_id})/)
35
+ .to_return(
36
+ status: 200,
37
+ body: {
38
+ givenName: 'Jrad',
39
+ familyName: 'Muir',
40
+ displayName: 'Jarrad Muir',
41
+ msisdn: '0411111111',
42
+ emailAddress: 'email@email.com'
43
+ }.to_json
44
+ )
45
+
46
+ response = @client.contact.update(test_id, {
47
+ given_name: 'Jrad'
48
+ })
49
+ assert_equal response[:given_name], 'Jrad'
50
+ end
51
+
52
+ def test_delete
53
+ test_id = 3
54
+
55
+ stub_request(:delete, /contact\/(#{test_id})/)
56
+ .to_return(status: 204, body: "")
57
+
58
+ assert @client.contact.delete(test_id)
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/dedicated_number_test.rb
3
+
4
+ class SmsGlobal::Object::DedicatedNumberTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_all
13
+ stub_request(:get, /dedicated-number/)
14
+ .to_return(
15
+ status: 200,
16
+ body: {
17
+ dedicatedNumbers: [
18
+ {
19
+ id: 1,
20
+ userId: 1
21
+ }
22
+ ]
23
+ }.to_json
24
+ )
25
+
26
+
27
+ response = @client.dedicated_number.all
28
+ assert_equal response[:dedicated_numbers].first[:id], 1
29
+ end
30
+ end
@@ -0,0 +1,95 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/group_test.rb
3
+
4
+ class SmsGlobal::Object::GroupTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_all
13
+ stub_request(:get, /group/)
14
+ .to_return(
15
+ status: 200,
16
+ body: {
17
+ groups: [
18
+ {
19
+ id: 1,
20
+ name: 'group 1',
21
+ keyword: 'test',
22
+ isGlobal: false,
23
+ contactCount: 1,
24
+ defaultOrigin: '0411111111'
25
+ }
26
+ ]
27
+ }.to_json
28
+ )
29
+
30
+ response = @client.group.all
31
+ assert_equal response[:groups].first[:id], 1
32
+ end
33
+
34
+ def test_find
35
+ test_id = 2
36
+ stub_request(:get, /group\/#{test_id}/)
37
+ .to_return(
38
+ status: 200,
39
+ body: {
40
+ id: test_id,
41
+ name: 'group 2',
42
+ keyword: 'test',
43
+ isGlobal: false,
44
+ contactCount: 1,
45
+ defaultOrigin: '0411111111'
46
+ }.to_json
47
+ )
48
+
49
+ response = @client.group.find(test_id)
50
+ assert_equal response[:name], 'group 2'
51
+ end
52
+
53
+ def test_create
54
+ stub_request(:post, /group/)
55
+ .to_return(
56
+ status: 200,
57
+ body: {
58
+ name: 'group 3',
59
+ keyword: 'test',
60
+ isGlobal: false,
61
+ defaultOrigin: '0422222222'
62
+ }.to_json
63
+ )
64
+
65
+ response = @client.group.create({
66
+ name: 'group 3',
67
+ keyword: 'test',
68
+ isGlobal: false,
69
+ defaultOrigin: '0422222222'
70
+ })
71
+ assert_equal response[:name], 'group 3'
72
+ end
73
+
74
+ def test_update
75
+ test_id = 3
76
+ stub_request(:patch, /group/)
77
+ .to_return(
78
+ status: 200,
79
+ body: {
80
+ name: 'group 4',
81
+ keyword: 'test',
82
+ isGlobal: false,
83
+ defaultOrigin: '0422222222'
84
+ }.to_json
85
+ )
86
+
87
+ response = @client.group.update(test_id, {
88
+ name: 'group 4',
89
+ keyword: 'testing',
90
+ isGlobal: true,
91
+ defaultOrigin: '0433333333'
92
+ })
93
+ assert_equal response[:name], 'group 4'
94
+ end
95
+ end
@@ -0,0 +1,49 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/shared_pool_test.rb
3
+
4
+ class SmsGlobal::Object::SharedPoolTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_find
13
+ test_id = 1
14
+
15
+ stub_request(:get, /sharedpool\/(#{test_id})/)
16
+ .to_return(
17
+ status: 200,
18
+ body: {
19
+ id: test_id,
20
+ name: 'name 1',
21
+ size: 1,
22
+ numbers: ['041111111']
23
+ }.to_json
24
+ )
25
+
26
+ response = @client.shared_pool.find(test_id)
27
+ assert_equal response[:id], test_id
28
+ end
29
+
30
+ def test_all
31
+ stub_request(:get, /sharedpool/)
32
+ .to_return(
33
+ status: 200,
34
+ body: {
35
+ SharedPools: [
36
+ {
37
+ id: 2,
38
+ name: 'name 2',
39
+ size: 1,
40
+ numbers: ['041111111']
41
+ }
42
+ ]
43
+ }.to_json
44
+ )
45
+
46
+ response = @client.shared_pool.all
47
+ assert_equal response[:shared_pools].first[:id], 2
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/sms_incoming_test.rb
3
+
4
+ class SmsGlobal::Object::SmsIncomingTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_find
13
+ test_id = 1
14
+
15
+ stub_request(:get, /sms-incoming\/(#{test_id})/)
16
+ .to_return(
17
+ status: 200,
18
+ body: {
19
+ id: test_id,
20
+ origin: '123',
21
+ destination: '123',
22
+ message: 'hello world',
23
+ status: 'delivered',
24
+ dateTime: ''
25
+ }.to_json
26
+ )
27
+
28
+ response = @client.sms_incoming.find(test_id)
29
+ assert_equal response[:id], test_id
30
+ end
31
+
32
+ def test_all
33
+ stub_request(:get, /sms-incoming/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ messages: [
38
+ {
39
+ id: 2,
40
+ origin: '123',
41
+ destination: '123',
42
+ message: 'hello world',
43
+ status: 'delivered',
44
+ dateTime: ''
45
+ }
46
+ ]
47
+ }.to_json
48
+ )
49
+
50
+
51
+ response = @client.sms_incoming.all
52
+ assert_equal response[:messages].first[:id], 2
53
+ end
54
+
55
+ def test_delete
56
+ test_id = 3
57
+
58
+ stub_request(:delete, /sms-incoming\/(#{test_id})/)
59
+ .to_return(status: 204, body: "")
60
+
61
+ assert @client.sms_incoming.delete(test_id)
62
+ end
63
+ end
@@ -0,0 +1,92 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/sms_global/object/sms_test.rb
3
+
4
+ class SmsGlobal::Object::SmsTest < MiniTest::Test
5
+ def setup
6
+ @client = SmsGlobal::Client.new(
7
+ key: '123fake',
8
+ secret: '123fake'
9
+ )
10
+ end
11
+
12
+ def test_find
13
+ test_id = 1
14
+
15
+ stub_request(:get, /sms\/(#{test_id})/)
16
+ .to_return(
17
+ status: 200,
18
+ body: {
19
+ id: test_id,
20
+ outgoing_id: test_id,
21
+ origin: '123',
22
+ destination: '123',
23
+ message: 'hello world',
24
+ status: 'delivered',
25
+ dateTime: ''
26
+ }.to_json
27
+ )
28
+
29
+ response = @client.sms.find(test_id)
30
+ assert_equal response[:id], test_id
31
+ end
32
+
33
+ def test_all
34
+ stub_request(:get, /sms/)
35
+ .to_return(
36
+ status: 200,
37
+ body: {
38
+ messages: [
39
+ {
40
+ id: 2,
41
+ outgoing_id: 2,
42
+ origin: '123',
43
+ destination: '123',
44
+ message: 'hello world',
45
+ status: 'delivered',
46
+ dateTime: ''
47
+ }
48
+ ]
49
+ }.to_json
50
+ )
51
+
52
+
53
+ response = @client.sms.all
54
+ assert_equal response[:messages].first[:id], 2
55
+ end
56
+
57
+ def test_send
58
+ stub_request(:post, /sms/)
59
+ .to_return(
60
+ status: 200,
61
+ body: {
62
+ messages: [
63
+ {
64
+ id: 2,
65
+ outgoing_id: 2,
66
+ origin: '123',
67
+ destination: '123',
68
+ message: 'hello world',
69
+ status: 'delivered',
70
+ dateTime: ''
71
+ }
72
+ ]
73
+ }.to_json
74
+ )
75
+
76
+ response = @client.sms.send({
77
+ origin: '123',
78
+ destination: '123',
79
+ message: 'hello'
80
+ })
81
+ assert_equal response[:messages].first[:id], 2
82
+ end
83
+
84
+ def test_delete
85
+ test_id = 3
86
+
87
+ stub_request(:delete, /sms\/(#{test_id})/)
88
+ .to_return(status: 204, body: "")
89
+
90
+ assert @client.sms.delete(test_id)
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class SmsGlobalTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil SmsGlobal::VERSION
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
2
+ require "sms_global"
3
+
4
+ require "minitest/autorun"
5
+ require "minitest/pride"
6
+
7
+ require "byebug"
8
+ require 'webmock/minitest'
9
+
10
+ WebMock.disable_net_connect!(allow_localhost: true)
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms-global
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jarrad Muir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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.7'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.7.6
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.7'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.7.6
75
+ - !ruby/object:Gem::Dependency
76
+ name: byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '11.0'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 11.0.0
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '11.0'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 11.0.0
95
+ description:
96
+ email:
97
+ - jarrads@live.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - LICENSE.txt
103
+ - README.md
104
+ - lib/core_ext/string.rb
105
+ - lib/sms_global.rb
106
+ - lib/sms_global/client.rb
107
+ - lib/sms_global/exceptions.rb
108
+ - lib/sms_global/object/auto_topup.rb
109
+ - lib/sms_global/object/base.rb
110
+ - lib/sms_global/object/contact.rb
111
+ - lib/sms_global/object/dedicated_number.rb
112
+ - lib/sms_global/object/group.rb
113
+ - lib/sms_global/object/helper.rb
114
+ - lib/sms_global/object/request.rb
115
+ - lib/sms_global/object/response.rb
116
+ - lib/sms_global/object/shared_pool.rb
117
+ - lib/sms_global/object/sms.rb
118
+ - lib/sms_global/object/sms_incoming.rb
119
+ - lib/sms_global/version.rb
120
+ - test/sms_global/object/auto_topup_test.rb
121
+ - test/sms_global/object/contact_test.rb
122
+ - test/sms_global/object/dedicated_number_test.rb
123
+ - test/sms_global/object/group_test.rb
124
+ - test/sms_global/object/shared_pool_test.rb
125
+ - test/sms_global/object/sms_incoming_test.rb
126
+ - test/sms_global/object/sms_test.rb
127
+ - test/sms_global/sms_global_test.rb
128
+ - test/test_helper.rb
129
+ homepage: https://github.com/JDrizzy/sms-global
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ source_code_uri: https://github.com/JDrizzy/sms-global
134
+ changelog_uri: https://github.com/JDrizzy/sms-global/releases
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.7.6
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Ruby library for SMS Global
155
+ test_files:
156
+ - test/sms_global/object/auto_topup_test.rb
157
+ - test/sms_global/object/contact_test.rb
158
+ - test/sms_global/object/dedicated_number_test.rb
159
+ - test/sms_global/object/group_test.rb
160
+ - test/sms_global/object/shared_pool_test.rb
161
+ - test/sms_global/object/sms_incoming_test.rb
162
+ - test/sms_global/object/sms_test.rb
163
+ - test/sms_global/sms_global_test.rb
164
+ - test/test_helper.rb