verifykit 0.0.0 → 0.1.0

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: 78c1a3ee627f8960c242b2d27797b565a16bd0f84d860fb0ab7d01667e83d3ef
4
- data.tar.gz: e80c212d8fb2e387b767aebb22b3f86668e840eadd79b45de9b5077a7fa5a323
3
+ metadata.gz: 2473e1046dcafaf0c25dd4bbab37d4b74a3e8f2b6464c8389b8c3b57697a69d7
4
+ data.tar.gz: e737bafa0ab02717d2f9f47af3230970877a2ca18a9d6c6b13c3af08e0b7e239
5
5
  SHA512:
6
- metadata.gz: b479f90b3eb90bf629e39a88d8dec9d553d712f5ba1ea4a8acd73a062ea5396848261ca79ed7aa282f577f0dae57f4dc846d794cc338d00b86fa87af5cdb6c71
7
- data.tar.gz: f92481d06803f355a68e8da2773a23d30a88bed00d5a5c032770788d136def72f512c8d669a16dd2411662cdf5d114e7722ecb0418e8b506e73e5c7e68146bfd
6
+ metadata.gz: edbd604aad4338fd0f48c6341118e6c24be073bd1821dd81c80b396b3f710a97734fc24aa0fa8512f2dbfb7bea8b5940bfc6bafae69493141faec551f82c277c
7
+ data.tar.gz: ac5b54578bdf04d4a84b77fa73ed33901cb32065b6266c1a5aabe21bd638f383b98590c77b901017c5a49b427deaf84040ea8d311f606c5e14d42e159b050cf5
data/Gemfile.lock CHANGED
@@ -1,7 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- verifykit (0.0.0)
4
+ verifykit (0.1.0)
5
+ dry-configurable (~> 1.0, >= 1.0.1)
6
+ dry-initializer (~> 3.1, >= 3.1.1)
7
+ dry-monads (~> 1.6)
8
+ dry-struct (~> 1.6)
9
+ dry-types (~> 1.7, >= 1.7.1)
10
+ faraday (~> 2.7, >= 2.7.4)
11
+ zeitwerk (~> 2.6, >= 2.6.8)
5
12
 
6
13
  GEM
7
14
  remote: https://rubygems.org/
@@ -9,7 +16,40 @@ GEM
9
16
  ast (2.4.2)
10
17
  awesome_print (1.9.2)
11
18
  coderay (1.1.3)
19
+ concurrent-ruby (1.2.2)
12
20
  diff-lcs (1.5.0)
21
+ dry-configurable (1.0.1)
22
+ dry-core (~> 1.0, < 2)
23
+ zeitwerk (~> 2.6)
24
+ dry-core (1.0.0)
25
+ concurrent-ruby (~> 1.0)
26
+ zeitwerk (~> 2.6)
27
+ dry-inflector (1.0.0)
28
+ dry-initializer (3.1.1)
29
+ dry-logic (1.5.0)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 1.0, < 2)
32
+ zeitwerk (~> 2.6)
33
+ dry-monads (1.6.0)
34
+ concurrent-ruby (~> 1.0)
35
+ dry-core (~> 1.0, < 2)
36
+ zeitwerk (~> 2.6)
37
+ dry-struct (1.6.0)
38
+ dry-core (~> 1.0, < 2)
39
+ dry-types (>= 1.7, < 2)
40
+ ice_nine (~> 0.11)
41
+ zeitwerk (~> 2.6)
42
+ dry-types (1.7.1)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-core (~> 1.0)
45
+ dry-inflector (~> 1.0)
46
+ dry-logic (~> 1.4)
47
+ zeitwerk (~> 2.6)
48
+ faraday (2.7.4)
49
+ faraday-net_http (>= 2.0, < 3.1)
50
+ ruby2_keywords (>= 0.0.4)
51
+ faraday-net_http (3.0.2)
52
+ ice_nine (0.11.2)
13
53
  json (2.6.3)
14
54
  method_source (1.0.0)
15
55
  parallel (1.23.0)
@@ -48,7 +88,9 @@ GEM
48
88
  rubocop-ast (1.28.1)
49
89
  parser (>= 3.2.1.0)
50
90
  ruby-progressbar (1.13.0)
91
+ ruby2_keywords (0.0.5)
51
92
  unicode-display_width (2.4.2)
93
+ zeitwerk (2.6.8)
52
94
 
53
95
  PLATFORMS
54
96
  arm64-darwin-22
data/README.md CHANGED
@@ -32,7 +32,151 @@ gem install verifykit
32
32
 
33
33
  ## Usage
34
34
 
35
- TODO: Write usage instructions here
35
+ ### Configuration
36
+
37
+ ```ruby
38
+ # config/initializers/verifykit.rb
39
+
40
+ VerifyKit.configure do |config|
41
+ # it's optional, you can set manually when you create a VerifyKit::Client instance too
42
+ config.server_key = ENV.fetch('VERIFYKIT_SERVER_KEY')
43
+
44
+ # it's optional, default is Logger.new(STDOUT)
45
+ config.logger = Rails.logger
46
+
47
+ # it's optional, default is false
48
+ config.debug.enabled = true
49
+
50
+ # it's optional, default is 'v1.0', you can set manually when you create a VerifyKit::Client instance too but VerifyKit doesn't support any other version yet, so don't change it
51
+ config.api_version = 'v1.0'
52
+ end
53
+
54
+ # or
55
+
56
+ VerifyKit.config.server_key = ENV.fetch('VERIFYKIT_SERVER_KEY')
57
+ VerifyKit.config.logger = Rails.logger
58
+ VerifyKit.config.debug.enabled = true
59
+ VerifyKit.config.api_version = 'v1.0'
60
+ ```
61
+
62
+ ### Client
63
+
64
+ ```ruby
65
+ # you can create a client instance with default configuration
66
+ client = VerifyKit::Client.new
67
+
68
+ # or you can create a client instance with custom configuration
69
+ client = VerifyKit::Client.new(server_key: 'your-server-key', api_version: 'v1.0')
70
+ ```
71
+
72
+ ### Verification
73
+
74
+ VerifyKit supports two verification methods: `sms` and `whatsapp`.
75
+
76
+ #### SMS Verification
77
+
78
+ Send a verification code to the phone number like this:
79
+
80
+ ```ruby
81
+ client = VerifyKit::Client.new
82
+
83
+ params = { phoneNumber: '555 555 55 55', countryCode: 'TR' }
84
+ query = { lang: 'tr' } # optional, default is 'en'
85
+
86
+ result = client.sms.send(params) # or client.sms.send(params, query)
87
+
88
+ if result.success?
89
+ success_response = result.success
90
+ # success_response is a VerifyKit::Response::Success instance
91
+
92
+ # do something
93
+ else
94
+ error_response = result.failure
95
+ # error_response is a VerifyKit::Response::Error instance
96
+
97
+ # do something
98
+ end
99
+ ```
100
+
101
+ Check the verification code like this:
102
+
103
+ ```ruby
104
+ client = VerifyKit::Client.new
105
+
106
+ params = { phoneNumber: '554 597 46 46',
107
+ countryCode: 'TR',
108
+ reference: 'reference code',
109
+ code: 'verification code' }
110
+ query = { lang: 'tr' } # optional, default is 'en'
111
+
112
+ result = client.sms.check(params) # or client.sms.check(params, query)
113
+
114
+ if result.success?
115
+ success_response = result.success
116
+ # success_response is a VerifyKit::Response::Success instance
117
+
118
+ # do something
119
+ else
120
+ error_response = result.failure
121
+ # error_response is a VerifyKit::Response::Error instance
122
+
123
+ # do something
124
+ end
125
+ ```
126
+
127
+ #### WhatsApp Verification
128
+
129
+ Send a verification code to the phone number like this:
130
+
131
+ ```ruby
132
+ client = VerifyKit::Client.new
133
+
134
+ params = { phoneNumber: '555 555 55 55', countryCode: 'TR' }
135
+ query = { lang: 'tr' } # optional, default is 'en'
136
+
137
+ result = client.whatsapp.send(params) # or client.whatsapp.send(params, query)
138
+
139
+ if result.success?
140
+ success_response = result.success
141
+ # success_response is a VerifyKit::Response::Success instance
142
+
143
+ # do something
144
+ else
145
+ error_response = result.failure
146
+ # error_response is a VerifyKit::Response::Error instance
147
+
148
+ # do something
149
+ end
150
+ ```
151
+
152
+ Check the verification code like this:
153
+
154
+ ```ruby
155
+ client = VerifyKit::Client.new
156
+
157
+ params = { reference: 'reference code',
158
+ code: 'verification code' }
159
+ query = { lang: 'tr' } # optional, default is 'en'
160
+
161
+ result = client.whatsapp.check(params) # or client.whatsapp.check(params, query)
162
+
163
+ if result.success?
164
+ success_response = result.success
165
+ # success_response is a VerifyKit::Response::Success instance
166
+
167
+ # do something
168
+ else
169
+ error_response = result.failure
170
+ # error_response is a VerifyKit::Response::Error instance
171
+
172
+ # do something
173
+ end
174
+ ```
175
+
176
+ ### Response Objects
177
+
178
+ - [VerifyKit::Response::Success](lib/verify_kit/responses/success.rb)
179
+ - [VerifyKit::Response::Error](lib/verify_kit/responses/error.rb)
36
180
 
37
181
  ## Development
38
182
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module VerifyKit
6
+ class Client < Core::Service
7
+ BASE_URL = 'https://web-rest.verifykit.com'
8
+ SERVER_KEY_HEADER = 'X-Vfk-Server-Key'
9
+
10
+ option :server_key, type: Types::String | Types::Nil, default: proc { VerifyKit.config.server_key }
11
+ option :api_version, type: Types::String, default: proc { VerifyKit.config.api_version }
12
+ option :adapter, type: Types::Symbol, default: proc { Faraday.default_adapter }
13
+
14
+ def connection
15
+ @connection ||= Faraday.new(connection_url) do |conn|
16
+ conn.headers[SERVER_KEY_HEADER] = server_key
17
+ conn.request :json
18
+ conn.response :json, content_type: 'application/json'
19
+ conn.adapter adapter
20
+
21
+ if VerifyKit.config.debug.enabled
22
+ conn.response :logger, VerifyKit.config.logger, body: true,
23
+ bodies: { request: true, response: true }
24
+ end
25
+ end
26
+ end
27
+
28
+ def sms
29
+ VerifyKit::Resources::SMS.new(self)
30
+ end
31
+
32
+ def whatsapp
33
+ VerifyKit::Resources::WhatsApp.new(self)
34
+ end
35
+
36
+ private
37
+
38
+ def connection_url
39
+ BASE_URL + "/#{api_version}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+ require 'dry/monads/all'
5
+
6
+ module VerifyKit
7
+ module Core
8
+ class Service
9
+ extend Dry::Initializer
10
+
11
+ include Dry::Monads
12
+ include Dry::Monads::Do
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyKit
4
+ module Resources
5
+ class Base < Core::Service
6
+ param :client, type: Types.Instance(VerifyKit::Client)
7
+ option :connection, type: Types.Instance(Faraday::Connection), default: proc { client.connection }
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {}, params: {})
16
+ connection.post(url, body, headers) do |req|
17
+ req.params = params
18
+ end
19
+ end
20
+
21
+ def patch_request(url, body:, headers: {})
22
+ connection.patch(url, body, headers)
23
+ end
24
+
25
+ def put_request(url, body:, headers: {})
26
+ connection.put(url, body, headers)
27
+ end
28
+
29
+ def delete_request(url, params: {}, headers: {})
30
+ client.connection.delete(url, params, headers)
31
+ end
32
+
33
+ def error_response(response)
34
+ error_response = VerifyKit::Responses::Error.new(response.body)
35
+ Failure(error_response)
36
+ end
37
+
38
+ def success_response(response)
39
+ success_response = VerifyKit::Responses::Success.new(response.body)
40
+ Success(success_response)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyKit
4
+ module Resources
5
+ class SMS < VerifyKit::Resources::Base
6
+ def send(body = {}, params = {})
7
+ response = post_request('send-otp', body: body, params: params)
8
+ return error_response(response) unless response.success?
9
+
10
+ success_response(response)
11
+ end
12
+
13
+ def check(body = {}, params = {})
14
+ response = post_request('check-otp', body: body, params: params)
15
+ return error_response(response) unless response.success?
16
+
17
+ success_response(response)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyKit
4
+ module Resources
5
+ class WhatsApp < VerifyKit::Resources::Base
6
+ def send(body = {}, params = {})
7
+ body[:app] = 'whatsapp'
8
+
9
+ response = post_request('start', body: body, params: params)
10
+ return error_response(response) unless response.success?
11
+
12
+ success_response(response)
13
+ end
14
+
15
+ def check(body = {}, params = {})
16
+ response = post_request('check-whatsapp', body: body, params: params)
17
+ return error_response(response) unless response.success?
18
+
19
+ success_response(response)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module VerifyKit
6
+ module Responses
7
+ class Base < Dry::Struct
8
+ transform_keys(&:to_sym)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyKit
4
+ module Responses
5
+ class Error < VerifyKit::Responses::Base
6
+ attribute :meta, Types::Hash
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyKit
4
+ module Responses
5
+ class Success < VerifyKit::Responses::Base
6
+ attribute :meta, Types::Hash
7
+ attribute :result, Types::Hash
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-types'
4
+
5
+ module VerifyKit
6
+ module Types
7
+ include Dry::Types()
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VerifyKit
4
- VERSION = '0.0.0'
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/verify_kit.rb CHANGED
@@ -1,8 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'verify_kit/version'
3
+ require 'zeitwerk'
4
+ require 'logger'
5
+ require 'dry-configurable'
6
+ require 'dry/configurable/test_interface'
7
+
8
+ loader = Zeitwerk::Loader.for_gem.tap do |l|
9
+ l.inflector.inflect(
10
+ 'sms' => 'SMS',
11
+ 'Sms' => 'SMS',
12
+ 'whatsapp' => 'WhatsApp',
13
+ 'Whatsapp' => 'WhatsApp'
14
+ )
15
+ end
16
+
17
+ loader.setup
4
18
 
5
19
  module VerifyKit
6
- class Error < StandardError; end
7
- # Your code goes here...
20
+ extend Dry::Configurable
21
+
22
+ enable_test_interface
23
+
24
+ setting :server_key, default: nil, reader: true
25
+ setting :api_version, default: 'v1.0', reader: true
26
+ setting :logger, default: Logger.new($stdout), reader: true
27
+ setting :debug do
28
+ setting :enabled, default: false, reader: true
29
+ end
8
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verifykit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nejdetkadir
@@ -9,7 +9,135 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2023-05-09 00:00:00.000000000 Z
12
- dependencies: []
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: '2.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.7.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: dry-initializer
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: dry-monads
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.6'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.6'
67
+ - !ruby/object:Gem::Dependency
68
+ name: dry-struct
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.6'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.6'
81
+ - !ruby/object:Gem::Dependency
82
+ name: dry-types
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.7'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.7.1
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.7'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.7.1
101
+ - !ruby/object:Gem::Dependency
102
+ name: dry-configurable
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '1.0'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.1
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.0.1
121
+ - !ruby/object:Gem::Dependency
122
+ name: zeitwerk
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '2.6'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.8
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '2.6'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 2.6.8
13
141
  description: Ruby bindings for VerifyKit REST API. VerifyKit is a service that offers
14
142
  alternative channels alongside SMS for phone number verification and it enables
15
143
  your users to log in or sign up to your apps quickly.
@@ -29,6 +157,15 @@ files:
29
157
  - Rakefile
30
158
  - docs/cover.png
31
159
  - lib/verify_kit.rb
160
+ - lib/verify_kit/client.rb
161
+ - lib/verify_kit/core/service.rb
162
+ - lib/verify_kit/resources/base.rb
163
+ - lib/verify_kit/resources/sms.rb
164
+ - lib/verify_kit/resources/whatsapp.rb
165
+ - lib/verify_kit/responses/base.rb
166
+ - lib/verify_kit/responses/error.rb
167
+ - lib/verify_kit/responses/success.rb
168
+ - lib/verify_kit/types.rb
32
169
  - lib/verify_kit/version.rb
33
170
  - sig/verifykit.rbs
34
171
  homepage: https://github.com/nejdetkadir/verifykit