cequens 0.0.2 → 0.0.7

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: be3486da8322d3687e414560bd33e1d93eae35328e067d835bd721c29fa2caeb
4
- data.tar.gz: 4b3d2575a79f5ac88041d3e57446aabe3750b17a8c396a7765fb4e65f847a001
3
+ metadata.gz: f11166fbdbe9870dc4ca38824b06c4bf8f508b9949f8722fe92cad32d527b25e
4
+ data.tar.gz: c6b5eb0a9c544b27922643e42fa87d864614ea2d5d5cd0593f687080980e3d13
5
5
  SHA512:
6
- metadata.gz: 6a628284aaeee98c0c5a6830468c09802744eff644f1d2a2c64838a4e49ffef4b3ba14c810a1da9f81a4d7c95f3bb80bbd9fbc513b1d4ee279bfb37e466ab6c9
7
- data.tar.gz: 2fa1bc796410c2a85d51d3a2378810d9b97f14c4f67489d83c11be552596aec462df6a2b040617e51fbdae19ec123c413cc5ce837105ff1b812e03f3e344006c
6
+ metadata.gz: 8588a8033b78e4bbe046297c18bf56c0d399b0603e918ea3d9ff21b0ee4669fbb73d4b5cfca862ceda6c6c2f11f39f512a0126c48b377efe629aecc93fb699e8
7
+ data.tar.gz: 6feb98cdd452e20c471bd8cbec09161defe58bdc2d66238a9847064af5b9f5aa61645a3daca27bba61c71ad255cffc34437fb7d40e5565cf00475b3dbc19dac9
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.6)
5
5
  dry-validation (~> 1.6)
6
6
  faraday (~> 0.17)
7
7
 
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 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
 
@@ -22,6 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ configure access token as:
26
+
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
+ end
33
+
25
34
  ### Send SMS
26
35
 
27
36
  ```ruby
@@ -38,3 +47,12 @@ res = Cequens.send_sms(params)
38
47
  res.success? # => true
39
48
  ```
40
49
 
50
+ ### Get SMS Details
51
+
52
+ ```ruby
53
+ res = Cequens.get_sms_details(id: "AAAAA")
54
+ # => #<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"=>""}}>
55
+
56
+ res.success? # => true
57
+ res.message # => Request handled successfully
58
+ ```
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)/}) }
data/lib/cequens.rb CHANGED
@@ -7,8 +7,10 @@ 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 'byebug'
10
+ require 'cequens/requests/get_sms_details_request'
11
+ require 'cequens/contracts/get_sms_details_contract'
11
12
  require 'rails'
13
+ require 'byebug'
12
14
 
13
15
  module Cequens
14
16
  class << self
@@ -21,5 +23,9 @@ module Cequens
21
23
  def send_sms(params, opts = {})
22
24
  Request.new('send_sms', params, opts).fire_request
23
25
  end
26
+
27
+ def get_sms_details(params, opts = {})
28
+ Request.new('get_sms_details', params, opts).fire_request
29
+ end
24
30
  end
25
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
@@ -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])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cequens
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.7'
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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Cequens.config do |c|
4
+ # c.access_token = token
5
+ 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.2
4
+ version: 0.0.7
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-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation
@@ -171,20 +171,22 @@ files:
171
171
  - cequens.gemspec
172
172
  - lib/cequens.rb
173
173
  - lib/cequens/connection.rb
174
+ - lib/cequens/contracts/get_sms_details_contract.rb
174
175
  - lib/cequens/contracts/send_sms_contract.rb
175
176
  - lib/cequens/errors.rb
176
177
  - lib/cequens/request.rb
178
+ - lib/cequens/requests/get_sms_details_request.rb
177
179
  - lib/cequens/requests/send_sms_request.rb
178
180
  - lib/cequens/response.rb
179
181
  - lib/cequens/version.rb
180
182
  - lib/generators/cequens/config_generator.rb
181
- - lib/generators/cequens/templates/cequens_template.rb
183
+ - lib/generators/cequens/templates/cequens_config.rb
182
184
  homepage:
183
185
  licenses:
184
186
  - MIT
185
187
  metadata:
186
- homepage_uri: https://github.com/AhmedAIbrahim/cequens
187
- source_code_uri: https://github.com/AhmedAIbrahim/cequens
188
+ homepage_uri: https://github.com/AhmedAliIbrahim/cequens
189
+ source_code_uri: https://github.com/AhmedAliIbrahim/cequens
188
190
  post_install_message:
189
191
  rdoc_options: []
190
192
  require_paths:
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Cequens.configure do |config|
4
- # config.access_token = ''
5
- end