lmb-developers 1.2.7 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e64458ffec1b4d3c2bd34a026a8152dc28f3b19d063602d926e2120a0fc44c15
4
- data.tar.gz: 916703f62987d556140d27606fe006e4acce6d39a66006dd9b20f1ed1f7c03fe
3
+ metadata.gz: 905ee8df8f98770914ccd0ccb57b189bfa4ac88bc1c6a2442030322199e86c59
4
+ data.tar.gz: c0997d3bf1170b44ded8402ca6fc1ce5deb7b11ffdb12863697c8b69ff677035
5
5
  SHA512:
6
- metadata.gz: 876277b942a54431d5573fb9a0dd396be90a4fec5e8cfb7e3364f4f69bb44bfd59108fd161333cfbf5601f9d97cd901d0dd66c65152f0c91919ddb1eb3206842
7
- data.tar.gz: eebd7d1d7fa5839b2f62a8d839d981a0fbe2f1fb065f812a2fd9180a7642f76ded5abfc019c724bf98c752fdfd222bb3cf8b2020f481cd57b1d48f9fd05b36c0
6
+ metadata.gz: b013245670313eb06f8783c050fbd6fbdc7f368a469b67add904d53196c2faeb3219e965fd85db75a5db449532686d0c18e6ca4e5d1e28a08340b7a1aaa21399
7
+ data.tar.gz: ff968a11436f26bd82a86785abf8596aec91e2dc8d4b589f73b77d8283ddca4a807fb7448f7106b899f233e099db5a8726a9800a36ad86a55c6156fa64fa6d3c
@@ -2,6 +2,8 @@ module Lmb
2
2
  module Developers
3
3
  class Configuration
4
4
  attr_accessor :api_key,
5
+ :username,
6
+ :password
5
7
  :environment
6
8
  attr_reader :url
7
9
 
@@ -22,11 +24,15 @@ module Lmb
22
24
  end
23
25
  # Configure global parameters
24
26
  #
25
- # @param environment [String] environment to consume APIs, `TEST` or `PROD`
27
+ # @param environment [String] environment to consume APIs, `DEV`, `TEST` or `PROD`
26
28
  # @param api_key [String] ApiKey to consume APIs.
29
+ # @param username [String] Username to consume APIs.
30
+ # @param password [String] Password to consume APIs.
27
31
  # @return [Lmb::Developers::Configuration]
28
- def configure(environment = 'DEV', api_key)
32
+ def configure(environment = 'DEV', api_key = 'api_key', username = 'username', password = 'password')
29
33
  @api_key = api_key
34
+ @username = username
35
+ @password = password
30
36
  @environment = environment
31
37
  @url = @config[environment][:url]
32
38
  self
@@ -1,100 +1,83 @@
1
+ require 'base64'
2
+
1
3
  module Lmb
2
4
  module Developers
3
5
  class Loyalty
4
6
  attr_reader :configuration
5
7
 
6
- # Paths to methods
8
+ # Define constant paths for different API endpoints.
7
9
  VOUCHER_EXPIRED_PATH = '/v1/loyalty/voucher/expired'.freeze
8
10
  VOUCHER_PROVISIONED_PATH = '/v1/loyalty/voucher/provisioned'.freeze
9
11
  VOUCHER_ACTIVATED_PATH = '/v1/loyalty/voucher/activated'.freeze
10
12
  SCORING_REDEMPTION_PATH = '/v1/loyalty/redemption'.freeze
11
13
 
12
- # Set Inhabitant's Expired Vouchers.
14
+ # Set expired vouchers for inhabitants.
13
15
  #
14
- # @param expirations [Hash] the expriations object.
15
- # @return [Boolean]
16
+ # @param expirations [Hash] the expirations object.
17
+ # @return [Boolean] returns true if response code is 202, false otherwise.
16
18
  def self.voucher_expired(expirations)
17
- uri = URI.parse("#{configuration.url}#{VOUCHER_EXPIRED_PATH}")
18
- request = Net::HTTP::Post.new(uri)
19
- request['Apikey'] = configuration.api_key.to_s
20
- request['Cache-Control'] = 'no-cache'
21
- request.body = JSON.dump(
22
- 'expirations' => expirations
23
- )
24
- req_options = {
25
- use_ssl: uri.scheme == 'https'
26
- }
27
- response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
28
- http.request(request)
29
- end
30
- response.code.to_i == 202
31
- rescue StandardError => exception
32
- exception
19
+ post_request(VOUCHER_EXPIRED_PATH, 'expirations' => expirations)
33
20
  end
34
21
 
35
- # Set Inhabitant's Provisioned Vouchers.
22
+ # Set provisioned vouchers for inhabitants.
36
23
  #
37
- # @param expirations [Hash] the provisions object.
38
- # @return [Boolean]
24
+ # @param provisions [Hash] the provisions object.
25
+ # @return [Boolean] returns true if response code is 202, false otherwise.
39
26
  def self.voucher_provisioned(provisions)
40
- uri = URI.parse("#{configuration.url}#{VOUCHER_PROVISIONED_PATH}")
41
- request = Net::HTTP::Post.new(uri)
42
- request['Apikey'] = configuration.api_key.to_s
43
- request['Cache-Control'] = 'no-cache'
44
- request.body = JSON.dump(
45
- 'provisions' => provisions
46
- )
47
- req_options = {
48
- use_ssl: uri.scheme == 'https'
49
- }
50
- response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
51
- http.request(request)
52
- end
53
- response.code.to_i == 202
54
- rescue StandardError => exception
55
- exception
27
+ post_request(VOUCHER_PROVISIONED_PATH, 'provisions' => provisions)
56
28
  end
57
29
 
58
- # Set Inhabitant's Activated Vouchers.
30
+ # Set activated vouchers for inhabitants.
59
31
  #
60
- # @param expirations [Hash] the activations object.
61
- # @return [Boolean]
32
+ # @param activations [Hash] the activations object.
33
+ # @return [Boolean] returns true if response code is 202, false otherwise.
62
34
  def self.voucher_activated(activations)
63
- uri = URI.parse("#{configuration.url}#{VOUCHER_ACTIVATED_PATH}")
64
- request = Net::HTTP::Post.new(uri)
65
- request['Apikey'] = configuration.api_key.to_s
66
- request['Cache-Control'] = 'no-cache'
67
- request.body = JSON.dump(
68
- 'activations' => activations
69
- )
70
- req_options = {
71
- use_ssl: uri.scheme == 'https'
72
- }
73
- response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
74
- http.request(request)
75
- end
76
- response.code.to_i == 202
77
- rescue StandardError => exception
78
- exception
35
+ post_request(VOUCHER_ACTIVATED_PATH, 'activations' => activations)
36
+ end
37
+
38
+ # Handles the redemption process.
39
+ #
40
+ # @param redemptions [Hash] the redemptions object.
41
+ # @return [Boolean] returns true if response code is 202, false otherwise.
42
+ def self.redemption(redemptions)
43
+ post_request(SCORING_REDEMPTION_PATH, redemptions)
44
+ end
45
+
46
+ private
47
+
48
+ # Generate Basic Authorization header from configuration's username and password.
49
+ #
50
+ # @return [String] returns the Authorization header string.
51
+ def self.generate_basic_auth
52
+ base64_encoded_credentials = Base64.encode64("#{configuration.username.to_s}:#{configuration.password.to_s}").strip
53
+ "Basic #{base64_encoded_credentials}"
79
54
  end
80
55
 
81
- # Get configuration.
56
+ # Fetch the configuration for the API.
57
+ #
58
+ # @return [Object] returns the configuration object.
82
59
  def self.configuration
83
- @configuration = Lmb::Developers.configuration
60
+ @configuration ||= Lmb::Developers.configuration
84
61
  end
85
62
 
86
- def self.redemption(redemptions)
87
- uri = URI.parse("#{configuration.url}#{SCORING_REDEMPTION_PATH}")
63
+ # Makes a POST request to a given endpoint with provided body.
64
+ #
65
+ # @param endpoint [String] the API endpoint.
66
+ # @param body [Hash] the request body.
67
+ # @return [Boolean] returns true if response code is 202, false otherwise.
68
+ def self.post_request(endpoint, body)
69
+ uri = URI.parse("#{configuration.url}#{endpoint}")
88
70
  request = Net::HTTP::Post.new(uri)
89
71
  request['Apikey'] = configuration.api_key.to_s
72
+ request['Authorization'] = generate_basic_auth
90
73
  request['Cache-Control'] = 'no-cache'
91
- request.body = redemptions.to_json
92
- req_options = {
93
- use_ssl: uri.scheme == 'https'
94
- }
74
+ request.body = body.to_json
75
+ req_options = { use_ssl: uri.scheme == 'https' }
76
+
95
77
  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
96
78
  http.request(request)
97
79
  end
80
+
98
81
  response.code.to_i == 202
99
82
  rescue StandardError => exception
100
83
  exception
@@ -11,11 +11,13 @@ module Lmb
11
11
 
12
12
  # Configure global parameters
13
13
  #
14
- # @param environment [String] environment to consume APIs, `TEST` or `PROD`
14
+ # @param environment [String] environment to consume APIs, `DEV`, `TEST` or `PROD`
15
15
  # @param api_key [String] ApiKey to consume APIs.
16
+ # @param username [String] Username to consume APIs.
17
+ # @param password [String] Password to consume APIs.
16
18
  # @return [Lmb::Developers::Configuration]
17
- def configure(environment, api_key)
18
- configuration.configure(environment, api_key)
19
+ def configure(environment = "DEV", api_key = "apikey", username = "username", password = "password")
20
+ configuration.configure(environment, api_key, username, password)
19
21
  end
20
22
 
21
23
  # Instace or return global configuration
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'lmb-developers'
3
- s.version = '1.2.7'
4
- s.date = '2019-05-19'
3
+ s.version = '1.3.0'
4
+ s.date = '2023-09-25'
5
5
  s.summary = "Consume APIs at Leroy Merlin Brazil Developer's Portal"
6
6
  s.description = "Gem to consume APIs available at Leroy Merlin Brazil Developer's Portal https://developers.leroymerlin.com.br"
7
7
  s.author = "PRTE - Tecnologia e Soluções"
@@ -9,6 +9,6 @@ Gem::Specification.new do |s|
9
9
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
10
10
  s.require_paths = ['lib']
11
11
  s.homepage =
12
- 'https://github.com/somosprte/lmb-developers'
12
+ 'https://github.com/adeo/brlm-loyalty-developers-gem'
13
13
  s.license = 'MIT'
14
14
  end
data/product-info.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+
3
+ "tangram_id": "d0365f9c-d399-453e-867b-084eea99a10a"
4
+
5
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lmb-developers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PRTE - Tecnologia e Soluções
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-19 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem to consume APIs available at Leroy Merlin Brazil Developer's Portal
14
14
  https://developers.leroymerlin.com.br
@@ -29,7 +29,8 @@ files:
29
29
  - lib/lmb/developers/error.rb
30
30
  - lib/lmb/developers/loyalty.rb
31
31
  - lmb-developers.gemspec
32
- homepage: https://github.com/somosprte/lmb-developers
32
+ - product-info.json
33
+ homepage: https://github.com/adeo/brlm-loyalty-developers-gem
33
34
  licenses:
34
35
  - MIT
35
36
  metadata: {}
@@ -48,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  requirements: []
51
- rubygems_version: 3.1.2
52
+ rubygems_version: 3.4.10
52
53
  signing_key:
53
54
  specification_version: 4
54
55
  summary: Consume APIs at Leroy Merlin Brazil Developer's Portal