arafa 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/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +174 -0
- data/Rakefile +12 -0
- data/implementation_plan.md +610 -0
- data/lib/arafa/airtime/africas_talking.rb +107 -0
- data/lib/arafa/airtime/base.rb +107 -0
- data/lib/arafa/airtime/wasiliana.rb +95 -0
- data/lib/arafa/configuration.rb +33 -0
- data/lib/arafa/contracts/africas_talking_airtime_contract.rb +29 -0
- data/lib/arafa/contracts/africas_talking_contract.rb +27 -0
- data/lib/arafa/contracts/airtime_contract.rb +52 -0
- data/lib/arafa/contracts/base_contract.rb +21 -0
- data/lib/arafa/contracts/mobile_data_contract.rb +60 -0
- data/lib/arafa/contracts/wasiliana_contract.rb +30 -0
- data/lib/arafa/data/africas_talking.rb +157 -0
- data/lib/arafa/errors.rb +23 -0
- data/lib/arafa/message.rb +17 -0
- data/lib/arafa/phone_number.rb +25 -0
- data/lib/arafa/providers/africas_talking.rb +116 -0
- data/lib/arafa/providers/base.rb +118 -0
- data/lib/arafa/providers/wasiliana.rb +98 -0
- data/lib/arafa/schemas/airtime_request_schema.rb +28 -0
- data/lib/arafa/schemas/delivery_report_schema.rb +15 -0
- data/lib/arafa/schemas/ussd_callback_schema.rb +17 -0
- data/lib/arafa/send_result.rb +37 -0
- data/lib/arafa/types.rb +21 -0
- data/lib/arafa/ussd/africas_talking.rb +26 -0
- data/lib/arafa/ussd/request.rb +41 -0
- data/lib/arafa/ussd/response.rb +25 -0
- data/lib/arafa/ussd/wasiliana.rb +26 -0
- data/lib/arafa/version.rb +5 -0
- data/lib/arafa/whatsapp/africas_talking.rb +174 -0
- data/lib/arafa/whatsapp/message_body.rb +146 -0
- data/lib/arafa.rb +68 -0
- data/sig/arafa.rbs +4 -0
- metadata +209 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e9650757184b4dee784ceb18fb349ee3b3ac97124cf298df249fab5292e33479
|
|
4
|
+
data.tar.gz: 02775ec8c4cea5c8c2b648bb2d21b0d6f4cd9d8a0dc55d4836f9127e4cb13fe7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 60110fbec45f0d2c6595d4f96b540c6335c8f06817409afac29a04fed3443ee94b89b53f40c97a7f87c28249be3018793686052da3f5078a12071a1de9128346
|
|
7
|
+
data.tar.gz: 31234c425a0a109d00aac04f4d12a9d7b49ada54d8416a61fa4ec1ff8d76addd0b7af149215a00e5d7dcb47aa5ab6a6cce0e665937da09b7305e3e88070a8af5
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"arafa" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["mcpaul2058@gmail.com"](mailto:"mcpaul2058@gmail.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paul Oguda
|
|
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,174 @@
|
|
|
1
|
+
# Arafa
|
|
2
|
+
|
|
3
|
+
Arafa gives you a single, uniform Ruby interface to multiple SMS/USSD/Airtime gateways
|
|
4
|
+
used in Kenya, starting with **Africa's Talking** and **Wasiliana**. Every send-shaped
|
|
5
|
+
call returns a `Dry::Monads::Result` —
|
|
6
|
+
`Success(Arafa::SendResult)` or `Failure(Arafa::Error subclass)` — instead of raising on
|
|
7
|
+
expected provider errors, so a rejected phone number or a bad API key is something you
|
|
8
|
+
pattern-match on, not `rescue`.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install the gem and add it to the application's Gemfile by executing:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bundle add arafa
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
gem install arafa
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
Configure credentials once, wherever your app boots (e.g. `config/initializers/arafa.rb`
|
|
27
|
+
in Rails); provider instances then pick them up automatically instead of needing
|
|
28
|
+
credentials passed on every call:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
Arafa.configure do |config|
|
|
32
|
+
config.wasiliana.api_key = ENV["WASILIANA_API_KEY"]
|
|
33
|
+
config.africas_talking.api_key = ENV["AT_API_KEY"]
|
|
34
|
+
config.africas_talking.username = ENV["AT_USERNAME"]
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Testing against Africa's Talking's sandbox app? Set `config.africas_talking.sandbox = true` to
|
|
39
|
+
route SMS sends through `https://api.sandbox.africastalking.com/version1/messaging` instead of
|
|
40
|
+
the production bulk endpoint, and use the sandbox app's own `username` (`sandbox`) and API key.
|
|
41
|
+
Note the sandbox only delivers to phone numbers registered as Simulator Numbers in the sandbox
|
|
42
|
+
app's dashboard — any other number comes back as a `Failure(Arafa::InvalidRequestError)`.
|
|
43
|
+
|
|
44
|
+
## Sending an SMS
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
provider = Arafa::Wasiliana.new(text: "Hello", to: "0728833100")
|
|
48
|
+
result = provider.send
|
|
49
|
+
result.success? # => true
|
|
50
|
+
result.value!.message_id
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Wasiliana requires a Sender ID/ShortCode on every send — pass it explicitly with `from:`,
|
|
54
|
+
or set `config.default_sender` once in `Arafa.configure` so every call can omit it, as
|
|
55
|
+
above.
|
|
56
|
+
|
|
57
|
+
`to:` accepts a single number or an array, in any of the accepted Kenyan formats
|
|
58
|
+
(`07...`, `01...`, `+254...`, `254...`) — Arafa normalizes each one to `2547XXXXXXXX` /
|
|
59
|
+
`2541XXXXXXXX` before it's sent. The same shape works for Africa's Talking:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
Arafa::AfricasTalking.new(text: "Hello", to: %w[0711123456 0722334455], from: "MyApp").send
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Prefer a one-off call without instantiating the provider yourself? Use the class-level
|
|
66
|
+
shortcut:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
Arafa::Wasiliana.send(text: "Hello", to: "0728833100")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or dispatch to a provider chosen at runtime (e.g. from config/env) by name, via the
|
|
73
|
+
provider registry:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
Arafa.send(:wasiliana, text: "Hello", to: "0728833100")
|
|
77
|
+
Arafa.send(:africas_talking, text: "Hello", to: "0728833100", from: "MyApp")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Reading a validation failure
|
|
81
|
+
|
|
82
|
+
Requests are validated locally before any HTTP call is made — e.g. Wasiliana requires a
|
|
83
|
+
`from:` Sender ID/ShortCode on every send, so leaving it out (with no
|
|
84
|
+
`default_sender` configured) comes back as `Failure(Arafa::ValidationError)` without
|
|
85
|
+
hitting the network:
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
result = Arafa::Wasiliana.new(text: "Hello", to: "0728833100").send
|
|
89
|
+
|
|
90
|
+
result.success? # => false
|
|
91
|
+
result.failure # => #<Arafa::ValidationError: {from: ["must be filled"]}>
|
|
92
|
+
result.failure.message # => "{from: [\"must be filled\"]}"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Note that malformed input the phone number *type* itself rejects (e.g. `to: "not-a-number"`)
|
|
96
|
+
raises `Dry::Types::ConstraintError` at construction time instead, since it fails before a
|
|
97
|
+
`Dry::Monads::Result` even exists to wrap it — only failures caught by a provider's
|
|
98
|
+
`Contract` (§5.3) come back as `result.failure`.
|
|
99
|
+
|
|
100
|
+
`result.failure` is always an `Arafa::Error` subclass — `ValidationError` for a rejected
|
|
101
|
+
payload, or `AuthenticationError` / `InvalidRequestError` / `RateLimitError` /
|
|
102
|
+
`ProviderServerError` / `NetworkError` once the request actually reaches the provider
|
|
103
|
+
(see `lib/arafa/errors.rb`).
|
|
104
|
+
|
|
105
|
+
## USSD (callback-only — no `#send`)
|
|
106
|
+
|
|
107
|
+
Neither provider exposes an outbound "send USSD" call — USSD is inbound-only. You
|
|
108
|
+
register a service code and callback URL with the provider; they `POST` each subscriber
|
|
109
|
+
interaction to your app, and you must respond within 10 seconds with a `CON `/`END
|
|
110
|
+
`-prefixed plain-text body. Arafa only helps with parsing that inbound payload and
|
|
111
|
+
building the reply — there is no `Arafa::Ussd::Wasiliana.new(...).send`-style call, since
|
|
112
|
+
there's nothing to send:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
# Inside your controller/route handling the provider's callback POST:
|
|
116
|
+
request = Arafa::Ussd::Request.from_africas_talking(params)
|
|
117
|
+
# or: Arafa::Ussd::Request.from_wasiliana(params)
|
|
118
|
+
|
|
119
|
+
if request.text.empty?
|
|
120
|
+
render plain: Arafa::Ussd::Response.continue("Welcome\n1. Check balance\n2. Buy airtime")
|
|
121
|
+
else
|
|
122
|
+
render plain: Arafa::Ussd::Response.end("Thanks for using our service")
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Airtime
|
|
127
|
+
|
|
128
|
+
Top up a subscriber's airtime directly, without going through the SMS/USSD flow. Both
|
|
129
|
+
providers share the same request shape (`phone_number:`, `currency_code:`, `amount:`)
|
|
130
|
+
and return the same `Arafa::SendResult`:
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
Arafa::Airtime::Wasiliana.new(
|
|
134
|
+
phone_number: "0712345678",
|
|
135
|
+
currency_code: "KES",
|
|
136
|
+
amount: "100.50",
|
|
137
|
+
callback: "https://example.com/callback"
|
|
138
|
+
).send
|
|
139
|
+
|
|
140
|
+
Arafa::Airtime::AfricasTalking.new(
|
|
141
|
+
phone_number: %w[0712345678 0722345678],
|
|
142
|
+
currency_code: "KES",
|
|
143
|
+
amount: "100.50"
|
|
144
|
+
).send
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
|
150
|
+
test` to run the tests. You can also run `bin/console` for an interactive prompt that
|
|
151
|
+
will allow you to experiment.
|
|
152
|
+
|
|
153
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release
|
|
154
|
+
a new version, update the version number in `version.rb`, and then run `bundle exec rake
|
|
155
|
+
release`, which will create a git tag for the version, push git commits and the created
|
|
156
|
+
tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
161
|
+
https://github.com/kamalogudah/arafa. This project is intended to be a safe, welcoming
|
|
162
|
+
space for collaboration, and contributors are expected to adhere to the [code of
|
|
163
|
+
conduct](https://github.com/kamalogudah/arafa/blob/main/CODE_OF_CONDUCT.md).
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
The gem is available as open source under the terms of the [MIT
|
|
168
|
+
License](https://opensource.org/licenses/MIT).
|
|
169
|
+
|
|
170
|
+
## Code of Conduct
|
|
171
|
+
|
|
172
|
+
Everyone interacting in the Arafa project's codebases, issue trackers, chat rooms and
|
|
173
|
+
mailing lists is expected to follow the [code of
|
|
174
|
+
conduct](https://github.com/kamalogudah/arafa/blob/main/CODE_OF_CONDUCT.md).
|