bulkgate_sms_gateway_contract 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d234843a7e2920641e7d2d0eb78f0df29c256cffd403cf2f5a0658de93ccf8e
4
+ data.tar.gz: f48ef6cb4deeb699e01600fd8522a2c6aaf4772d48508e396207369df708584c
5
+ SHA512:
6
+ metadata.gz: f77f1b9d19f9912f7a6bd2780d2e272c6e0ea7c083d83d537daf867f79e7721f06c14697feadbbe6917fd33e5af4e66d340a9c4079a4269a211dd56da3077a90
7
+ data.tar.gz: 052b88955914497aa362ae418a55cafb874bcfdc64ee6046e056c8e5081ceb328386b5a90cf74e06710f108bb939185483ee720e97c6e4205899795a940ced71
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at equivalent@eq8.eu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bulkgate_sms_gateway_contract.gemspec
6
+ gemspec
@@ -0,0 +1,151 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bulkgate_sms_gateway_contract (1.0.0)
5
+ httparty
6
+ rails (>= 5.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.0.2.1)
12
+ actionpack (= 6.0.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.0.2.1)
16
+ actionpack (= 6.0.2.1)
17
+ activejob (= 6.0.2.1)
18
+ activerecord (= 6.0.2.1)
19
+ activestorage (= 6.0.2.1)
20
+ activesupport (= 6.0.2.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.2.1)
23
+ actionpack (= 6.0.2.1)
24
+ actionview (= 6.0.2.1)
25
+ activejob (= 6.0.2.1)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.0.2.1)
29
+ actionview (= 6.0.2.1)
30
+ activesupport (= 6.0.2.1)
31
+ rack (~> 2.0, >= 2.0.8)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.2.1)
36
+ actionpack (= 6.0.2.1)
37
+ activerecord (= 6.0.2.1)
38
+ activestorage (= 6.0.2.1)
39
+ activesupport (= 6.0.2.1)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.2.1)
42
+ activesupport (= 6.0.2.1)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.2.1)
48
+ activesupport (= 6.0.2.1)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.0.2.1)
51
+ activesupport (= 6.0.2.1)
52
+ activerecord (6.0.2.1)
53
+ activemodel (= 6.0.2.1)
54
+ activesupport (= 6.0.2.1)
55
+ activestorage (6.0.2.1)
56
+ actionpack (= 6.0.2.1)
57
+ activejob (= 6.0.2.1)
58
+ activerecord (= 6.0.2.1)
59
+ marcel (~> 0.3.1)
60
+ activesupport (6.0.2.1)
61
+ concurrent-ruby (~> 1.0, >= 1.0.2)
62
+ i18n (>= 0.7, < 2)
63
+ minitest (~> 5.1)
64
+ tzinfo (~> 1.1)
65
+ zeitwerk (~> 2.2)
66
+ builder (3.2.4)
67
+ concurrent-ruby (1.1.5)
68
+ crass (1.0.5)
69
+ erubi (1.9.0)
70
+ globalid (0.4.2)
71
+ activesupport (>= 4.2.0)
72
+ httparty (0.17.3)
73
+ mime-types (~> 3.0)
74
+ multi_xml (>= 0.5.2)
75
+ i18n (1.7.0)
76
+ concurrent-ruby (~> 1.0)
77
+ loofah (2.4.0)
78
+ crass (~> 1.0.2)
79
+ nokogiri (>= 1.5.9)
80
+ mail (2.7.1)
81
+ mini_mime (>= 0.1.1)
82
+ marcel (0.3.3)
83
+ mimemagic (~> 0.3.2)
84
+ method_source (0.9.2)
85
+ mime-types (3.3)
86
+ mime-types-data (~> 3.2015)
87
+ mime-types-data (3.2019.1009)
88
+ mimemagic (0.3.3)
89
+ mini_mime (1.0.2)
90
+ mini_portile2 (2.4.0)
91
+ minitest (5.13.0)
92
+ multi_xml (0.6.0)
93
+ nio4r (2.5.2)
94
+ nokogiri (1.10.7)
95
+ mini_portile2 (~> 2.4.0)
96
+ rack (2.0.8)
97
+ rack-test (1.1.0)
98
+ rack (>= 1.0, < 3)
99
+ rails (6.0.2.1)
100
+ actioncable (= 6.0.2.1)
101
+ actionmailbox (= 6.0.2.1)
102
+ actionmailer (= 6.0.2.1)
103
+ actionpack (= 6.0.2.1)
104
+ actiontext (= 6.0.2.1)
105
+ actionview (= 6.0.2.1)
106
+ activejob (= 6.0.2.1)
107
+ activemodel (= 6.0.2.1)
108
+ activerecord (= 6.0.2.1)
109
+ activestorage (= 6.0.2.1)
110
+ activesupport (= 6.0.2.1)
111
+ bundler (>= 1.3.0)
112
+ railties (= 6.0.2.1)
113
+ sprockets-rails (>= 2.0.0)
114
+ rails-dom-testing (2.0.3)
115
+ activesupport (>= 4.2.0)
116
+ nokogiri (>= 1.6)
117
+ rails-html-sanitizer (1.3.0)
118
+ loofah (~> 2.3)
119
+ railties (6.0.2.1)
120
+ actionpack (= 6.0.2.1)
121
+ activesupport (= 6.0.2.1)
122
+ method_source
123
+ rake (>= 0.8.7)
124
+ thor (>= 0.20.3, < 2.0)
125
+ rake (10.5.0)
126
+ sprockets (4.0.0)
127
+ concurrent-ruby (~> 1.0)
128
+ rack (> 1, < 3)
129
+ sprockets-rails (3.2.1)
130
+ actionpack (>= 4.0)
131
+ activesupport (>= 4.0)
132
+ sprockets (>= 3.0.0)
133
+ thor (1.0.1)
134
+ thread_safe (0.3.6)
135
+ tzinfo (1.2.5)
136
+ thread_safe (~> 0.1)
137
+ websocket-driver (0.7.1)
138
+ websocket-extensions (>= 0.1.0)
139
+ websocket-extensions (0.1.4)
140
+ zeitwerk (2.2.2)
141
+
142
+ PLATFORMS
143
+ ruby
144
+
145
+ DEPENDENCIES
146
+ bulkgate_sms_gateway_contract!
147
+ bundler
148
+ rake (~> 10.0)
149
+
150
+ BUNDLED WITH
151
+ 2.1.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tomas Valent
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,157 @@
1
+ # BulkgateSmsGatewayContract
2
+
3
+ The following gem is a Gateway Test contract & Production gateway for
4
+ sending SMS texts via service API: https://www.bulkgate.com/
5
+
6
+ Gem is designed for Rails only.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+ ```ruby
12
+ gem 'sms_gateway_contract', github: 'equivalent/sms_gateway_contract'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Usage
20
+
21
+ step 1: Configure Rails environments (individual sections down bellow)
22
+
23
+ step 2: Then just call:
24
+
25
+ ```ruby
26
+ BulkgateSmsGatewayContract.contract.send_sms(country: 'sk', number: 908123123, body: 'whatever')
27
+ # or
28
+ BulkgateSmsGatewayContract.contract.send_sms(country: 'sk', number: 908123123, body: 'whatever', sender_name: "my-website.com")
29
+ ```
30
+
31
+ #### Production
32
+
33
+ This is the real thing that will send SMS via Bulkgate.com API
34
+
35
+ ```ruby
36
+ #config/environments/production.rb
37
+
38
+ Rails.application.configure do
39
+ # ...
40
+ config.x.bulkgate_sms_gateway_contract = 'BulkgateSmsGatewayContract::Real'
41
+ # ...
42
+ end
43
+ ```
44
+
45
+ you also need to configure [Rails credentials](https://blog.eq8.eu/til/rails-52-credentials-tricks.html)
46
+
47
+ ```
48
+ # ...
49
+ bulkgate_sms:
50
+ application_id: yyyy
51
+ application_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
52
+ # ...
53
+ ```
54
+
55
+ > in order to open Rails credentials you can do `EDITOR=vim bundle exec rails credentials:edit`
56
+
57
+ In case of API error exception `BulkgateError` with Bulkgate error type as message.
58
+
59
+ You can capture exception as
60
+
61
+ ```ruby
62
+ begin
63
+ BulkgateSmsGatewayContract::Real.send_sms(country: 'sk', number: 'this-is-wrong', body: '666666 is your Authentication code')
64
+ rescue BulkgateSmsGatewayContract::BulkgateError => e
65
+ puts "rescue any API specific error form Bulkgate"
66
+ end
67
+
68
+ # or
69
+
70
+ begin
71
+ BulkgateSmsGatewayContract::Real.send_sms(country: 'sk', number: 'this-is-wrong', body: '666666 is your Authentication code')
72
+ rescue BulkgateSmsGatewayContract::BulkgateError, 'invalid_phone_number'
73
+ puts "phone number invalid"
74
+ end
75
+
76
+ # or gem also provides custom error classes for most common errors like
77
+
78
+ rescue BulkgateSmsGatewayContract::EmptyMessageBody
79
+ rescue BulkgateSmsGatewayContract::InvalidPhoneNumber
80
+ rescue BulkgateSmsGatewayContract::OutOfCredit
81
+ ```
82
+
83
+ > see https://help.bulkgate.com/docs/en/api-error-types.html#error-types for full list off error types
84
+
85
+ #### Test
86
+
87
+ This is actuall Test contract
88
+
89
+ If you don't know what Test contracts are please read:
90
+ https://blog.eq8.eu/article/explicit-contracts-for-rails-http-api-usecase.html
91
+
92
+
93
+ ```ruby
94
+ #config/environments/test.rb
95
+
96
+ Rails.application.configure do
97
+ # ...
98
+ config.x.bulkgate_sms_gateway_contract = 'BulkgateSmsGatewayContract::Mock'
99
+ # ...
100
+ end
101
+ ```
102
+
103
+ Example RSpec usage:
104
+
105
+ ```ruby
106
+ require 'rails_helper'
107
+ RSpec.describe 'sending of SMS' do
108
+ def trigger
109
+ BulkgateSmsGatewayContract.contract.send_sms(
110
+ country: "sk",
111
+ number: 908111222,
112
+ body: "Your 2FA code is 1234")
113
+ end
114
+
115
+ it do
116
+ expect(trigger).to eq "Bulkgate: Your 2FA code is 1234 TO: sk:908111222"
117
+ end
118
+ end
119
+ ```
120
+
121
+ #### Development
122
+
123
+ Will log SMS codes to `log/sms.log`
124
+
125
+ ```ruby
126
+ #config/environments/development.rb
127
+
128
+ Rails.application.configure do
129
+ # ...
130
+ config.x.bulkgate_sms_gateway_contract = 'BulkgateSmsGatewayContract::FileLog'
131
+ # ...
132
+ end
133
+ ```
134
+
135
+ ### Bonus - Production with Airbrake Debugging
136
+
137
+ If you are using [Airbrake](https://github.com/airbrake/airbrake) you
138
+ can use for production debugging `AirbrakeNotify` contract
139
+
140
+ ```ruby
141
+ # config/environments/production.rb
142
+
143
+
144
+ # This contract is not loaded by default. You need to explicitly require it
145
+ require 'sms_gateway_contract/airbrake_notify'
146
+
147
+ # ...
148
+ config.x.bulkgate_sms_gateway_contract = 'BulkgateSmsGatewayContract::AirbrakeNotify'
149
+ # ...
150
+ ```
151
+
152
+ > `BulkgateSmsGatewayContract::AirbrakeNotify` is only for debugging production. It's more a lazy tool to save cost during develompment. Don't use it once live.
153
+
154
+
155
+ ## Code of Conduct
156
+
157
+ Everyone interacting in the SmsGatewayContract project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/equivalent/sms_gateway_contract/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bulkgate_sms_gateway_contract"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bulkgate_sms_gateway_contract/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bulkgate_sms_gateway_contract"
7
+ spec.version = BulkgateSmsGatewayContract::VERSION
8
+ spec.authors = ["Tomas Valent"]
9
+ spec.email = ["equivalent@eq8.eu"]
10
+
11
+ spec.summary = %q{Contract classes for SMS Gateway provided by Bulkgate}
12
+ spec.description = %q{Contract classes for SMS Gateway (test + production for Bulkgate.com API)}
13
+ spec.homepage = "https://github.com/equivalent/bulkgate_sms_gateway_contract"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "httparty"
26
+ spec.add_dependency 'rails', ">= 5.2" # needed for credentials
27
+
28
+ spec.add_development_dependency "bundler"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ require 'rails'
3
+ require 'httparty'
4
+ require "bulkgate_sms_gateway_contract/version"
5
+ require "bulkgate_sms_gateway_contract/fake_contract_commonalities"
6
+ require "bulkgate_sms_gateway_contract/real"
7
+ require "bulkgate_sms_gateway_contract/mock"
8
+ require "bulkgate_sms_gateway_contract/file_log"
9
+
10
+ module BulkgateSmsGatewayContract
11
+ BulkgateError = Class.new(StandardError)
12
+
13
+ InvalidApplicationIdOrApplicationToken = Class.new(BulkgateError)
14
+ InvalidPhoneNumber = Class.new(BulkgateError)
15
+ EmptyMessageBody = Class.new(BulkgateError)
16
+ OutOfCredit = Class.new(BulkgateError)
17
+
18
+ def self.contract
19
+ Rails.application.config.x.bulkgate_sms_gateway_contract.constantize
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module BulkgateSmsGatewayContract
2
+ module AirbrakeNotify
3
+ def self.send_sms(number:, country:, body:, sender_name: nil)
4
+ BulkgateSmsGatewayContract::FakeContractCommonalities
5
+ .raise_when_invalid(country: country, body: body, number: number)
6
+
7
+ msg = "BulkgateSmsGatewayContract: login_code #{code} for #{country} #{number}"
8
+ msg += " | SENDER #{sender_name}" if sender_name
9
+ Airbrake.notify(msg)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module BulkgateSmsGatewayContract
2
+ module FakeContractCommonalities
3
+ def self.raise_when_invalid(country:, body:, number:)
4
+ raise BulkgateSmsGatewayContract::InvalidPhoneNumber, 'invalid_phone_number' if number == 'invalid_phone_number'
5
+ raise BulkgateSmsGatewayContract::InvalidPhoneNumber, 'invalid_phone_number' if country == 'invalid_phone_number'
6
+ raise BulkgateSmsGatewayContract::OutOfCredit, 'low_credit' if number == 'low_credit'
7
+ raise BulkgateSmsGatewayContract::EmptyMessageBody, 'empty_message' if body.blank?
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module BulkgateSmsGatewayContract
2
+ module FileLog
3
+ def self.send_sms(number:, country:, body:, sender_name: nil)
4
+ BulkgateSmsGatewayContract::FakeContractCommonalities
5
+ .raise_when_invalid(country: country, body: body, number: number)
6
+
7
+ msg = "BULKGATE: #{country}:#{number} - #{body}"
8
+ msg += " | SENDER:#{sender_name}"
9
+ _logger.info(msg)
10
+ end
11
+
12
+ def self._logger
13
+ @_logger ||= Logger.new(Rails.root.join('log', 'sms.log'))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module BulkgateSmsGatewayContract
2
+ module Mock
3
+ def self.send_sms(number:, body:, country:, sender_name: nil)
4
+ BulkgateSmsGatewayContract::FakeContractCommonalities
5
+ .raise_when_invalid(country: country, body: body, number: number)
6
+
7
+ msg = "BULKGATE: #{body} TO: '#{country}:#{number}'"
8
+ msg += " SENDER: #{sender_name}" if sender_name
9
+ msg
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module BulkgateSmsGatewayContract
2
+ module Real
3
+ # based on https://help.bulkgate.com/docs/en/http-simple-transactional.html#sender-id-type-sender_id
4
+ def self.send_sms(number:, country:, body:, sender_name: nil)
5
+ body = {
6
+ "application_id": Rails.application.credentials.dig(:bulkgate_sms, :application_id),
7
+ "application_token": Rails.application.credentials.dig(:bulkgate_sms, :application_token),
8
+ "number": number,
9
+ "text": body,
10
+ "country": country,
11
+ }
12
+
13
+ if sender_name # eg 'mycompany.com'
14
+ body.merge!({
15
+ 'sender_id' => 'gText',
16
+ 'sender_id_value' => sender_name
17
+ })
18
+ end
19
+
20
+ resp = HTTParty.post('https://portal.bulkgate.com/api/1.0/simple/transactional', body: body)
21
+ case resp.code
22
+ when 401
23
+ raise BulkgateSmsGatewayContract::InvalidApplicationIdOrApplicationToken
24
+ when 400
25
+ resp_body_hash = JSON.parse(resp.body)
26
+ error_type = resp_body_hash['type']
27
+ case error_type
28
+ when 'invalid_phone_number'
29
+ raise BulkgateSmsGatewayContract::InvalidPhoneNumber, error_type
30
+ when 'empty_message'
31
+ raise BulkgateSmsGatewayContract::EmptyMessageBody, error_type
32
+ when 'low_credit'
33
+ raise BulkgateSmsGatewayContract::OutOfCredit, error_type
34
+ else
35
+ # for more deatils see https://help.bulkgate.com/docs/en/api-error-types.html#error-types
36
+ raise BulkgateSmsGatewayContract::BulkgateError, error_type
37
+ end
38
+ when 200
39
+ resp_body_hash
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module BulkgateSmsGatewayContract
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulkgate_sms_gateway_contract
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Valent
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Contract classes for SMS Gateway (test + production for Bulkgate.com
70
+ API)
71
+ email:
72
+ - equivalent@eq8.eu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - bulkgate_sms_gateway_contract.gemspec
87
+ - lib/bulkgate_sms_gateway_contract.rb
88
+ - lib/bulkgate_sms_gateway_contract/airbrake_notify.rb
89
+ - lib/bulkgate_sms_gateway_contract/fake_contract_commonalities.rb
90
+ - lib/bulkgate_sms_gateway_contract/file_log.rb
91
+ - lib/bulkgate_sms_gateway_contract/mock.rb
92
+ - lib/bulkgate_sms_gateway_contract/real.rb
93
+ - lib/bulkgate_sms_gateway_contract/version.rb
94
+ homepage: https://github.com/equivalent/bulkgate_sms_gateway_contract
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Contract classes for SMS Gateway provided by Bulkgate
117
+ test_files: []