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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bcc7361c6c86cc6656eb61e4c79e70b6cfd1069de5e84e3d7b72c83f4f083fa
4
- data.tar.gz: 214138dc5132d0824c7187125eac67637d89ff6b093c2a43bb0aacd032d8057e
3
+ metadata.gz: d48f378b1cdf8112f66fcbf5334fd24efaafd1ca2699aa077c65cfac7f23ec82
4
+ data.tar.gz: a4220da33061ff0203372fc1a04cfcee0d39bd9085f2c63dc21b73e64f83c183
5
5
  SHA512:
6
- metadata.gz: 87c5ee0377b7b180c52c471ff51cc7d40e21e84d4aed6036fe63aa61ce977ad9325394290743fd21445e47bff1796d302ce3af78dc7d463bb910e841e9dac041
7
- data.tar.gz: 752b10ae30c0e3320ec1af2fcb50a6910c25665d010aaf2da2dcf4d654cf983186ee2f2536448ff1db12a460a26921b4eb9b82ab4100a2d5b836d31a58f1fe84
6
+ metadata.gz: 7786df951d1aaca3e9d01409d7006586afed83f94d0c1d4203c6c5fd9a296f54d69ffcd39761ff41b05094793bec08938c3a78681482ec7a9fee15972a09a37f
7
+ data.tar.gz: d6882edcdbd90d7fc995d09ac7b69ad367d5e00d2bb03e3dec1c18aa066c54de80489ce16c9f4073faec63986983e972efa3b0a611c09c558558ebfe7d171e7c
@@ -19,4 +19,9 @@ jobs:
19
19
  run: rubocop
20
20
  - name: Run tests
21
21
  run: bundle exec rake spec
22
+ - name: Brakeman action
23
+ uses: artplan1/brakeman-action@v1.2.1
24
+ with:
25
+ flags: "--force"
26
+
22
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cequens (0.0.1)
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 the Cequens company.
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 with Cequens SMS APIs
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 config
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/AhmedAIbrahim/cequens'
17
- spec.metadata['source_code_uri'] = 'https://github.com/AhmedAIbrahim/cequens'
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
@@ -8,10 +8,12 @@ module Cequens
8
8
  CEQUENS_BASE_URL = 'https://apis.cequens.com/'
9
9
 
10
10
  class << self
11
- def post(path, params, body, _options)
12
- conn = connection
11
+ def get(path, _params, _body, _options)
12
+ connection.get(path)
13
+ end
13
14
 
14
- conn.post(path) do |request|
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
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-validation'
4
+
5
+ module Cequens
6
+ module Contracts
7
+ class GetSMSDetailsContract < Dry::Validation::Contract
8
+ params do
9
+ required(:id).value(:string)
10
+ end
11
+ end
12
+ end
13
+ 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)
@@ -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: request_params[: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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cequens
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.8'
5
5
  end
@@ -14,7 +14,7 @@ module Cequens
14
14
  DESC
15
15
 
16
16
  def copy_config_file
17
- template 'cequens_template.rb', 'config/initializers/cequens.rb'
17
+ template 'cequens_config.rb', 'config/initializers/cequens.rb'
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Cequens.config do |c|
4
+ c.access_token = 'your_token'
5
+ # replace sender id with yours
6
+ c.sender_name = 'Cequens'
7
+ end
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.3
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-02-16 00:00:00.000000000 Z
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/cequens_template.rb
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/AhmedAIbrahim/cequens
187
- source_code_uri: https://github.com/AhmedAIbrahim/cequens
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:
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Cequens.configure do |config|
4
- # config.access_token = ''
5
- end