lmb-developers 1.1.2 → 1.2.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: ca4a980414d934e35a3abb1eda08230e0aaf3686c4e15da8a937f813c4ff2e2a
4
- data.tar.gz: 73dae7b30f033de9c07dfac6c3b4ed75063fca95ac1a4eb352ec1a2453c0c8c0
3
+ metadata.gz: 701b7288740d66b3ec871033ec0aa52558fe4487062c7f8d8164b14d57ef7a3e
4
+ data.tar.gz: d5becf3c8733a03c5202a6a668b6385e01bb54e8148a20a3a1ba72f761aef5c1
5
5
  SHA512:
6
- metadata.gz: 3daaa7854edbd80ff5facac95814888f7ef91d5574bf339371cada016b224fcf23512800a750db8a5bc77028fc7bd3492ecae37985aa83e2515ff49b1e0244bc
7
- data.tar.gz: 705cca1029bba160ccb4db98a5b64ba9cb227599d3d56657af919bfb0bf2428e0d1516527cfb941235f4ef0ab5ef50a1f6d921fa5299658427979ede9adc6eae
6
+ metadata.gz: 42b9e5cc0a39c8547e764bd856ce9b16eb58e396da4f87d2a550d51dafeb936a1c0079fcce6d6f209f8a116507a7be0cd0d5f4199e8eb4c0b1baee68bc2fefd5
7
+ data.tar.gz: 49c955f03ed68f8a793a2825bd48e1821adf227a4826502f9fcde016562e774a0184efd06889f844091011c4631a5fc9cef0ba5e8d80b0bf17cc959dea215d43
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
 
@@ -26,14 +28,26 @@ Or install it yourself as:
26
28
 
27
29
  ```ruby
28
30
 
29
- # Pass environment and api_key to configure
30
- Lmb::Developers.configure('environment', 'api_key')
31
+ # Pass environment and api_key to configure. Note: Use ENV variables to protect data in production environment
32
+ Lmb::Developers.configure('environment', ENV['LMB_API_KEY'])
31
33
 
32
34
  ```
33
35
 
34
36
  The environment can be 'TEST' or 'PROD'.
35
37
 
36
- You will need an api_key that can be obtained at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
38
+ You will need an API KEY that can be obtained at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
39
+
40
+ ### Example
41
+
42
+ ```ruby
43
+
44
+ #config/initilizers/lmb_developers.rb
45
+ Lmb::Developers.configure('TEST', ENV['LMB_API_KEY'])
46
+
47
+ #app/controller/login.rb
48
+ Lmb::Developers::Auth.login("ldap_username", "ldap_password")
49
+
50
+ ```
37
51
 
38
52
  ### Methods
39
53
 
@@ -45,7 +59,7 @@ Lmb::Developers::Auth.login("ldap_username", "ldap_password", "ldap_usertype = e
45
59
 
46
60
  ## Contributing
47
61
 
48
- 1. Fork it ( https://github.com/[my-github-username]/lmb-developers/fork )
62
+ 1. Fork it ( https://github.com/somosprte/lmb-developers/fork )
49
63
  2. Create your feature branch (`git checkout -b my-new-feature`)
50
64
  3. Commit your changes (`git commit -am 'Add some feature'`)
51
65
  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
@@ -0,0 +1,86 @@
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
+
11
+ # Set Inhabitant's Expired Vouchers.
12
+ #
13
+ # @param expirations [Hash] the expriations object.
14
+ # @return [Boolean]
15
+ def self.voucher_expired(expirations)
16
+ uri = URI.parse("#{configuration.url}#{VOUCHER_EXPIRED_PATH}")
17
+ request = Net::HTTP::Post.new(uri)
18
+ request['Apikey'] = configuration.api_key.to_s
19
+ request['Cache-Control'] = 'no-cache'
20
+ request.body = JSON.dump(
21
+ 'expirations' => expirations
22
+ )
23
+ req_options = {
24
+ use_ssl: uri.scheme == 'https'
25
+ }
26
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
27
+ http.request(request)
28
+ end
29
+ response.code.to_i == 202
30
+ rescue StandardError => exception
31
+ exception
32
+ end
33
+
34
+ # Set Inhabitant's Provisioned Vouchers.
35
+ #
36
+ # @param expirations [Hash] the provisions object.
37
+ # @return [Boolean]
38
+ def self.voucher_provisioned(provisions)
39
+ uri = URI.parse("#{configuration.url}#{VOUCHER_PROVISIONED_PATH}")
40
+ request = Net::HTTP::Post.new(uri)
41
+ request['Apikey'] = configuration.api_key.to_s
42
+ request['Cache-Control'] = 'no-cache'
43
+ request.body = JSON.dump(
44
+ 'provisions' => provisions
45
+ )
46
+ req_options = {
47
+ use_ssl: uri.scheme == 'https'
48
+ }
49
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
50
+ http.request(request)
51
+ end
52
+ response.code.to_i == 202
53
+ rescue StandardError => exception
54
+ exception
55
+ end
56
+
57
+ # Set Inhabitant's Activated Vouchers.
58
+ #
59
+ # @param expirations [Hash] the activations object.
60
+ # @return [Boolean]
61
+ def self.voucher_activated(activations)
62
+ uri = URI.parse("#{configuration.url}#{VOUCHER_ACTIVATED_PATH}")
63
+ request = Net::HTTP::Post.new(uri)
64
+ request['Apikey'] = configuration.api_key.to_s
65
+ request['Cache-Control'] = 'no-cache'
66
+ request.body = JSON.dump(
67
+ 'activations' => activations
68
+ )
69
+ req_options = {
70
+ use_ssl: uri.scheme == 'https'
71
+ }
72
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
73
+ http.request(request)
74
+ end
75
+ response.code.to_i == 202
76
+ rescue StandardError => exception
77
+ exception
78
+ end
79
+
80
+ # Get configuration.
81
+ def self.configuration
82
+ @configuration = Lmb::Developers.configuration
83
+ end
84
+ end
85
+ end
86
+ 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.0'
4
+ s.date = '2019-04-01'
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.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-01-10 00:00:00.000000000 Z
11
+ date: 2019-04-01 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
@@ -25,6 +25,7 @@ files:
25
25
  - lib/lmb/developers/auth.rb
26
26
  - lib/lmb/developers/configuration.rb
27
27
  - lib/lmb/developers/error.rb
28
+ - lib/lmb/developers/loyalty.rb
28
29
  - lmb-developers.gemspec
29
30
  homepage: https://github.com/somosprte/lmb-developers
30
31
  licenses:
@@ -45,8 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
48
  requirements: []
48
- rubyforge_project:
49
- rubygems_version: 2.7.8
49
+ rubygems_version: 3.0.2
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: Consume APIs at Leroy Merlin Brazil Developer's Portal