cequens 0.0.3 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -0
- data/Gemfile.lock +3 -1
- data/README.md +19 -3
- data/cequens.gemspec +3 -2
- data/lib/cequens.rb +8 -1
- data/lib/cequens/connection.rb +5 -3
- data/lib/cequens/contracts/get_sms_details_contract.rb +13 -0
- data/lib/cequens/contracts/send_sms_contract.rb +1 -1
- data/lib/cequens/request.rb +4 -0
- data/lib/cequens/requests/get_sms_details_request.rb +40 -0
- data/lib/cequens/requests/send_sms_request.rb +11 -2
- data/lib/cequens/version.rb +1 -1
- data/lib/generators/cequens/config_generator.rb +1 -1
- data/lib/generators/cequens/templates/cequens_config.rb +7 -0
- metadata +21 -5
- data/lib/generators/cequens/templates/cequens_template.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d48f378b1cdf8112f66fcbf5334fd24efaafd1ca2699aa077c65cfac7f23ec82
|
4
|
+
data.tar.gz: a4220da33061ff0203372fc1a04cfcee0d39bd9085f2c63dc21b73e64f83c183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7786df951d1aaca3e9d01409d7006586afed83f94d0c1d4203c6c5fd9a296f54d69ffcd39761ff41b05094793bec08938c3a78681482ec7a9fee15972a09a37f
|
7
|
+
data.tar.gz: d6882edcdbd90d7fc995d09ac7b69ad367d5e00d2bb03e3dec1c18aa066c54de80489ce16c9f4073faec63986983e972efa3b0a611c09c558558ebfe7d171e7c
|
data/.github/workflows/ruby.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cequens (0.0.
|
4
|
+
cequens (0.0.7)
|
5
5
|
dry-validation (~> 1.6)
|
6
6
|
faraday (~> 0.17)
|
7
7
|
|
@@ -70,6 +70,7 @@ GEM
|
|
70
70
|
addressable (2.7.0)
|
71
71
|
public_suffix (>= 2.0.2, < 5.0)
|
72
72
|
ast (2.4.2)
|
73
|
+
brakeman (5.0.0)
|
73
74
|
builder (3.2.4)
|
74
75
|
byebug (11.1.3)
|
75
76
|
concurrent-ruby (1.1.8)
|
@@ -225,6 +226,7 @@ PLATFORMS
|
|
225
226
|
ruby
|
226
227
|
|
227
228
|
DEPENDENCIES
|
229
|
+
brakeman (~> 5.0)
|
228
230
|
bundler (~> 2.0)
|
229
231
|
byebug (~> 11.1)
|
230
232
|
cequens!
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Cequens
|
2
2
|
|
3
|
-
**Disclaimer:** we are not officially affilated with
|
3
|
+
**Disclaimer:** we are not officially affilated with [Cequens](https://developer.cequens.com) company.
|
4
4
|
|
5
|
-
A plug-and-play library that make it easier to use
|
5
|
+
A plug-and-play library that make it easier to use Cequens SMS APIs
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -24,7 +24,13 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
configure access token as:
|
26
26
|
|
27
|
-
$ rails g cequens
|
27
|
+
$ rails g cequens:config
|
28
|
+
|
29
|
+
Cequens.config do |c|
|
30
|
+
# c.access_token = token # add your access token not api token
|
31
|
+
# access_token is what you get when you login
|
32
|
+
# c.sender_name = sender_name
|
33
|
+
end
|
28
34
|
|
29
35
|
### Send SMS
|
30
36
|
|
@@ -41,3 +47,13 @@ res = Cequens.send_sms(params)
|
|
41
47
|
|
42
48
|
res.success? # => true
|
43
49
|
```
|
50
|
+
|
51
|
+
### Get SMS Details
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
res = Cequens.get_sms_details(id: "AAAAA")
|
55
|
+
# => #<Cequens::Response:0x00007ffd672b29f8 @api_response={"replyCode"=>0, "replyMessage"=>"Request handled successfully", "requestId"=>"64035880-7044-11eb-9f04-11a5522e89a7", "clientRequestId"=>0, "requestTime"=>"2021-02-16T10:47:40.296", "data"=>{"SentSMSIDs"=>[{"SMSId"=>"056ef72a-1497-47be-a4c8-4a7835e071dc"}], "InvalidRecipients"=>""}}>
|
56
|
+
|
57
|
+
res.success? # => true
|
58
|
+
res.message # => Request handled successfully
|
59
|
+
```
|
data/cequens.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.summary = 'A library to interface with Cequens SMS gateway API.'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.metadata['homepage_uri'] = 'https://github.com/
|
17
|
-
spec.metadata['source_code_uri'] = 'https://github.com/
|
16
|
+
spec.metadata['homepage_uri'] = 'https://github.com/AhmedAliIbrahim/cequens'
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/AhmedAliIbrahim/cequens'
|
18
18
|
|
19
19
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'dry-validation', '~> 1.6'
|
28
28
|
spec.add_dependency 'faraday', '~> 0.17'
|
29
29
|
|
30
|
+
spec.add_development_dependency 'brakeman', '~> 5.0'
|
30
31
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
31
32
|
spec.add_development_dependency 'byebug', '~> 11.1'
|
32
33
|
spec.add_development_dependency 'rails', '~> 6.1'
|
data/lib/cequens.rb
CHANGED
@@ -7,11 +7,14 @@ require 'cequens/request'
|
|
7
7
|
require 'cequens/response'
|
8
8
|
require 'cequens/requests/send_sms_request'
|
9
9
|
require 'cequens/contracts/send_sms_contract'
|
10
|
+
require 'cequens/requests/get_sms_details_request'
|
11
|
+
require 'cequens/contracts/get_sms_details_contract'
|
10
12
|
require 'rails'
|
13
|
+
require 'byebug'
|
11
14
|
|
12
15
|
module Cequens
|
13
16
|
class << self
|
14
|
-
attr_accessor :access_token
|
17
|
+
attr_accessor :access_token, :sender_name
|
15
18
|
|
16
19
|
def config
|
17
20
|
yield self
|
@@ -20,5 +23,9 @@ module Cequens
|
|
20
23
|
def send_sms(params, opts = {})
|
21
24
|
Request.new('send_sms', params, opts).fire_request
|
22
25
|
end
|
26
|
+
|
27
|
+
def get_sms_details(params, opts = {})
|
28
|
+
Request.new('get_sms_details', params, opts).fire_request
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
data/lib/cequens/connection.rb
CHANGED
@@ -8,10 +8,12 @@ module Cequens
|
|
8
8
|
CEQUENS_BASE_URL = 'https://apis.cequens.com/'
|
9
9
|
|
10
10
|
class << self
|
11
|
-
def
|
12
|
-
|
11
|
+
def get(path, _params, _body, _options)
|
12
|
+
connection.get(path)
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
def post(path, params, body, _options)
|
16
|
+
connection.post(path) do |request|
|
15
17
|
request.params = params
|
16
18
|
request.body = body.to_json
|
17
19
|
end
|
@@ -10,8 +10,8 @@ module Cequens
|
|
10
10
|
params do
|
11
11
|
required(:recipients).value(:string)
|
12
12
|
required(:messageText).value(:string)
|
13
|
-
required(:senderName).value(:string)
|
14
13
|
required(:messageType).value(included_in?: MESSAGE_TYPE)
|
14
|
+
optional(:senderName).value(:string)
|
15
15
|
optional(:validityPeriod).value(:string)
|
16
16
|
optional(:clientMessageId).value(:integer)
|
17
17
|
optional(:acknowledgement).value(included_in?: KEYS)
|
data/lib/cequens/request.rb
CHANGED
@@ -22,6 +22,10 @@ module Cequens
|
|
22
22
|
self.class.include Requests::SendSMSRequest
|
23
23
|
validate_params!
|
24
24
|
@request = build_send_sms_request
|
25
|
+
when 'get_sms_details'
|
26
|
+
self.class.include Requests::GetSMSDetailsRequest
|
27
|
+
validate_params!
|
28
|
+
@request = build_get_sms_details_request
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cequens
|
4
|
+
module Requests
|
5
|
+
module GetSMSDetailsRequest
|
6
|
+
DEFAULTS = {}.freeze
|
7
|
+
|
8
|
+
def fire_request
|
9
|
+
cequens_api_response = Connection.get(request[:path], request[:params], request[:body], request[:options])
|
10
|
+
response_body = JSON.parse(cequens_api_response.body)
|
11
|
+
|
12
|
+
Response.new(response_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_get_sms_details_request
|
18
|
+
{
|
19
|
+
path: "sms/v1/messages/#{message_id}",
|
20
|
+
params: {},
|
21
|
+
body: {},
|
22
|
+
options: options
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_params
|
27
|
+
@request_params ||= DEFAULTS.merge(params)
|
28
|
+
end
|
29
|
+
|
30
|
+
def message_id
|
31
|
+
request_params[:id]
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_params!
|
35
|
+
contract = Contracts::GetSMSDetailsContract.new.call(request_params)
|
36
|
+
raise InvalidCequensRequestError, contract.errors.to_h if contract.failure?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Cequens
|
4
4
|
module Requests
|
5
5
|
module SendSMSRequest
|
6
|
-
DEFAULTS = {}.freeze
|
6
|
+
DEFAULTS = { messageType: 'text' }.freeze
|
7
7
|
|
8
8
|
def fire_request
|
9
9
|
cequens_api_response = Connection.post(request[:path], request[:params], request[:body], request[:options])
|
@@ -32,7 +32,7 @@ module Cequens
|
|
32
32
|
def request_transformed_params
|
33
33
|
{
|
34
34
|
messageText: request_params[:messageText],
|
35
|
-
senderName:
|
35
|
+
senderName: sender_name,
|
36
36
|
messageType: request_params[:messageType],
|
37
37
|
recipients: request_params[:recipients],
|
38
38
|
clientMessageId: request_params[:clientMessageId],
|
@@ -48,6 +48,15 @@ module Cequens
|
|
48
48
|
}.compact
|
49
49
|
end
|
50
50
|
|
51
|
+
def sender_name
|
52
|
+
if request_params[:sender_name].nil?
|
53
|
+
request_params[:sender_name] =
|
54
|
+
Cequens.sender_name
|
55
|
+
else
|
56
|
+
request_params[:sender_name]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
51
60
|
# rubocop:enable Metrics/AbcSize
|
52
61
|
# rubocop:enable Metrics/MethodLength
|
53
62
|
|
data/lib/cequens/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cequens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Ali
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: brakeman
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,20 +185,22 @@ files:
|
|
171
185
|
- cequens.gemspec
|
172
186
|
- lib/cequens.rb
|
173
187
|
- lib/cequens/connection.rb
|
188
|
+
- lib/cequens/contracts/get_sms_details_contract.rb
|
174
189
|
- lib/cequens/contracts/send_sms_contract.rb
|
175
190
|
- lib/cequens/errors.rb
|
176
191
|
- lib/cequens/request.rb
|
192
|
+
- lib/cequens/requests/get_sms_details_request.rb
|
177
193
|
- lib/cequens/requests/send_sms_request.rb
|
178
194
|
- lib/cequens/response.rb
|
179
195
|
- lib/cequens/version.rb
|
180
196
|
- lib/generators/cequens/config_generator.rb
|
181
|
-
- lib/generators/cequens/templates/
|
197
|
+
- lib/generators/cequens/templates/cequens_config.rb
|
182
198
|
homepage:
|
183
199
|
licenses:
|
184
200
|
- MIT
|
185
201
|
metadata:
|
186
|
-
homepage_uri: https://github.com/
|
187
|
-
source_code_uri: https://github.com/
|
202
|
+
homepage_uri: https://github.com/AhmedAliIbrahim/cequens
|
203
|
+
source_code_uri: https://github.com/AhmedAliIbrahim/cequens
|
188
204
|
post_install_message:
|
189
205
|
rdoc_options: []
|
190
206
|
require_paths:
|