smspartner 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +199 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +26 -0
- data/bin/setup +8 -0
- data/lib/smspartner.rb +30 -0
- data/lib/smspartner/client.rb +74 -0
- data/lib/smspartner/configuration.rb +58 -0
- data/lib/smspartner/configurator.rb +35 -0
- data/lib/smspartner/helpers/boolean.rb +11 -0
- data/lib/smspartner/response.rb +22 -0
- data/lib/smspartner/version.rb +3 -0
- data/smspartner.gemspec +38 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14d96b004f7d4cb97193ad409b6f3c51da21bff69ab0c66d6fb13ed0f155d5d9
|
4
|
+
data.tar.gz: 576e3364bc9a8c5672bba1827515697b46450adb3339ba25d680e5c2ecaf8a56
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7907805dd788b0128ab38e33907b485187382dc0855c9fa961724a3f72d917f9e50da94517b0369db32324afb46bfa3652f53a39bd9eecf35358ae51acaa416b
|
7
|
+
data.tar.gz: a10507000288092a8ff3b78a3404336c14378a33fc5b48da170da3e454acfa4828b63b894367c86f723f704c42bdc5472e432113d814b687bb4f096b812cd104
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'vendor/**/*'
|
4
|
+
- 'db/*'
|
5
|
+
- 'db/migrate/*'
|
6
|
+
- 'db/fixtures/**/*'
|
7
|
+
- 'tmp/**/*'
|
8
|
+
- 'builds/**/*'
|
9
|
+
- 'Gemfile'
|
10
|
+
- 'config/environments/*'
|
11
|
+
- 'config/puma.rb'
|
12
|
+
- 'test/application_system_test_case.rb'
|
13
|
+
- 'test/test_helper.rb'
|
14
|
+
- 'config/initializers/*.rb'
|
15
|
+
- 'Guardfile'
|
16
|
+
- 'node_modules/**/*'
|
17
|
+
- 'Capfile'
|
18
|
+
- 'config/deploy.rb'
|
19
|
+
- 'config/deploy/**/*'
|
20
|
+
|
21
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
22
|
+
Metrics/LineLength:
|
23
|
+
Max: 100
|
24
|
+
|
25
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
26
|
+
# the code easier to read (by naming things), but can also clutter the class
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 20
|
29
|
+
|
30
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Max: 1500
|
33
|
+
|
34
|
+
# No space makes the method definition shorter and differentiates
|
35
|
+
# from a regular assignment.
|
36
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
37
|
+
EnforcedStyle: no_space
|
38
|
+
|
39
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
40
|
+
Style/SymbolArray:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
# Most readable form.
|
44
|
+
Layout/AlignHash:
|
45
|
+
EnforcedHashRocketStyle: table
|
46
|
+
EnforcedColonStyle: table
|
47
|
+
|
48
|
+
# Mixing the styles looks just silly.
|
49
|
+
Style/HashSyntax:
|
50
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
51
|
+
|
52
|
+
# has_key? and has_value? are far more readable than key? and value?
|
53
|
+
Style/PreferredHashMethods:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
# String#% is by far the least verbose and only object oriented variant.
|
57
|
+
Style/FormatString:
|
58
|
+
EnforcedStyle: percent
|
59
|
+
|
60
|
+
Style/CollectionMethods:
|
61
|
+
Enabled: true
|
62
|
+
PreferredMethods:
|
63
|
+
# inject seems more common in the community.
|
64
|
+
reduce: inject
|
65
|
+
|
66
|
+
|
67
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
68
|
+
# is silly. Let's try to live without them for now.
|
69
|
+
Style/ParenthesesAroundCondition:
|
70
|
+
AllowSafeAssignment: false
|
71
|
+
Lint/AssignmentInCondition:
|
72
|
+
AllowSafeAssignment: false
|
73
|
+
|
74
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
75
|
+
# So both variants make sense.
|
76
|
+
Style/RaiseArgs:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
80
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
81
|
+
Layout/MultilineOperationIndentation:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
85
|
+
# The argument that fail should be used to abort the program is wrong too,
|
86
|
+
# there's Kernel#abort for that.
|
87
|
+
Style/SignalException:
|
88
|
+
EnforcedStyle: only_raise
|
89
|
+
|
90
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
91
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
92
|
+
# or suppressing LoadError for optional dependencies
|
93
|
+
Lint/HandleExceptions:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
97
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
98
|
+
Style/BlockDelimiters:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
# do / end blocks should be used for side effects,
|
102
|
+
# methods that run a block for side effects and have
|
103
|
+
# a useful return value are rare, assign the return
|
104
|
+
# value to a local variable for those cases.
|
105
|
+
Style/MethodCalledOnDoEndBlock:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
109
|
+
Style/SingleLineBlockParams:
|
110
|
+
Enabled: false
|
111
|
+
|
112
|
+
# Shadowing outer local variables with block parameters is often useful
|
113
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
114
|
+
# between the outer variable and the parameter. The cases where it's actually
|
115
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
116
|
+
# because the method is too long.
|
117
|
+
Lint/ShadowingOuterLocalVariable:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
# Check with yard instead.
|
121
|
+
Style/Documentation:
|
122
|
+
Enabled: false
|
123
|
+
|
124
|
+
# This is just silly. Calling the argument `other` in all cases makes no sense.
|
125
|
+
Naming/BinaryOperatorParameterName:
|
126
|
+
Enabled: false
|
127
|
+
|
128
|
+
# There are valid cases, for example debugging Cucumber steps,
|
129
|
+
# also they'll fail CI anyway
|
130
|
+
Lint/Debugger:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
# Style preference
|
134
|
+
Style/MethodDefParentheses:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
# Disable frozen string
|
138
|
+
Style/FrozenStringLiteralComment:
|
139
|
+
Enabled: false
|
140
|
+
|
141
|
+
# Disable No ASCII char in comments
|
142
|
+
Style/AsciiComments:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
# Disable ordered Gems By ascii
|
146
|
+
Bundler/OrderedGems:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
# Change ABC max value
|
150
|
+
Metrics/AbcSize:
|
151
|
+
Max: 20
|
152
|
+
|
153
|
+
# Disable empty method in one line
|
154
|
+
Style/EmptyMethod:
|
155
|
+
EnforcedStyle: expanded
|
156
|
+
|
157
|
+
# Disable max height block
|
158
|
+
Metrics/BlockLength:
|
159
|
+
Enabled: true
|
160
|
+
Exclude:
|
161
|
+
- 'spec/**/*.rb'
|
162
|
+
- 'lib/**/*'
|
163
|
+
- 'config/routes.rb'
|
164
|
+
|
165
|
+
Layout/EmptyLinesAroundClassBody:
|
166
|
+
EnforcedStyle: empty_lines
|
167
|
+
Exclude:
|
168
|
+
- 'app/channels/*/*'
|
169
|
+
- 'config/*'
|
170
|
+
- 'app/controllers/application_controller.rb'
|
171
|
+
- 'app/mailers/application_mailer.rb'
|
172
|
+
- 'app/models/application_record.rb'
|
173
|
+
- 'test/*/*'
|
174
|
+
|
175
|
+
Layout/EmptyLinesAroundModuleBody:
|
176
|
+
EnforcedStyle: no_empty_lines
|
177
|
+
Exclude:
|
178
|
+
- 'app/channels/*/*'
|
179
|
+
- 'config/*'
|
180
|
+
- 'app/helpers/application_helper.rb'
|
181
|
+
|
182
|
+
Style/PercentLiteralDelimiters:
|
183
|
+
PreferredDelimiters:
|
184
|
+
default: '()'
|
185
|
+
'%i': '[]'
|
186
|
+
'%I': '[]'
|
187
|
+
'%r': '{}'
|
188
|
+
'%w': '[]'
|
189
|
+
'%W': '[]'
|
190
|
+
|
191
|
+
Rails/Output:
|
192
|
+
Exclude:
|
193
|
+
- 'config/deploy.rb'
|
194
|
+
|
195
|
+
Style/UnneededPercentQ:
|
196
|
+
Enabled: false
|
197
|
+
|
198
|
+
Layout/SpaceInLambdaLiteral:
|
199
|
+
EnforcedStyle: require_space
|
data/.travis.yml
ADDED
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 brenau_j@modulotech.fr. 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,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
smspartner (0.1.0)
|
5
|
+
httparty (~> 0.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
httparty (0.15.7)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
multi_xml (0.6.0)
|
15
|
+
parallel (1.12.1)
|
16
|
+
parser (2.4.0.2)
|
17
|
+
ast (~> 2.3)
|
18
|
+
powerpack (0.1.1)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.1)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.1)
|
34
|
+
rubocop (0.52.1)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.4.0.2, < 3.0)
|
37
|
+
powerpack (~> 0.1)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
41
|
+
ruby-progressbar (1.9.0)
|
42
|
+
unicode-display_width (1.3.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 1.16)
|
49
|
+
rake (~> 10.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
rubocop (~> 0.50)
|
52
|
+
smspartner!
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jean-Baptiste Brenaut
|
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,73 @@
|
|
1
|
+
# Smspartner
|
2
|
+
|
3
|
+
This gem allows you to simply send SMS via the smspartner.fr API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'smspartner', '~> 0.1'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install smspartner
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You first need to configure the gem before using the SMS sending feature :
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Smspartner.configure do |config|
|
27
|
+
# fetch your API key from a file
|
28
|
+
config.api_key = File.read(Rails.root.join('api_keys', 'sms_partner'))
|
29
|
+
# or from the environment
|
30
|
+
# config.api_key = ENV['sms_partner_api_key']
|
31
|
+
|
32
|
+
config.sender = '11 chars max'
|
33
|
+
|
34
|
+
# default values
|
35
|
+
# config.sandbox = false
|
36
|
+
# config.range_value = :premium # valid values are %i[premium low_cost]
|
37
|
+
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Rails users: put this code inside `config/initializers/smspartner.rb`
|
42
|
+
|
43
|
+
To send a SMS, simply do the following
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
res = Smspartner.send_sms to: phone_number, body: sms_body
|
47
|
+
|
48
|
+
if res.success?
|
49
|
+
puts "You should store the message's id: #{res.message_id}"
|
50
|
+
else
|
51
|
+
warn "Failed to send SMS because: #{res.errors.join("\n")}"
|
52
|
+
end
|
53
|
+
|
54
|
+
puts JSON.pretty_generate res.raw_data
|
55
|
+
```
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
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.
|
60
|
+
|
61
|
+
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).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/moduloTech/smspartner. 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.
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
70
|
+
|
71
|
+
## Code of Conduct
|
72
|
+
|
73
|
+
Everyone interacting in the Smspartner project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moduloTech/smspartner/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'smspartner'
|
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
|
+
@secrets = YAML.load_file File.expand_path('../../spec/secrets.yml', __FILE__)
|
10
|
+
|
11
|
+
def configure!(api_key)
|
12
|
+
Smspartner.configure do |config|
|
13
|
+
config.sandbox = true
|
14
|
+
config.api_key = api_key
|
15
|
+
config.sender = 'Test'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
configure!(@secrets[:api_key])
|
20
|
+
|
21
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
22
|
+
# require 'pry'
|
23
|
+
# Pry.start
|
24
|
+
|
25
|
+
require 'irb'
|
26
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/smspartner.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'smspartner/version'
|
2
|
+
require 'smspartner/configurator'
|
3
|
+
|
4
|
+
module Smspartner
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def configure(&block)
|
8
|
+
Configurator.configure(&block)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
attr_accessor :client
|
14
|
+
|
15
|
+
def send_sms(**args)
|
16
|
+
if client.nil?
|
17
|
+
raise 'Initialization Error: You must call Smspartner.configure before calling send_sms'
|
18
|
+
end
|
19
|
+
client.send_sms(**args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def account_data
|
23
|
+
if client.nil?
|
24
|
+
raise 'Initialization Error: You must call Smspartner.configure before calling account_data'
|
25
|
+
end
|
26
|
+
client.me
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'smspartner/response'
|
3
|
+
|
4
|
+
module Smspartner
|
5
|
+
class Client
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
SEND_SMS_URL = 'https://api.smspartner.fr/v1/send'.freeze
|
12
|
+
|
13
|
+
MY_DATA_URL = 'https://api.smspartner.fr/v1/me'.freeze
|
14
|
+
|
15
|
+
ALLOWED_CONFIG_OVERRIDE = %i[sandbox sender range_value].freeze
|
16
|
+
|
17
|
+
RANGE_VALUES = { premium: 1, low_cost: 2 }.freeze
|
18
|
+
|
19
|
+
# @param to [String] phone number
|
20
|
+
# @param body [String] SMS body
|
21
|
+
# @param config [Hash] overrides to config
|
22
|
+
def send_sms(to:, body:, **config)
|
23
|
+
res = send_request(to, body, config)
|
24
|
+
ret = Response.new(res.parsed_response)
|
25
|
+
raise SmsSendError.new(ret) if !ret.success? && config[:raise_on_error]
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
|
29
|
+
def me
|
30
|
+
HTTParty.get(
|
31
|
+
MY_DATA_URL,
|
32
|
+
query: {
|
33
|
+
apiKey: @config.api_key
|
34
|
+
},
|
35
|
+
headers: {
|
36
|
+
content_type: 'application/json'
|
37
|
+
}
|
38
|
+
).parsed_response
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def send_request(to, body, config)
|
44
|
+
HTTParty.post(
|
45
|
+
SEND_SMS_URL,
|
46
|
+
body: sms_json(
|
47
|
+
to,
|
48
|
+
body,
|
49
|
+
config.select { |k, _v| ALLOWED_CONFIG_OVERRIDE.include?(k) }.compact
|
50
|
+
).to_json,
|
51
|
+
headers: {
|
52
|
+
content_type: 'application/json'
|
53
|
+
}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def sms_json(to, body, config)
|
58
|
+
final_config = @config.to_h.merge!(config)
|
59
|
+
|
60
|
+
json = {
|
61
|
+
apiKey: final_config[:api_key],
|
62
|
+
message: body,
|
63
|
+
phoneNumbers: to,
|
64
|
+
gamme: RANGE_VALUES[final_config[:range_value]],
|
65
|
+
sender: final_config[:sender]
|
66
|
+
}
|
67
|
+
json.compact!
|
68
|
+
json[:sandbox] = 1 if final_config[:sandbox]
|
69
|
+
|
70
|
+
json
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'smspartner/helpers/boolean'
|
2
|
+
|
3
|
+
module Smspartner
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
ALLOWED_RANGE_VALUES = %i[premium low_cost].freeze
|
7
|
+
|
8
|
+
# @param api_key [String] the API key
|
9
|
+
# @param range_value [:premium, :low_cost]
|
10
|
+
# @param sandbox [Boolean] true to enable sandbox mode, disabled by default
|
11
|
+
# @param sender [String] SMS sender's name
|
12
|
+
def initialize(api_key:, range_value:, sandbox: false, sender: nil)
|
13
|
+
self.api_key = api_key
|
14
|
+
self.range_value = range_value
|
15
|
+
self.sandbox = sandbox
|
16
|
+
self.sender = sender
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Hash] attributes as a hash
|
20
|
+
def to_h
|
21
|
+
{
|
22
|
+
api_key: api_key,
|
23
|
+
range_value: range_value,
|
24
|
+
sandbox: sandbox,
|
25
|
+
sender: sender
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :api_key
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_writer :api_key
|
34
|
+
attr_accessor :sender
|
35
|
+
|
36
|
+
attr_reader :range_value
|
37
|
+
def range_value=(value)
|
38
|
+
unless ALLOWED_RANGE_VALUES.include?(value)
|
39
|
+
raise ArgumentError.new(
|
40
|
+
"#{value.inspect} is not a valid range_value, " \
|
41
|
+
"valid values are #{ALLOWED_RANGE_VALUES.inspect}"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
@range_value = value
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_reader :sandbox
|
48
|
+
def sandbox=(bool)
|
49
|
+
unless Helpers::Boolean.valid?(bool)
|
50
|
+
raise ArgumentError.new(
|
51
|
+
"#{bool.inspect} should be a boolean"
|
52
|
+
)
|
53
|
+
end
|
54
|
+
@sandbox = bool
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'smspartner/configuration'
|
2
|
+
require 'smspartner/client'
|
3
|
+
|
4
|
+
module Smspartner
|
5
|
+
# Configuration builder that is yielded by Smspartner.configure
|
6
|
+
class Configurator
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
raise ArgumentError.new('A block is needed for Smspartner.configure') unless block_given?
|
10
|
+
builder = new
|
11
|
+
yield builder
|
12
|
+
Smspartner.configuration = builder.build_config
|
13
|
+
Smspartner.client = Client.new(Smspartner.configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@range_value = :premium
|
18
|
+
@sandbox = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_config
|
22
|
+
Configuration.new(
|
23
|
+
api_key: api_key,
|
24
|
+
sender: sender,
|
25
|
+
range_value: range_value,
|
26
|
+
sandbox: sandbox
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_accessor :api_key, :sender, :range_value, :sandbox
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
private_constant :Configurator
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Smspartner
|
2
|
+
class Response
|
3
|
+
|
4
|
+
def initialize(body)
|
5
|
+
@success = body['success']
|
6
|
+
@errors = body['error']
|
7
|
+
@code = body['code']
|
8
|
+
@message_id = body['message_id']
|
9
|
+
@raw_data = body
|
10
|
+
end
|
11
|
+
|
12
|
+
def success?
|
13
|
+
@success
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :errors
|
17
|
+
attr_reader :code
|
18
|
+
attr_reader :message_id
|
19
|
+
attr_reader :raw_data
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/smspartner.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'smspartner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'smspartner'
|
8
|
+
spec.version = Smspartner::VERSION
|
9
|
+
spec.authors = ['Jean-Baptiste Brenaut']
|
10
|
+
spec.email = ['tech-web@modulotech.fr']
|
11
|
+
|
12
|
+
spec.summary = %q(Ruby interface to https://www.smspartner.fr)
|
13
|
+
spec.description = %q(Ruby interface to https://www.smspartner.fr's API)
|
14
|
+
spec.homepage = 'https://github.com/moduloTech/smspartner'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
# else
|
23
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
# 'public gem pushes.'
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'httparty', '~> 0.13'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.50'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smspartner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Baptiste Brenaut
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-26 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.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.50'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.50'
|
83
|
+
description: Ruby interface to https://www.smspartner.fr's API
|
84
|
+
email:
|
85
|
+
- tech-web@modulotech.fr
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/smspartner.rb
|
103
|
+
- lib/smspartner/client.rb
|
104
|
+
- lib/smspartner/configuration.rb
|
105
|
+
- lib/smspartner/configurator.rb
|
106
|
+
- lib/smspartner/helpers/boolean.rb
|
107
|
+
- lib/smspartner/response.rb
|
108
|
+
- lib/smspartner/version.rb
|
109
|
+
- smspartner.gemspec
|
110
|
+
homepage: https://github.com/moduloTech/smspartner
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Ruby interface to https://www.smspartner.fr
|
133
|
+
test_files: []
|