bigid_auth 0.1.1 → 0.2.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: 7f45c2559c85156c23be8006c158e2d2ad481f24df3b249492e91bc78ce98bbc
4
- data.tar.gz: f5960d62a9124cdadf99b259775e90249d0e4e4d629f1a6f38ca9ebd17f337ff
3
+ metadata.gz: 7cae484adde1a8537c29863c0ec2eaf28dd89632a95605c8120546b8b7a5b6b0
4
+ data.tar.gz: ad11c04490bbd147bf9ebe570ec3fa53d7451f175b7197430cb7aa6001b48527
5
5
  SHA512:
6
- metadata.gz: a51b222efcc1a2d424473b6bb4ee0ddb59fd27a2f5fef7d52d2575285ddff408f538481cf2986a32fbb0b69553fd898ed567e9986e9dcc9b8cd4268aea976e09
7
- data.tar.gz: 77071623167b535be8197fecd123bc102a4dc015620f2e1f334efaac59bf1a691e85326ec04ee6fb7a4cbe2b9b8a2df3b585c2359400ba827551036822340cc8
6
+ metadata.gz: e4ef820360f66f94daf90d523bf150aaea64552c1421e8408cbd0cecf828c68284ecbed699d6daea57f5d06d00302da35c9654c9110a4ed7b8abf2cdb153dde9
7
+ data.tar.gz: 42a4c5181bd9692faa5f64bf56840e57f9671e0cec05090fe88022a4e29c79db91d874f60bdc67622c86b0dc3aa86ea43586a7171c2c3244843ea85f4154031b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.2.0
4
+
5
+ * Use the gem "flash_integration" to retrieve a connection
6
+
3
7
  ## v0.1.1
4
8
 
5
9
  * Fix a problem with the locale initialization in Rails projects
data/README.md CHANGED
@@ -3,6 +3,7 @@ BigId Auth's Library for Ruby
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/bigid_auth.svg)](https://badge.fury.io/rb/bigid_auth)
5
5
  [![Build Status](https://travis-ci.com/Quasar-Flash/bigid-auth-ruby.svg?branch=master)](https://travis-ci.com/Quasar-Flash/bigid-auth-ruby)
6
+ [![bigid_auth](https://github.com/Quasar-Flash/bigid-auth-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/Quasar-Flash/bigid-auth-ruby/actions/workflows/ruby.yml)
6
7
 
7
8
  Dev Requirements
8
9
  -----------------
@@ -13,76 +14,97 @@ Dev Requirements
13
14
  Global Installation
14
15
  -----------------
15
16
 
16
- gem install bigid_auth
17
+ ```ruby
18
+ gem install bigid_auth
19
+ ```
17
20
 
18
21
  Installation for Rails
19
22
  -----------------
20
23
 
21
- # Add to the Gemfile
22
- gem 'bigid_auth', '~> 0.1.0'
23
-
24
- Setting the BigID credentials
25
- -----------------
26
-
27
- # Set the env variables
28
- ENV['BIGID_USERNAME'] = 'your_username'
29
- ENV['BIGID_PASSWORD'] = 'your_password'
24
+ ```ruby
25
+ # Add to the Gemfile
26
+ gem "bigid_auth", '~> 0.1.0'
27
+ ```
30
28
 
31
29
  Setting the BigID credentials - Rails Project
32
30
  -----------------
33
31
 
34
32
  Create the config/initializers/bigid.rb file and define:
35
33
 
36
- # Set the env variables
37
- Bigid.configure do |config|
38
- config.username = 'your_username'
39
- config.password = 'your_password'
40
- end
34
+ ```ruby
35
+ # Set the env variables
36
+ Bigid.configure do |config|
37
+ config.username = 'JHONNY.MUNIS@QFLASH.COM.BR'
38
+ config.password = 'crtvreru'
39
+ end
40
+ ```
41
41
 
42
42
  Applying an authentication
43
43
  -----------------
44
44
 
45
- require 'bigid_auth'
45
+ ```ruby
46
+ require 'bigid_auth'
46
47
 
47
- auth = Bigid::Auth::Authentication.new
48
- auth.login
48
+ Bigid::Auth::Authentication.new.login
49
+ ```
49
50
 
50
51
  Result Example
51
52
  -----------------
52
53
 
53
- #<Bigid::Auth::Integration::Response:0x0000564181d2bef0
54
- @request=#<Bigid::Auth::Integration::Request:0x0000564181d76a18
55
- @method=:post,
56
- @url="https://accesstoken.bigdatacorp.com.br/Generate",
57
- @params={},
58
- @headers={:"Content-Type"=>"application/json", :Accept=>"application/json"},
59
- @body="{\"login\":\"username\",\"password\":\"crtvreru\",\"expires\":60000}",
60
- @time=2021-04-18 18:55:24.678349974 UTC>,
61
- @status=200,
62
- @body="{\"expiration\":\"Mon, 21 Feb 2028 18:55:24 GMT\",\"message\":\"Token Generated\",\"success\":true,\"token\":\"xxxxxxxxxxxx\",\"tokenID\":\"0000000000\"}\n", @time=2021-04-18 18:55:24.995163484 UTC>
54
+ ```ruby
55
+ <Flash::Integration::Response:xxxx
56
+ @request=<Flash::Integration::Request:xxx
57
+ @method = :post,
58
+ @url = "https://accesstoken.bigdatacorp.com.br/Generate",
59
+ @params = {},
60
+ @headers = {
61
+ :"Content-Type" => "application/json",
62
+ :Accept => "application/json"
63
+ },
64
+ @body = "{\"login\":\"email@email.com\",\"password\":\"xxxxxx\",\"expires\":60000}",
65
+ @time = 2021-07-21 22:49:57.869382432 UTC>,
66
+ @status = 200,
67
+ @headers = {
68
+ "content-type" => "application/json",
69
+ "content-length" => "361",
70
+ "connection" => "keep-alive",
71
+ "date" => "Wed, 21 Jul 2021 22:49:58 GMT"
72
+ },
73
+ @body="{\"expiration\":\"Thu, 25 May 2028 22:49:58 GMT\",\"message\":\"Token Generated\",\"success\":true,\"token\":\"xxx\",\"tokenID\":\"xxx\"}\n",
74
+ @time=2021-07-21 22:49:58.248277077 UTC>
75
+
76
+ ```
63
77
 
64
78
  Problems?
65
79
  -----------------
66
80
 
67
- **Please do not directly email any committers with questions or problems.** A community is best served when discussions are held in public.
81
+ **Please do not directly email any committers with questions or problems.** A
82
+ community is best served when discussions are held in public.
68
83
 
69
- Searching the [issues](https://github.com/Quasar-Flash/bigid-auth-ruby/issues) for your problem is also a good idea.
84
+ Searching the [issues](https://github.com/Quasar-Flash/bigid-auth-ruby/issues)
85
+ for your problem is also a good idea.
70
86
 
71
87
  Contributing
72
88
  -----------------
73
89
 
74
- - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet;
75
- - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it;
90
+ - Check out the latest master to make sure the feature hasn't been implemented
91
+ or the bug hasn't been fixed yet;
92
+ - Check out the issue tracker to make sure someone already hasn't requested it
93
+ and/or contributed it;
76
94
  - Fork the project;
77
95
  - Start a feature/bugfix branch;
78
96
  - Commit and push until you are happy with your contribution;
79
- - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.;
80
- - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
97
+ - Make sure to add tests for it. This is important so I don't break it in a
98
+ future version unintentionally.;
99
+ - Please try not to mess with the Rakefile, version, or history. If you want to
100
+ have your own version, or is otherwise necessary, that is fine, but please
101
+ isolate to its own commit so I can cherry-pick around it.
81
102
 
82
103
  License
83
104
  -----------------
84
105
 
85
- Please see [LICENSE](https://github.com/Quasar-Flash/bigid-auth-ruby/blob/master/LICENSE.txt) for licensing details.
106
+ Please see [LICENSE](https://github.com/Quasar-Flash/bigid-auth-ruby/blob/master/LICENSE.txt)
107
+ for licensing details.
86
108
 
87
109
  Authors
88
110
  -----------------
data/Rakefile CHANGED
@@ -45,4 +45,4 @@ rescue LoadError
45
45
  # no rspec available
46
46
  end
47
47
 
48
- task default: %i[rubocop ]
48
+ task default: %i[rubocop spec]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bigid
4
4
  module Auth
5
- class Connection < Bigid::Auth::Integration::Connection
5
+ class Connection < Flash::Integration::Connection
6
6
  def initialize(request_class: Faraday, base_url: Bigid::Auth::AUTH_ENDPOINT)
7
7
  super(request_class: request_class, base_url: base_url)
8
8
  end
@@ -9,6 +9,6 @@ module Bigid
9
9
  # Major - Incremented for incompatible changes with previous release (or big enough new features)
10
10
  # Minor - Incremented for new backwards-compatible features + deprecations
11
11
  # Patch - Incremented for backwards-compatible bug fixes
12
- VERSION = "0.1.1"
12
+ VERSION = "0.2.0"
13
13
  end
14
14
  end
data/lib/bigid_auth.rb CHANGED
@@ -1,16 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
3
+ require "flash_integration"
4
4
  require "i18n"
5
5
  require "json"
6
6
 
7
7
  require "bigid/auth/version"
8
8
 
9
- require "bigid/auth/integration/multipart_flat"
10
- require "bigid/auth/integration/response"
11
- require "bigid/auth/integration/request"
12
- require "bigid/auth/integration/connection"
13
-
14
9
  require "bigid/auth/connection"
15
10
  require "bigid/auth/authentication"
16
11
  require "bigid/auth/authenticated_resource"
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
- require "bigid_auth"
5
4
 
6
5
  RSpec.describe Bigid::Auth do
7
6
  describe "AUTH_ENDPOINT" do
@@ -18,15 +17,15 @@ RSpec.describe Bigid::Auth do
18
17
 
19
18
  describe ".configure" do
20
19
  before do
21
- described_class.configuration = nil
20
+ Bigid.configuration = nil
22
21
  ENV.clear
23
22
  end
24
23
 
25
- subject { described_class.configuration }
24
+ subject { Bigid.configuration }
26
25
 
27
26
  context "when configuration is defined" do
28
27
  before do
29
- described_class.configure do |config|
28
+ Bigid.configure do |config|
30
29
  config.username = "username_value"
31
30
  config.password = "password_value"
32
31
  end
@@ -65,7 +64,7 @@ RSpec.describe Bigid::Auth do
65
64
  ENV["BIGID_USERNAME"] = "username_value"
66
65
  ENV["BIGID_PASSWORD"] = "password_value"
67
66
 
68
- described_class.configure do |config|
67
+ Bigid.configure do |config|
69
68
  config.username = "username_value2"
70
69
  config.password = "password_value2"
71
70
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "simplecov"
4
+
5
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter]
6
+ SimpleCov.minimum_coverage 70.0
7
+
8
+ SimpleCov.start do
9
+ add_filter "/spec/"
10
+ minimum_coverage 70
11
+ minimum_coverage_by_file 40
12
+ end
13
+
3
14
  require "rubygems"
4
15
  require "bundler"
16
+ require "bigid_auth"
17
+ require "pry"
5
18
 
6
19
  begin
7
20
  Bundler.setup(:default, :development, :test)
@@ -12,14 +25,13 @@ rescue Bundler::BundlerError => e
12
25
  exit e.status_code
13
26
  end
14
27
 
15
- require "simplecov"
16
-
17
- SimpleCov.start do
18
- add_filter "spec"
19
- end
20
-
21
28
  RSpec.configure do |config|
22
- # some (optional) config here
29
+ # Enable flags like --only-failures and --next-failure
30
+ config.example_status_persistence_file_path = ".rspec_status"
31
+
32
+ config.expect_with :rspec do |c|
33
+ c.syntax = :expect
34
+ end
23
35
  end
24
36
 
25
37
  # minitest/mock # Uncomment me to use minitest mocks
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigid_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Carolino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: flash_integration
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.1
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: '1.0'
19
+ version: 0.1.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 1.4.1
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '1.0'
26
+ version: 0.1.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: i18n
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,14 +84,14 @@ dependencies:
90
84
  requirements:
91
85
  - - "~>"
92
86
  - !ruby/object:Gem::Version
93
- version: 6.1.0
87
+ version: 6.2.0
94
88
  type: :development
95
89
  prerelease: false
96
90
  version_requirements: !ruby/object:Gem::Requirement
97
91
  requirements:
98
92
  - - "~>"
99
93
  - !ruby/object:Gem::Version
100
- version: 6.1.0
94
+ version: 6.2.0
101
95
  - !ruby/object:Gem::Dependency
102
96
  name: gemsurance
103
97
  requirement: !ruby/object:Gem::Requirement
@@ -166,14 +160,14 @@ dependencies:
166
160
  requirements:
167
161
  - - "~>"
168
162
  - !ruby/object:Gem::Version
169
- version: 1.12.0
163
+ version: 1.18.3
170
164
  type: :development
171
165
  prerelease: false
172
166
  version_requirements: !ruby/object:Gem::Requirement
173
167
  requirements:
174
168
  - - "~>"
175
169
  - !ruby/object:Gem::Version
176
- version: 1.12.0
170
+ version: 1.18.3
177
171
  - !ruby/object:Gem::Dependency
178
172
  name: rubocop-packaging
179
173
  requirement: !ruby/object:Gem::Requirement
@@ -194,14 +188,14 @@ dependencies:
194
188
  requirements:
195
189
  - - "~>"
196
190
  - !ruby/object:Gem::Version
197
- version: 1.10.0
191
+ version: 1.11.4
198
192
  type: :development
199
193
  prerelease: false
200
194
  version_requirements: !ruby/object:Gem::Requirement
201
195
  requirements:
202
196
  - - "~>"
203
197
  - !ruby/object:Gem::Version
204
- version: 1.10.0
198
+ version: 1.11.4
205
199
  - !ruby/object:Gem::Dependency
206
200
  name: simplecov
207
201
  requirement: !ruby/object:Gem::Requirement
@@ -234,10 +228,6 @@ files:
234
228
  - lib/bigid/auth/bad_request_error.rb
235
229
  - lib/bigid/auth/base_error.rb
236
230
  - lib/bigid/auth/connection.rb
237
- - lib/bigid/auth/integration/connection.rb
238
- - lib/bigid/auth/integration/multipart_flat.rb
239
- - lib/bigid/auth/integration/request.rb
240
- - lib/bigid/auth/integration/response.rb
241
231
  - lib/bigid/auth/invalid_credentials_error.rb
242
232
  - lib/bigid/auth/server_error.rb
243
233
  - lib/bigid/auth/version.rb
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bigid
4
- module Auth
5
- module Integration
6
- class Connection
7
- attr_reader :base_url
8
-
9
- def initialize(base_url:, request_class: Faraday)
10
- @request_class = request_class
11
- @base_url = base_url
12
- end
13
-
14
- def get(url: "", params: {}, headers: {})
15
- send_request(
16
- method: :get,
17
- url: url,
18
- params: params,
19
- headers: headers
20
- )
21
- end
22
-
23
- def post(url: "", params: {}, headers: {}, body: {}, multipart: false)
24
- send_request(
25
- method: :post,
26
- url: url,
27
- params: params,
28
- headers: headers,
29
- body: body,
30
- multipart: multipart
31
- )
32
- end
33
-
34
- def put(url: "", params: {}, headers: {}, body: {})
35
- send_request(
36
- method: :put,
37
- url: url,
38
- params: params,
39
- headers: headers,
40
- body: body
41
- )
42
- end
43
-
44
- def patch(url: "", params: {}, headers: {}, body: {})
45
- send_request(
46
- method: :patch,
47
- url: url,
48
- params: params,
49
- headers: headers,
50
- body: body
51
- )
52
- end
53
-
54
- def delete(url: "", params: {}, headers: {}, body: {})
55
- send_request(
56
- method: :delete,
57
- url: url,
58
- params: params,
59
- headers: headers,
60
- body: body
61
- )
62
- end
63
-
64
- def default_headers
65
- {}
66
- end
67
-
68
- private
69
- def send_request(method:, url:, params:, headers:, body: nil, multipart: false)
70
- connection = multipart ? multipart_connection : @request_class.new(url: @base_url)
71
-
72
- merged_headers = default_headers.merge(headers)
73
-
74
- request = build_request(
75
- method, connection.build_url(url).to_s, params, merged_headers, body
76
- )
77
-
78
- result =
79
- connection.send(method) do |request|
80
- request.url(url)
81
- request.params = params
82
- request.headers = merged_headers
83
- request.body = body if body
84
- end
85
-
86
- build_response(request, result.status, result.headers, result.body)
87
- end
88
-
89
- def multipart_connection
90
- @request_class.new(url: @base_url) do |conn|
91
- conn.use Bigid::Auth::Integration::MultipartFlat
92
- conn.request :url_encoded
93
- conn.adapter @request_class.default_adapter
94
- end
95
- end
96
-
97
- def build_request(method, url, params, headers, body)
98
- Bigid::Auth::Integration::Request.new(
99
- method: method,
100
- url: url,
101
- params: params,
102
- headers: headers,
103
- body: body,
104
- time: Time.now.utc
105
- )
106
- end
107
-
108
- def build_response(request, status, headers, body)
109
- Bigid::Auth::Integration::Response.new(
110
- request: request,
111
- status: status,
112
- headers: headers,
113
- body: body,
114
- time: Time.now.utc
115
- )
116
- end
117
- end
118
- end
119
- end
120
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bigid
4
- module Auth
5
- module Integration
6
- class MultipartFlat < Faraday::Request::Multipart
7
- self.mime_type = "multipart/form-data"
8
- DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost" unless defined? DEFAULT_BOUNDARY_PREFIX
9
-
10
- def process_params(params, prefix = nil, pieces = nil, &block)
11
- params.inject(pieces || []) do |all, (key, value)|
12
- key = prefix.to_s if prefix
13
-
14
- case value
15
- when Array
16
- values = value.inject([]) { |a, v| a << [nil, v] }
17
- process_params(values, key, all, &block)
18
- when Hash
19
- process_params(value, key, all, &block)
20
- else
21
- all << block.call(key, value)
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bigid
4
- module Auth
5
- module Integration
6
- class Request
7
- attr_reader :method, :url, :params, :headers, :body, :time
8
-
9
- def initialize(attributes)
10
- @method = attributes.fetch(:method)
11
- @url = attributes.fetch(:url)
12
- @params = attributes[:params] || {}
13
- @headers = attributes[:headers] || {}
14
- @body = attributes[:body] || {}
15
- @time = attributes[:time] || Time.current
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bigid
4
- module Auth
5
- module Integration
6
- class Response
7
- attr_reader :request, :status, :headers, :body, :time
8
-
9
- def initialize(attributes)
10
- @request = attributes.fetch(:request)
11
- @status = attributes.fetch(:status)
12
- @headers = attributes[:headers] || {}
13
- @body = attributes[:body] || {}
14
- @time = attributes[:time] || Time.current
15
- end
16
-
17
- def success?
18
- @status.between?(200, 299)
19
- end
20
-
21
- def error?
22
- !success?
23
- end
24
- end
25
- end
26
- end
27
- end