busibe 0.1.2
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/.coveralls.yml +0 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +236 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +141 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/busibe.gemspec +39 -0
- data/lib/busibe.rb +12 -0
- data/lib/busibe/client.rb +62 -0
- data/lib/busibe/configuration.rb +40 -0
- data/lib/busibe/connection.rb +29 -0
- data/lib/busibe/error/error.rb +40 -0
- data/lib/busibe/error/raise_client_error.rb +22 -0
- data/lib/busibe/error/raise_server_error.rb +19 -0
- data/lib/busibe/request.rb +45 -0
- data/lib/busibe/version.rb +3 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3465371e9662c98bee98c1584f26785a13082859
|
4
|
+
data.tar.gz: 9bd4f89301cf20bfb3fdef94957ff530c209ef8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7132c0c422d237a397e48894fe509d6cbd8a0ae9e0aaf6c33ce2b0abf4f686f5adcea0af8d08e037ca17fb8b0046138fa15389eb64410268c69a887044a0e44
|
7
|
+
data.tar.gz: 8fd1b5ecd2c7fb2b107a5c5849fc47c6b63d307c6b1eb53c79acc283a468f27ff6f9d50d41a4dbd5c084ccfc6cbeb287dab449afc1ead3e36ec6e9bcfcbf0748
|
data/.coveralls.yml
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "bin/**/*"
|
5
|
+
- "Rakefile"
|
6
|
+
- "busibe.gemspec"
|
7
|
+
- "spec/fixtures/**/*"
|
8
|
+
UseCache: false
|
9
|
+
Style/CollectionMethods:
|
10
|
+
Description: Preferred collection methods.
|
11
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
12
|
+
Enabled: true
|
13
|
+
PreferredMethods:
|
14
|
+
collect: map
|
15
|
+
collect!: map!
|
16
|
+
find: detect
|
17
|
+
find_all: select
|
18
|
+
reduce: inject
|
19
|
+
Style/DotPosition:
|
20
|
+
Description: Checks the position of the dot in multi-line method calls.
|
21
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
22
|
+
Enabled: true
|
23
|
+
EnforcedStyle: trailing
|
24
|
+
SupportedStyles:
|
25
|
+
- leading
|
26
|
+
- trailing
|
27
|
+
Style/FileName:
|
28
|
+
Description: Use snake_case for source file names.
|
29
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
30
|
+
Enabled: false
|
31
|
+
Exclude: []
|
32
|
+
Style/GuardClause:
|
33
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
34
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
35
|
+
Enabled: false
|
36
|
+
MinBodyLength: 1
|
37
|
+
Style/IfUnlessModifier:
|
38
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
39
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
40
|
+
Enabled: false
|
41
|
+
MaxLineLength: 80
|
42
|
+
Style/OptionHash:
|
43
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
44
|
+
Enabled: false
|
45
|
+
Style/PercentLiteralDelimiters:
|
46
|
+
Description: Use `%`-literal delimiters consistently
|
47
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
48
|
+
Enabled: false
|
49
|
+
PreferredDelimiters:
|
50
|
+
"%": "()"
|
51
|
+
"%i": "()"
|
52
|
+
"%q": "()"
|
53
|
+
"%Q": "()"
|
54
|
+
"%r": "{}"
|
55
|
+
"%s": "()"
|
56
|
+
"%w": "()"
|
57
|
+
"%W": "()"
|
58
|
+
"%x": "()"
|
59
|
+
Style/PredicateName:
|
60
|
+
Description: Check the names of predicate methods.
|
61
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
62
|
+
Enabled: true
|
63
|
+
NamePrefix:
|
64
|
+
- is_
|
65
|
+
- has_
|
66
|
+
- have_
|
67
|
+
NamePrefixBlacklist:
|
68
|
+
- is_
|
69
|
+
Exclude:
|
70
|
+
- spec/**/*
|
71
|
+
Style/RaiseArgs:
|
72
|
+
Description: Checks the arguments passed to raise/fail.
|
73
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
74
|
+
Enabled: false
|
75
|
+
EnforcedStyle: exploded
|
76
|
+
SupportedStyles:
|
77
|
+
- compact
|
78
|
+
- exploded
|
79
|
+
Style/SignalException:
|
80
|
+
Description: Checks for proper usage of fail and raise.
|
81
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
82
|
+
Enabled: false
|
83
|
+
EnforcedStyle: semantic
|
84
|
+
SupportedStyles:
|
85
|
+
- only_raise
|
86
|
+
- only_fail
|
87
|
+
- semantic
|
88
|
+
Style/SingleLineBlockParams:
|
89
|
+
Description: Enforces the names of some block params.
|
90
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
91
|
+
Enabled: false
|
92
|
+
Methods:
|
93
|
+
- reduce:
|
94
|
+
- a
|
95
|
+
- e
|
96
|
+
- inject:
|
97
|
+
- a
|
98
|
+
- e
|
99
|
+
Style/SingleLineMethods:
|
100
|
+
Description: Avoid single-line methods.
|
101
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
102
|
+
Enabled: false
|
103
|
+
AllowIfMethodIsEmpty: true
|
104
|
+
Style/StringLiterals:
|
105
|
+
Description: Checks if uses of quotes match the configured preference.
|
106
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
107
|
+
Enabled: true
|
108
|
+
EnforcedStyle: double_quotes
|
109
|
+
SupportedStyles:
|
110
|
+
- single_quotes
|
111
|
+
- double_quotes
|
112
|
+
Style/StringLiteralsInInterpolation:
|
113
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
114
|
+
match the configured preference.
|
115
|
+
Enabled: true
|
116
|
+
EnforcedStyle: single_quotes
|
117
|
+
SupportedStyles:
|
118
|
+
- single_quotes
|
119
|
+
- double_quotes
|
120
|
+
Style/TrailingCommaInArguments:
|
121
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
122
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
123
|
+
Enabled: false
|
124
|
+
EnforcedStyleForMultiline: no_comma
|
125
|
+
SupportedStyles:
|
126
|
+
- comma
|
127
|
+
- no_comma
|
128
|
+
Metrics/AbcSize:
|
129
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
130
|
+
conditions.
|
131
|
+
Enabled: false
|
132
|
+
Max: 15
|
133
|
+
Metrics/ClassLength:
|
134
|
+
Description: Avoid classes longer than 100 lines of code.
|
135
|
+
Enabled: false
|
136
|
+
CountComments: false
|
137
|
+
Max: 100
|
138
|
+
Metrics/ModuleLength:
|
139
|
+
CountComments: false
|
140
|
+
Max: 100
|
141
|
+
Description: Avoid modules longer than 100 lines of code.
|
142
|
+
Enabled: false
|
143
|
+
Metrics/CyclomaticComplexity:
|
144
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
145
|
+
cases needed to validate a method.
|
146
|
+
Enabled: false
|
147
|
+
Max: 6
|
148
|
+
Metrics/MethodLength:
|
149
|
+
Description: Avoid methods longer than 10 lines of code.
|
150
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
151
|
+
Enabled: false
|
152
|
+
CountComments: false
|
153
|
+
Max: 10
|
154
|
+
Metrics/ParameterLists:
|
155
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
156
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
157
|
+
Enabled: false
|
158
|
+
Max: 5
|
159
|
+
CountKeywordArgs: true
|
160
|
+
Metrics/PerceivedComplexity:
|
161
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
162
|
+
reader.
|
163
|
+
Enabled: false
|
164
|
+
Max: 7
|
165
|
+
Lint/AssignmentInCondition:
|
166
|
+
Description: Don't use assignment in conditions.
|
167
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
168
|
+
Enabled: false
|
169
|
+
AllowSafeAssignment: true
|
170
|
+
Style/InlineComment:
|
171
|
+
Description: Avoid inline comments.
|
172
|
+
Enabled: false
|
173
|
+
Style/AccessorMethodName:
|
174
|
+
Description: Check the naming of accessor methods for get_/set_.
|
175
|
+
Enabled: false
|
176
|
+
Style/Alias:
|
177
|
+
Description: Use alias_method instead of alias.
|
178
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
179
|
+
Enabled: false
|
180
|
+
Style/Documentation:
|
181
|
+
Description: Document classes and non-namespace modules.
|
182
|
+
Enabled: false
|
183
|
+
Style/DoubleNegation:
|
184
|
+
Description: Checks for uses of double negation (!!).
|
185
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
186
|
+
Enabled: false
|
187
|
+
Style/EachWithObject:
|
188
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
189
|
+
Enabled: false
|
190
|
+
Style/EmptyLiteral:
|
191
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
192
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
193
|
+
Enabled: false
|
194
|
+
Style/ModuleFunction:
|
195
|
+
Description: Checks for usage of `extend self` in modules.
|
196
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
197
|
+
Enabled: false
|
198
|
+
Style/OneLineConditional:
|
199
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
200
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
201
|
+
Enabled: false
|
202
|
+
Style/PerlBackrefs:
|
203
|
+
Description: Avoid Perl-style regex back references.
|
204
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
205
|
+
Enabled: false
|
206
|
+
Style/Send:
|
207
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
208
|
+
may overlap with existing methods.
|
209
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
210
|
+
Enabled: false
|
211
|
+
Style/SpecialGlobalVars:
|
212
|
+
Description: Avoid Perl-style global variables.
|
213
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
214
|
+
Enabled: false
|
215
|
+
Style/VariableInterpolation:
|
216
|
+
Description: Don't interpolate global, instance and class variables directly in
|
217
|
+
strings.
|
218
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
219
|
+
Enabled: false
|
220
|
+
Style/WhenThen:
|
221
|
+
Description: Use when x then ... for one-line cases.
|
222
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
223
|
+
Enabled: false
|
224
|
+
Lint/EachWithObjectArgument:
|
225
|
+
Description: Check for immutable argument given to each_with_object.
|
226
|
+
Enabled: true
|
227
|
+
Lint/HandleExceptions:
|
228
|
+
Description: Don't suppress exception.
|
229
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
230
|
+
Enabled: false
|
231
|
+
Lint/LiteralInCondition:
|
232
|
+
Description: Checks of literals used in conditions.
|
233
|
+
Enabled: false
|
234
|
+
Lint/LiteralInInterpolation:
|
235
|
+
Description: Checks for literals used in interpolation.
|
236
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 andela-bmakinwa
|
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,141 @@
|
|
1
|
+
# Busibe
|
2
|
+
|
3
|
+
[](https://coveralls.io/github/andela-bmakinwa/busibe?branch=master) [](https://travis-ci.org/andela-bmakinwa/busibe) [](https://codeclimate.com/github/andela-bmakinwa/busibe)
|
4
|
+
|
5
|
+
> Jusibe Library for Ruby
|
6
|
+
|
7
|
+
Busibe is a ruby gem that consumes the services of [Jusibe](http:://jusibe.com). With this library, you can access the SMS functionalities provided by the Jusibe seamlessly.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'busibe'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install busibe
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
|
28
|
+
#### Create a Client instance
|
29
|
+
```ruby
|
30
|
+
require "busibe"
|
31
|
+
|
32
|
+
# set configuration params
|
33
|
+
config = {
|
34
|
+
public_key: "PUBLIC_KEY",
|
35
|
+
access_token: "ACCESS_TOKEN"
|
36
|
+
}
|
37
|
+
|
38
|
+
# instantiate Client class
|
39
|
+
client = Busibe::Client.new(config)
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Send SMS
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# data needed to send sms
|
46
|
+
payload = {
|
47
|
+
to: "PHONE NUMBER",
|
48
|
+
from: "Sender's name",
|
49
|
+
message: "Do you love Ruby?"
|
50
|
+
}
|
51
|
+
|
52
|
+
begin
|
53
|
+
client.send_sms payload # return instance of Client
|
54
|
+
# OR
|
55
|
+
client.send_sms(payload).get_response # return response body
|
56
|
+
rescue Exception => e
|
57
|
+
puts e.message
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
##### Sample response body
|
62
|
+
```
|
63
|
+
{
|
64
|
+
"status": "Sent",
|
65
|
+
"message_id": "xeqd6rrd26",
|
66
|
+
"sms_credits_used": 1
|
67
|
+
}
|
68
|
+
```
|
69
|
+
|
70
|
+
___
|
71
|
+
#### Check Available Credits
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
begin
|
75
|
+
client.check_available_credits # return instance of Client
|
76
|
+
# OR
|
77
|
+
client.check_available_credits.get_response # return response body
|
78
|
+
rescue Exception => e
|
79
|
+
puts e.message
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
##### Sample response body
|
84
|
+
```
|
85
|
+
{
|
86
|
+
"sms_credits": "182"
|
87
|
+
}
|
88
|
+
```
|
89
|
+
___
|
90
|
+
|
91
|
+
#### Check Delivery Status
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
message_id = "MESSAGE ID"
|
95
|
+
|
96
|
+
begin
|
97
|
+
# return instance of Client
|
98
|
+
client.check_delivery_status message_id
|
99
|
+
# OR
|
100
|
+
# return response body
|
101
|
+
client.check_delivery_status(message_id).get_response
|
102
|
+
rescue Exception => e
|
103
|
+
puts e.message
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
##### Sample response body
|
108
|
+
```
|
109
|
+
{
|
110
|
+
"sms_credits": "182"
|
111
|
+
}
|
112
|
+
```
|
113
|
+
___
|
114
|
+
|
115
|
+
##### Other available methods
|
116
|
+
```ruby
|
117
|
+
# sends sms and returns response
|
118
|
+
client.send_sms_with_response(payload)
|
119
|
+
|
120
|
+
# makes request and returns response
|
121
|
+
client.check_available_credits_with_response
|
122
|
+
|
123
|
+
# makes request and returns response
|
124
|
+
client.check_delivery_status_with_response
|
125
|
+
```
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests.
|
130
|
+
|
131
|
+
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).
|
132
|
+
|
133
|
+
## Contributing
|
134
|
+
|
135
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/andela-bmakinwa/busibe.
|
136
|
+
|
137
|
+
|
138
|
+
## License
|
139
|
+
|
140
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
141
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "rake/testtask"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
Rake::TestTask.new do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.ruby_opts << "-rubygems"
|
10
|
+
test.pattern = 'test/**/*_test.rb'
|
11
|
+
test.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "busibe"
|
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
|
data/bin/setup
ADDED
data/busibe.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "busibe/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "busibe"
|
8
|
+
spec.version = Busibe::VERSION
|
9
|
+
spec.authors = ["andela-bmakinwa"]
|
10
|
+
spec.email = ["makinwa37@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "SMS service using Jusibe (jusibe.com)"
|
13
|
+
spec.description = "Busibe provides an easy interface to interact with the Jusibe API (jusibe.com)"
|
14
|
+
spec.homepage = "https://github.com/andela-bmakinwa/busibe"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "faraday"
|
31
|
+
spec.add_dependency "faraday_middleware"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "dotenv"
|
37
|
+
spec.add_development_dependency "vcr"
|
38
|
+
spec.add_development_dependency "coveralls"
|
39
|
+
end
|
data/lib/busibe.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "json"
|
2
|
+
require "busibe/connection"
|
3
|
+
require "busibe/request"
|
4
|
+
|
5
|
+
module Busibe
|
6
|
+
class Client
|
7
|
+
include Busibe::Connection
|
8
|
+
include Busibe::Request
|
9
|
+
|
10
|
+
attr_accessor(*Configuration::VALID_CONFIG_KEYS)
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
merged_options = Busibe::Jusibe.options.merge(options)
|
15
|
+
|
16
|
+
Configuration::VALID_CONFIG_KEYS.each do |key|
|
17
|
+
send("#{key}=", merged_options[key])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_sms(payload = {})
|
22
|
+
if payload.empty?
|
23
|
+
raise ArgumentError.new("A payload is required in order to send an sms")
|
24
|
+
end
|
25
|
+
|
26
|
+
post("/smsapi/send_sms", payload)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_available_credits
|
31
|
+
get("/smsapi/get_credits")
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_delivery_status(message_id = nil)
|
36
|
+
if message_id.nil?
|
37
|
+
raise ArgumentError.new("A message ID is required")
|
38
|
+
end
|
39
|
+
|
40
|
+
post("/smsapi/delivery_status?message_id=#{message_id}")
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_response
|
45
|
+
JSON.load @response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def method_missing(method_sym, *args, &_block)
|
51
|
+
result = method_sym.to_s =~ /^(.*)_with_response$/
|
52
|
+
super unless result
|
53
|
+
send($1, *args).get_response
|
54
|
+
end
|
55
|
+
|
56
|
+
def respond_to_missing?(method_sym, include_private = false)
|
57
|
+
method_sym.to_s =~ /^(.*)_with_response$/
|
58
|
+
super unless respond_to? $1.to_sym
|
59
|
+
true
|
60
|
+
end
|
61
|
+
end # Client
|
62
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Busibe
|
2
|
+
module Configuration
|
3
|
+
VALID_CONNECTION_KEYS = [:endpoint, :user_agent, :request_method].freeze
|
4
|
+
VALID_OPTIONS_KEYS = [:public_key, :access_token, :format].freeze
|
5
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
6
|
+
|
7
|
+
DEFAULT_ENDPOINT = "https://jusibe.com".freeze
|
8
|
+
DEFAULT_REQUEST_METHOD = :get
|
9
|
+
DEFAULT_USER_AGENT = "Busibe API Ruby Gem #{Busibe::VERSION}".freeze
|
10
|
+
|
11
|
+
DEFAULT_PUBLIC_KEY = nil
|
12
|
+
DEFAULT_ACCESS_TOKEN = nil
|
13
|
+
DEFAULT_FORMAT = :json
|
14
|
+
|
15
|
+
attr_accessor(*VALID_CONFIG_KEYS)
|
16
|
+
|
17
|
+
def self.extended(base)
|
18
|
+
base.reset
|
19
|
+
end
|
20
|
+
|
21
|
+
# reset config settings
|
22
|
+
def reset
|
23
|
+
self.endpoint = DEFAULT_ENDPOINT
|
24
|
+
self.request_method = DEFAULT_REQUEST_METHOD
|
25
|
+
self.user_agent = DEFAULT_USER_AGENT
|
26
|
+
|
27
|
+
self.public_key = DEFAULT_PUBLIC_KEY
|
28
|
+
self.access_token = DEFAULT_ACCESS_TOKEN
|
29
|
+
self.format = DEFAULT_FORMAT
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure
|
33
|
+
yield self
|
34
|
+
end
|
35
|
+
|
36
|
+
def options
|
37
|
+
Hash[*VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten]
|
38
|
+
end
|
39
|
+
end # Configuration
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "busibe/error/raise_client_error"
|
4
|
+
require "busibe/error/raise_server_error"
|
5
|
+
|
6
|
+
module Busibe
|
7
|
+
module Connection
|
8
|
+
private
|
9
|
+
|
10
|
+
def connection(options)
|
11
|
+
default_options = {
|
12
|
+
url: options.fetch(:endpoint, endpoint)
|
13
|
+
}
|
14
|
+
|
15
|
+
@connection ||= Faraday.new(default_options) do |faraday|
|
16
|
+
faraday.use(
|
17
|
+
Faraday::Request::BasicAuthentication,
|
18
|
+
options[:public_key],
|
19
|
+
options[:access_token]
|
20
|
+
)
|
21
|
+
|
22
|
+
faraday.use Busibe::Error::RaiseClientError
|
23
|
+
faraday.use Busibe::Error::RaiseServerError
|
24
|
+
faraday.request :url_encoded
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Busibe
|
2
|
+
module Error
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :http_headers
|
5
|
+
|
6
|
+
def initialize(message, http_headers)
|
7
|
+
@http_headers = http_headers
|
8
|
+
super(message)
|
9
|
+
end
|
10
|
+
end # Error
|
11
|
+
end
|
12
|
+
# class Error::ServerError < Busibe::Error::Error; end
|
13
|
+
module Error
|
14
|
+
class ServerError < Busibe::Error::Error; end
|
15
|
+
end
|
16
|
+
# class Error::ServiceUnavailable < Error::ServerError; end
|
17
|
+
module Error
|
18
|
+
class ServiceUnavailable < Busibe::Error::ServerError; end
|
19
|
+
end
|
20
|
+
|
21
|
+
# class Error::ClientError < Busibe::Error::Error; end
|
22
|
+
module Error
|
23
|
+
class ClientError < Busibe::Error::Error; end
|
24
|
+
end
|
25
|
+
|
26
|
+
# class Error::Forbidden < Error::ClientError; end
|
27
|
+
|
28
|
+
module Error
|
29
|
+
class Forbidden < Busibe::Error::ClientError; end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Error
|
33
|
+
class BadRequest < Busibe::Error::ClientError; end
|
34
|
+
end
|
35
|
+
# class Error::BadRequest < Error::ClientError; end
|
36
|
+
module Error
|
37
|
+
class RequestTooLarge < Busibe::Error::ClientError; end
|
38
|
+
end
|
39
|
+
# class Error::RequestTooLarge < Error::ClientError; end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Busibe
|
4
|
+
module Error
|
5
|
+
class RaiseClientError < Faraday::Response::Middleware
|
6
|
+
def on_complete(env)
|
7
|
+
status = env[:status].to_i
|
8
|
+
body = env[:body]
|
9
|
+
headers = env[:response_headers]
|
10
|
+
|
11
|
+
case status
|
12
|
+
when 400
|
13
|
+
raise Busibe::Error::BadRequest.new body, headers
|
14
|
+
when 403
|
15
|
+
raise Busibe::Error::Forbidden.new body, headers
|
16
|
+
when 413
|
17
|
+
raise Busibe::Error::RequestTooLarge.new body, headers
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end # ClientError
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "busibe/error/error"
|
3
|
+
|
4
|
+
module Busibe
|
5
|
+
module Error
|
6
|
+
class RaiseServerError < Faraday::Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
status = env[:status].to_i
|
9
|
+
headers = env[:response_headers]
|
10
|
+
|
11
|
+
case status
|
12
|
+
when 503
|
13
|
+
message = "503 No server is available to handle this request."
|
14
|
+
raise Busibe::Error::ServiceUnavailable.new message, headers
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Busibe
|
2
|
+
module Request
|
3
|
+
def get(path, params = {})
|
4
|
+
perform_request(
|
5
|
+
:get,
|
6
|
+
path,
|
7
|
+
params,
|
8
|
+
public_key: @public_key, access_token: @access_token
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, params = {})
|
13
|
+
perform_request(
|
14
|
+
:post,
|
15
|
+
path,
|
16
|
+
params,
|
17
|
+
public_key: @public_key, access_token: @access_token
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def perform_request(method, path, params, options)
|
24
|
+
@connection = connection(options)
|
25
|
+
@response = @connection.run_request(
|
26
|
+
method,
|
27
|
+
path,
|
28
|
+
params,
|
29
|
+
nil
|
30
|
+
) do |request|
|
31
|
+
request.options[:raw] = true if options[:raw]
|
32
|
+
|
33
|
+
case method.to_sym
|
34
|
+
when :get
|
35
|
+
request.url(path, params)
|
36
|
+
when :post
|
37
|
+
request.path = path
|
38
|
+
request.body = params unless params.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
options[:raw] ? @response : @response.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: busibe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- andela-bmakinwa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
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: faraday_middleware
|
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: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
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: dotenv
|
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: coveralls
|
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: Busibe provides an easy interface to interact with the Jusibe API (jusibe.com)
|
126
|
+
email:
|
127
|
+
- makinwa37@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".coveralls.yml"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- busibe.gemspec
|
144
|
+
- lib/busibe.rb
|
145
|
+
- lib/busibe/client.rb
|
146
|
+
- lib/busibe/configuration.rb
|
147
|
+
- lib/busibe/connection.rb
|
148
|
+
- lib/busibe/error/error.rb
|
149
|
+
- lib/busibe/error/raise_client_error.rb
|
150
|
+
- lib/busibe/error/raise_server_error.rb
|
151
|
+
- lib/busibe/request.rb
|
152
|
+
- lib/busibe/version.rb
|
153
|
+
homepage: https://github.com/andela-bmakinwa/busibe
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata:
|
157
|
+
allowed_push_host: https://rubygems.org
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.4.5.1
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: SMS service using Jusibe (jusibe.com)
|
178
|
+
test_files: []
|
179
|
+
has_rdoc:
|