glabssms 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gempush.yml +44 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/glabssms.gemspec +45 -0
- data/lib/glabssms/base_module.rb +13 -0
- data/lib/glabssms/client.rb +61 -0
- data/lib/glabssms/configuration.rb +74 -0
- data/lib/glabssms/error_result.rb +13 -0
- data/lib/glabssms/exceptions.rb +5 -0
- data/lib/glabssms/sms_result.rb +27 -0
- data/lib/glabssms/token_result.rb +23 -0
- data/lib/glabssms/version.rb +3 -0
- data/lib/glabssms.rb +24 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a93476437a9b7f401f001c8b6bd60c81bdc2965d982e0f2efbe873a99711d61f
|
4
|
+
data.tar.gz: cb8c86099e5a0f695a405f3b8d6c6bff132caa6646dc129b3a2c19fc4937edda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5beed2b95b1aca430c4425c9ac5f4d4bd2e5bd14e4ca6834b5ba0a2474743f6abb7f7f10b4b3992008b2192b2dd9636e05d080170d5f23f07e9b026038bf89b
|
7
|
+
data.tar.gz: dfcfbe0b02f9f82b39e2e8515bf3d2fa8bd9c09d097afd7a5f5ccef8d567a2eae33b0884cfd18eefeaf7a7fe0ed623d7ed5c8a6a5a2046a5608ad1b5e3565ecd
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@master
|
18
|
+
- name: Set up Ruby 2.6
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to GPR
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
+
env:
|
32
|
+
GEM_HOST_API_KEY: ${{secrets.GITHUB_TOKEN}}
|
33
|
+
OWNER: makisu
|
34
|
+
|
35
|
+
- name: Publish to RubyGems
|
36
|
+
run: |
|
37
|
+
mkdir -p $HOME/.gem
|
38
|
+
touch $HOME/.gem/credentials
|
39
|
+
chmod 0600 $HOME/.gem/credentials
|
40
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
41
|
+
gem build *.gemspec
|
42
|
+
gem push *.gem
|
43
|
+
env:
|
44
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic
|
6
|
+
Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
### Added
|
10
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 xlablaza@gmail.com. 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
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
glabssms (0.1.0)
|
5
|
+
activesupport
|
6
|
+
gem_config
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2)
|
17
|
+
addressable (2.7.0)
|
18
|
+
public_suffix (>= 2.0.2, < 5.0)
|
19
|
+
byebug (11.0.1)
|
20
|
+
coderay (1.1.2)
|
21
|
+
concurrent-ruby (1.1.5)
|
22
|
+
crack (0.4.3)
|
23
|
+
safe_yaml (~> 1.0.0)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
gem_config (0.3.1)
|
26
|
+
hashdiff (1.0.0)
|
27
|
+
i18n (1.7.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
method_source (0.9.2)
|
30
|
+
minitest (5.13.0)
|
31
|
+
pry (0.12.2)
|
32
|
+
coderay (~> 1.1.0)
|
33
|
+
method_source (~> 0.9.0)
|
34
|
+
pry-byebug (3.7.0)
|
35
|
+
byebug (~> 11.0)
|
36
|
+
pry (~> 0.10)
|
37
|
+
public_suffix (4.0.1)
|
38
|
+
rake (10.5.0)
|
39
|
+
rspec (3.7.0)
|
40
|
+
rspec-core (~> 3.7.0)
|
41
|
+
rspec-expectations (~> 3.7.0)
|
42
|
+
rspec-mocks (~> 3.7.0)
|
43
|
+
rspec-core (3.7.1)
|
44
|
+
rspec-support (~> 3.7.0)
|
45
|
+
rspec-expectations (3.7.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.7.0)
|
48
|
+
rspec-mocks (3.7.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.7.0)
|
51
|
+
rspec-support (3.7.1)
|
52
|
+
safe_yaml (1.0.5)
|
53
|
+
thread_safe (0.3.6)
|
54
|
+
tzinfo (1.2.5)
|
55
|
+
thread_safe (~> 0.1)
|
56
|
+
vcr (5.0.0)
|
57
|
+
webmock (3.7.6)
|
58
|
+
addressable (>= 2.3.6)
|
59
|
+
crack (>= 0.3.2)
|
60
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
61
|
+
zeitwerk (2.2.1)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
bundler (~> 2.0)
|
68
|
+
glabssms!
|
69
|
+
pry-byebug
|
70
|
+
rake (~> 10.0)
|
71
|
+
rspec (~> 3.0)
|
72
|
+
vcr
|
73
|
+
webmock
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Xavi Ablaza
|
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,118 @@
|
|
1
|
+
# Globe Labs SMS Ruby Library
|
2
|
+
|
3
|
+
Send SMS using [Globe Labs](http://www.globelabs.com.ph/developer/api) in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'glabssms'
|
11
|
+
```
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem install glabssms
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
In an initializer:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Glabssms.configure do |c|
|
25
|
+
c.app_id = 'GLABS_APP_ID'
|
26
|
+
c.app_secret = 'GLABS_APP_SECRET'
|
27
|
+
c.cross_telco_short_code = 'GLABS_CROSS_TELCO_SHORT_CODE'
|
28
|
+
c.short_code = 'GLABS_SHORT_CODE'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Initializing a Client
|
33
|
+
|
34
|
+
This is the instance that you will be interacting with to send SMS.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# This client grabs defaults from config
|
38
|
+
client = Glabssms::Client.new(Glabssms::Configuration.new)
|
39
|
+
|
40
|
+
# Only to override the defaults that were set in config
|
41
|
+
client = Glabssms::Client.new(
|
42
|
+
app_id: "...",
|
43
|
+
app_secret: "...",
|
44
|
+
cross_telco_short_code: "...",
|
45
|
+
short_code: "..."
|
46
|
+
)
|
47
|
+
```
|
48
|
+
|
49
|
+
## Fetching Access Token after Subscriber Opt-In
|
50
|
+
|
51
|
+
You need to have the user go through the Subscriber Consent Workflow. They can
|
52
|
+
either [Opt-In via
|
53
|
+
SMS](http://www.globelabs.com.ph/docs/#getting-started-opt-in-via-sms) or
|
54
|
+
[Opt-In via
|
55
|
+
Webform](http://www.globelabs.com.ph/docs/#getting-started-opt-in-via-webform).
|
56
|
+
Globe Labs will then post the `code` to your Redirect URL. You can then use the
|
57
|
+
`code` you receive below.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
result = client.get_token(
|
61
|
+
code: code_from_opt_in
|
62
|
+
)
|
63
|
+
|
64
|
+
# result will be an instance of TokenResult
|
65
|
+
result.success?
|
66
|
+
=> true
|
67
|
+
token_from_subscriber_opt_in = result.access_token
|
68
|
+
subscriber_number = result.subscriber_number
|
69
|
+
```
|
70
|
+
|
71
|
+
## Sending SMS
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
result = client.send_sms(
|
75
|
+
number: subscriber_number, # Can be in the form +639171234567 or 09171234567 or 9171234567
|
76
|
+
message: 'max_160_character_string',
|
77
|
+
token: token_from_subscriber_opt_in
|
78
|
+
)
|
79
|
+
|
80
|
+
result.success?
|
81
|
+
=> true
|
82
|
+
result.message
|
83
|
+
=> 'max_160_character_string'
|
84
|
+
result.number
|
85
|
+
=> '9171234567'
|
86
|
+
result.sender_address
|
87
|
+
=> '0000'
|
88
|
+
```
|
89
|
+
|
90
|
+
## Running the test suite
|
91
|
+
|
92
|
+
1. Install the latest Ruby
|
93
|
+
|
94
|
+
2. Copy `config.yml.sample` to `config.yml` then run:
|
95
|
+
```
|
96
|
+
bundle exec rspec spec
|
97
|
+
```
|
98
|
+
|
99
|
+
3. You can replace values in `config.yml` with values from your Globe Labs API
|
100
|
+
dashboard
|
101
|
+
|
102
|
+
## Development
|
103
|
+
|
104
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
105
|
+
|
106
|
+
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).
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/makisu/glabssms_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
115
|
+
|
116
|
+
## Code of Conduct
|
117
|
+
|
118
|
+
Everyone interacting in the Glabssms project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/makisu/glabssms_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "glabssms"
|
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__)
|
data/bin/setup
ADDED
data/glabssms.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "glabssms/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "glabssms"
|
8
|
+
spec.version = Glabssms::VERSION
|
9
|
+
spec.authors = ["Xavi Ablaza"]
|
10
|
+
spec.email = ["xlablaza@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Send SMS using Globe Labs in Ruby}
|
13
|
+
spec.homepage = "https://github.com/makisu/glabssms_ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/makisu/glabssms_ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/makisu/glabssms_ruby/blob/master/CHANGELOG.md"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
"public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
end
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_dependency "activesupport"
|
37
|
+
spec.add_dependency "gem_config"
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency "pry-byebug"
|
43
|
+
spec.add_development_dependency "vcr"
|
44
|
+
spec.add_development_dependency "webmock"
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Glabssms
|
2
|
+
module BaseModule
|
3
|
+
module Methods
|
4
|
+
def set_instance_variables_from_hash(hash)
|
5
|
+
hash.each { |key, value| instance_variable_set "@#{key}", value }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend Methods
|
10
|
+
end
|
11
|
+
include Methods
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Glabssms
|
2
|
+
class Client
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
if config.is_a? Hash
|
7
|
+
@config = Configuration.new config
|
8
|
+
elsif config.is_a? Glabssms::Configuration
|
9
|
+
@config = config
|
10
|
+
else
|
11
|
+
raise ArgumentError, 'config is an invalid type'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_token(code:)
|
16
|
+
uri = URI.parse("https://developer.globelabs.com.ph/oauth/access_token?app_id=#{config.app_id}&app_secret=#{config.app_secret}&code=#{code}")
|
17
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
https.use_ssl = true
|
19
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
20
|
+
res = https.request(req)
|
21
|
+
body = JSON.parse(res.body).with_indifferent_access
|
22
|
+
|
23
|
+
if body[:access_token] && body[:subscriber_number]
|
24
|
+
TokenResult._new(body)
|
25
|
+
elsif body[:error]
|
26
|
+
ErrorResult.new(body[:error])
|
27
|
+
else
|
28
|
+
raise UnexpectedError, 'expected query parameters app_id, app_secret and code'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_sms(number:, message:, token:)
|
33
|
+
header = { 'Content-Type': 'application/json' }
|
34
|
+
sender_address = config.short_code[-4..-1]
|
35
|
+
sms_params = {
|
36
|
+
outboundSMSMessageRequest: {
|
37
|
+
senderAddress: sender_address,
|
38
|
+
outboundSMSTextMessage: { message: message },
|
39
|
+
address: number
|
40
|
+
}
|
41
|
+
}.to_json
|
42
|
+
|
43
|
+
uri = URI.parse("https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/#{sender_address}/requests?access_token=#{token}")
|
44
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
https.use_ssl = true
|
46
|
+
req = Net::HTTP::Post.new(uri.request_uri, header)
|
47
|
+
req.body = sms_params
|
48
|
+
res = https.request(req)
|
49
|
+
|
50
|
+
body = JSON.parse(res.body).with_indifferent_access
|
51
|
+
|
52
|
+
if body['outboundSMSMessageRequest']
|
53
|
+
SmsResult._new(body)
|
54
|
+
elsif body[:error]
|
55
|
+
ErrorResult.new(body[:error])
|
56
|
+
else
|
57
|
+
raise UnexpectedError, 'expected query parameters access_token'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Glabssms
|
2
|
+
class Configuration
|
3
|
+
READABLE_ATTRIBUTES = %i[app_id app_secret cross_telco_short_code short_code]
|
4
|
+
|
5
|
+
WRITABLE_ATTRIBUTES = %i[app_id app_secret cross_telco_short_code short_code logger]
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer *WRITABLE_ATTRIBUTES
|
9
|
+
end
|
10
|
+
attr_reader *READABLE_ATTRIBUTES
|
11
|
+
attr_writer *WRITABLE_ATTRIBUTES
|
12
|
+
|
13
|
+
def self.expectant_reader(*attributes)
|
14
|
+
attributes.each do |attribute|
|
15
|
+
(
|
16
|
+
class << self
|
17
|
+
self
|
18
|
+
end
|
19
|
+
)
|
20
|
+
.send(:define_method, attribute) do
|
21
|
+
attribute_value = instance_variable_get("@#{attribute}")
|
22
|
+
if attribute_value.nil? || attribute_value.to_s.empty?
|
23
|
+
raise ConfigurationError.new(
|
24
|
+
"Glabssms::Configuration.#{attribute.to_s} needs to be set"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
attribute_value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
expectant_reader *READABLE_ATTRIBUTES
|
32
|
+
|
33
|
+
def self.client
|
34
|
+
Glabssms::Client.new(instantiate)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.instantiate
|
38
|
+
config = new
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.logger
|
42
|
+
@logger ||= _default_logger
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(options = {})
|
46
|
+
WRITABLE_ATTRIBUTES.each do |attr|
|
47
|
+
instance_variable_set "@#{attr}",
|
48
|
+
options[attr] || Glabssms.configuration.send(attr)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def logger
|
53
|
+
@logger ||= self.class._default_logger
|
54
|
+
end
|
55
|
+
|
56
|
+
def self._default_logger
|
57
|
+
logger = Logger.new(STDOUT)
|
58
|
+
logger.level = Logger::INFO
|
59
|
+
logger
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
super.gsub(/@app_secret=\".*\"/, '@app_secret="[FILTERED]"')
|
64
|
+
end
|
65
|
+
|
66
|
+
def assert_has_keys
|
67
|
+
if app_id.nil? || app_secret.nil? || cross_telco_short_code.nil? || short_code.nil?
|
68
|
+
raise ConfigurationError.new(
|
69
|
+
'Glabssms::Configuration app_id, app_secret, cross_telco_short_code, short_code and are required.'
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Glabssms
|
2
|
+
class SmsResult
|
3
|
+
include BaseModule
|
4
|
+
|
5
|
+
attr_reader :number
|
6
|
+
attr_reader :sender_address
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
message_request = attributes.dig('outboundSMSMessageRequest')
|
11
|
+
@number = message_request.dig('address')
|
12
|
+
@sender_address = message_request.dig('senderAddress')
|
13
|
+
@message = message_request.dig('outboundSMSTextMessage', 'message')
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
protected :new
|
18
|
+
def _new(*args)
|
19
|
+
self.new(*args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def success?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Glabssms
|
2
|
+
class TokenResult
|
3
|
+
include BaseModule
|
4
|
+
|
5
|
+
attr_reader :access_token
|
6
|
+
attr_reader :subscriber_number
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
set_instance_variables_from_hash(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
protected :new
|
14
|
+
def _new(*args)
|
15
|
+
self.new(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/glabssms.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'gem_config'
|
2
|
+
require 'glabssms/version'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'json'
|
6
|
+
require 'glabssms/base_module'
|
7
|
+
require 'glabssms/configuration'
|
8
|
+
require 'glabssms/exceptions'
|
9
|
+
require 'glabssms/client'
|
10
|
+
require 'glabssms/token_result'
|
11
|
+
require 'glabssms/sms_result'
|
12
|
+
require 'glabssms/error_result'
|
13
|
+
|
14
|
+
module Glabssms
|
15
|
+
include GemConfig::Base
|
16
|
+
|
17
|
+
with_configuration do
|
18
|
+
has :app_id, classes: String
|
19
|
+
has :app_secret, classes: String
|
20
|
+
has :cross_telco_short_code, classes: String
|
21
|
+
has :short_code, classes: String
|
22
|
+
has :logger
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glabssms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavi Ablaza
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
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: gem_config
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- xlablaza@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".github/workflows/gempush.yml"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
137
|
+
- CODE_OF_CONDUCT.md
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- glabssms.gemspec
|
146
|
+
- lib/glabssms.rb
|
147
|
+
- lib/glabssms/base_module.rb
|
148
|
+
- lib/glabssms/client.rb
|
149
|
+
- lib/glabssms/configuration.rb
|
150
|
+
- lib/glabssms/error_result.rb
|
151
|
+
- lib/glabssms/exceptions.rb
|
152
|
+
- lib/glabssms/sms_result.rb
|
153
|
+
- lib/glabssms/token_result.rb
|
154
|
+
- lib/glabssms/version.rb
|
155
|
+
homepage: https://github.com/makisu/glabssms_ruby
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata:
|
159
|
+
homepage_uri: https://github.com/makisu/glabssms_ruby
|
160
|
+
source_code_uri: https://github.com/makisu/glabssms_ruby
|
161
|
+
changelog_uri: https://github.com/makisu/glabssms_ruby/blob/master/CHANGELOG.md
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubygems_version: 3.0.3
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Send SMS using Globe Labs in Ruby
|
181
|
+
test_files: []
|