lmb-developers 1.1.2 → 1.2.3

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: ca4a980414d934e35a3abb1eda08230e0aaf3686c4e15da8a937f813c4ff2e2a
4
- data.tar.gz: 73dae7b30f033de9c07dfac6c3b4ed75063fca95ac1a4eb352ec1a2453c0c8c0
3
+ metadata.gz: 9466a7817868f2c4a29301a99f34a881575fd1eb52559b087c6520136cd293cf
4
+ data.tar.gz: be1c41758fcd5f3568a1451f60a4d70a52e2decf1fbce9946ea37d41faf50b35
5
5
  SHA512:
6
- metadata.gz: 3daaa7854edbd80ff5facac95814888f7ef91d5574bf339371cada016b224fcf23512800a750db8a5bc77028fc7bd3492ecae37985aa83e2515ff49b1e0244bc
7
- data.tar.gz: 705cca1029bba160ccb4db98a5b64ba9cb227599d3d56657af919bfb0bf2428e0d1516527cfb941235f4ef0ab5ef50a1f6d921fa5299658427979ede9adc6eae
6
+ metadata.gz: 28801e5ec6aadc1cff1e83a0c9d51b35b22a68328f060c7ca862ef0b235c49aba5c6ce5932de5c36739c1f49bc197d232b221fc928825fe162e346fd1097677c
7
+ data.tar.gz: 479438e0752923d95162d094e0f59e24f5a3415213355f51d75fcb4e471276cf6e6fa7ae45c078fb870578db1ca281a1fd8908c1d3f235fc2104b9bc23729015
@@ -0,0 +1,20 @@
1
+ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/ruby/.devcontainer/base.Dockerfile
2
+
3
+ # [Choice] Ruby version: 3, 3.0, 2, 2.7, 2.6
4
+ ARG VARIANT="3.0"
5
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
6
+
7
+ # [Option] Install Node.js
8
+ ARG INSTALL_NODE="true"
9
+ ARG NODE_VERSION="lts/*"
10
+ RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
11
+
12
+ # [Optional] Uncomment this section to install additional OS packages.
13
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
14
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
15
+
16
+ # [Optional] Uncomment this line to install additional gems.
17
+ # RUN gem install <your-gem-names-here>
18
+
19
+ # [Optional] Uncomment this line to install global node packages.
20
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,33 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/ruby
3
+ {
4
+ "name": "Ruby",
5
+ "build": {
6
+ "dockerfile": "Dockerfile",
7
+ "args": {
8
+ // Update 'VARIANT' to pick a Ruby version: 3, 3.0, 2, 2.7, 2.6
9
+ "VARIANT": "3",
10
+ // Options
11
+ "INSTALL_NODE": "false",
12
+ "NODE_VERSION": "lts/*"
13
+ }
14
+ },
15
+
16
+ // Set *default* container specific settings.json values on container create.
17
+ "settings": {},
18
+
19
+ // Add the IDs of extensions you want installed when the container is created.
20
+ "extensions": [
21
+ "rebornix.Ruby"
22
+ ],
23
+
24
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
25
+ // "forwardPorts": [],
26
+
27
+ // Use 'postCreateCommand' to run commands after the container is created.
28
+ // "postCreateCommand": "ruby --version",
29
+
30
+ // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
31
+ "remoteUser": "vscode"
32
+
33
+ }
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/lmb-developers.svg)](http://badge.fury.io/rb/lmb-developers)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/379c8d6d26abf532b045/maintainability)](https://codeclimate.com/github/somosprte/lmb-developers/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/379c8d6d26abf532b045/test_coverage)](https://codeclimate.com/github/somosprte/lmb-developers/test_coverage)
2
4
 
3
5
  # Lmb Developers
4
6
 
@@ -24,16 +26,32 @@ Or install it yourself as:
24
26
 
25
27
  ### Configuration
26
28
 
29
+ To use the terminal use the following command:
30
+
31
+ $ irb -Ilib -rlmb/developers
32
+
27
33
  ```ruby
28
34
 
29
- # Pass environment and api_key to configure
30
- Lmb::Developers.configure('environment', 'api_key')
35
+ # Pass environment and api_key to configure. Note: Use ENV variables to protect data in production environment
36
+ Lmb::Developers.configure('environment', ENV['LMB_API_KEY'])
31
37
 
32
38
  ```
33
39
 
34
40
  The environment can be 'TEST' or 'PROD'.
35
41
 
36
- You will need an api_key that can be obtained at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
42
+ You will need an API KEY that can be obtained at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
43
+
44
+ ### Example
45
+
46
+ ```ruby
47
+
48
+ #config/initilizers/lmb_developers.rb
49
+ Lmb::Developers.configure('DEV', ENV['LMB_API_KEY'])
50
+
51
+ #app/controller/login.rb
52
+ Lmb::Developers::Auth.login("ldap_username", "ldap_password")
53
+
54
+ ```
37
55
 
38
56
  ### Methods
39
57
 
@@ -45,7 +63,7 @@ Lmb::Developers::Auth.login("ldap_username", "ldap_password", "ldap_usertype = e
45
63
 
46
64
  ## Contributing
47
65
 
48
- 1. Fork it ( https://github.com/[my-github-username]/lmb-developers/fork )
66
+ 1. Fork it ( https://github.com/somosprte/lmb-developers/fork )
49
67
  2. Create your feature branch (`git checkout -b my-new-feature`)
50
68
  3. Commit your changes (`git commit -am 'Add some feature'`)
51
69
  4. Push to the branch (`git push origin my-new-feature`)
@@ -2,6 +2,7 @@ require 'net/http'
2
2
  require 'json'
3
3
  require 'lmb/developers/configuration'
4
4
  require 'lmb/developers/auth'
5
+ require 'lmb/developers/loyalty'
5
6
  require 'lmb/developers/error'
6
7
  module Lmb
7
8
  module Developers
@@ -8,21 +8,24 @@ module Lmb
8
8
  # Initial config.
9
9
  def initialize
10
10
  @config = {
11
+ 'DEV' => {
12
+ 'url': 'https://api-dev.leroymerlin.com.br'
13
+ },
11
14
  'TEST' => {
12
15
  'url': 'https://api-test.leroymerlin.com.br'
13
16
  },
14
17
  'PROD' => {
15
- 'url' => 'https://api.leroymerlin.com.br',
18
+ 'url': 'https://api.leroymerlin.com.br'
16
19
  }
17
20
  }
18
- configure('TEST', nil)
21
+ configure('DEV', nil)
19
22
  end
20
23
  # Configure global parameters
21
24
  #
22
25
  # @param environment [String] environment to consume APIs, `TEST` or `PROD`
23
26
  # @param api_key [String] ApiKey to consume APIs.
24
27
  # @return [Lmb::Developers::Configuration]
25
- def configure(environment = 'TEST', api_key)
28
+ def configure(environment = 'DEV', api_key)
26
29
  @api_key = api_key
27
30
  @environment = environment
28
31
  @url = @config[environment][:url]
@@ -0,0 +1,104 @@
1
+ module Lmb
2
+ module Developers
3
+ class Loyalty
4
+ attr_reader :configuration
5
+
6
+ # Paths to methods
7
+ VOUCHER_EXPIRED_PATH = '/v1/loyalty/voucher/expired'.freeze
8
+ VOUCHER_PROVISIONED_PATH = '/v1/loyalty/voucher/provisioned'.freeze
9
+ VOUCHER_ACTIVATED_PATH = '/v1/loyalty/voucher/activated'.freeze
10
+ SCORING_REDEMPTION_PATH = '/v1/loyalty/redemption'.freeze
11
+
12
+ # Set Inhabitant's Expired Vouchers.
13
+ #
14
+ # @param expirations [Hash] the expriations object.
15
+ # @return [Boolean]
16
+ 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
33
+ end
34
+
35
+ # Set Inhabitant's Provisioned Vouchers.
36
+ #
37
+ # @param expirations [Hash] the provisions object.
38
+ # @return [Boolean]
39
+ 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
56
+ end
57
+
58
+ # Set Inhabitant's Activated Vouchers.
59
+ #
60
+ # @param expirations [Hash] the activations object.
61
+ # @return [Boolean]
62
+ 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
79
+ end
80
+
81
+ # Get configuration.
82
+ def self.configuration
83
+ @configuration = Lmb::Developers.configuration
84
+ end
85
+
86
+ def self.redemption(redemptions)
87
+ uri = URI.parse("#{configuration.url}#{SCORING_REDEMPTION_PATH}")
88
+ request = Net::HTTP::Post.new(uri)
89
+ request['Apikey'] = configuration.api_key.to_s
90
+ request['Cache-Control'] = 'no-cache'
91
+ request.body = redemptions
92
+ req_options = {
93
+ use_ssl: uri.scheme == 'https'
94
+ }
95
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
96
+ http.request(request)
97
+ end
98
+ response.code.to_i == 202
99
+ rescue StandardError => exception
100
+ exception
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'lmb-developers'
3
- s.version = '1.1.2'
4
- s.date = '2019-01-10'
3
+ s.version = '1.2.3'
4
+ s.date = '2019-05-19'
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"
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.1.2
4
+ version: 1.2.3
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-01-10 00:00:00.000000000 Z
11
+ date: 2019-05-19 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
@@ -17,6 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".devcontainer/Dockerfile"
21
+ - ".devcontainer/devcontainer.json"
20
22
  - ".gitignore"
21
23
  - README.md
22
24
  - Rakefile
@@ -25,6 +27,7 @@ files:
25
27
  - lib/lmb/developers/auth.rb
26
28
  - lib/lmb/developers/configuration.rb
27
29
  - lib/lmb/developers/error.rb
30
+ - lib/lmb/developers/loyalty.rb
28
31
  - lmb-developers.gemspec
29
32
  homepage: https://github.com/somosprte/lmb-developers
30
33
  licenses:
@@ -45,8 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
48
  - !ruby/object:Gem::Version
46
49
  version: '0'
47
50
  requirements: []
48
- rubyforge_project:
49
- rubygems_version: 2.7.8
51
+ rubygems_version: 3.1.2
50
52
  signing_key:
51
53
  specification_version: 4
52
54
  summary: Consume APIs at Leroy Merlin Brazil Developer's Portal