lmb-developers 1.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca4a980414d934e35a3abb1eda08230e0aaf3686c4e15da8a937f813c4ff2e2a
4
+ data.tar.gz: 73dae7b30f033de9c07dfac6c3b4ed75063fca95ac1a4eb352ec1a2453c0c8c0
5
+ SHA512:
6
+ metadata.gz: 3daaa7854edbd80ff5facac95814888f7ef91d5574bf339371cada016b224fcf23512800a750db8a5bc77028fc7bd3492ecae37985aa83e2515ff49b1e0244bc
7
+ data.tar.gz: 705cca1029bba160ccb4db98a5b64ba9cb227599d3d56657af919bfb0bf2428e0d1516527cfb941235f4ef0ab5ef50a1f6d921fa5299658427979ede9adc6eae
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ *.gem
3
+ doc/
4
+ .yardoc/
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ [![Gem Version](https://badge.fury.io/rb/lmb-developers.svg)](http://badge.fury.io/rb/lmb-developers)
2
+
3
+ # Lmb Developers
4
+
5
+ A ruby wrapper for the Leroy Merlin Brazil Developers API available at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lmb-developers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install lmb-developers
22
+
23
+ ## Usage
24
+
25
+ ### Configuration
26
+
27
+ ```ruby
28
+
29
+ # Pass environment and api_key to configure
30
+ Lmb::Developers.configure('environment', 'api_key')
31
+
32
+ ```
33
+
34
+ The environment can be 'TEST' or 'PROD'.
35
+
36
+ You will need an api_key that can be obtained at [Leroy Merlin Brazil Developer's Portal](https://developers.leroymerlin.com.br)
37
+
38
+ ### Methods
39
+
40
+ Ldap Login
41
+
42
+ ```ruby
43
+ Lmb::Developers::Auth.login("ldap_username", "ldap_password", "ldap_usertype = employee")
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/[my-github-username]/lmb-developers/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
53
+
54
+ We are always keen to learn so please feel free to create an issue with code reviews, suggestions and possible refactorings.
55
+
56
+ ## TODOS
57
+
58
+ - Docs
59
+ - Tests
60
+ - Other Methods
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,71 @@
1
+ module Lmb
2
+ module Developers
3
+ class Auth
4
+ attr_reader :configuration
5
+
6
+ # Path to consume login
7
+ AUTH_PATH = '/v1/auth/login'
8
+
9
+ # Check if user is valid in LMB Ldap.
10
+ #
11
+ # @param username [String] the ldap username.
12
+ # @param password [String] the ldap password.
13
+ # @param user_type [String] the ldap user_type, `employee` (default), `customer` or `supplier`
14
+ # @return [Hash] when login successful.
15
+ # * [String] :userType LDAP user_type
16
+ # * [String] :username LDAP of the employee
17
+ # * [String] :employeeID ID of the employee
18
+ # * [String] :employeeType EmployeeType
19
+ # * [String] :fullName Full Name of the user
20
+ # * [String] :givenName Given Name of the user
21
+ # * [String] :surname Surname of the user
22
+ # * [String] :title Mission designated to the user
23
+ # * [String] :titleCode Code of mission designated to the user
24
+ # * [String] :locationName Site where the user works
25
+ # * [String] :locationCode Code from site where the user works
26
+ # * [String] :department Department of the user
27
+ # * [Date] :contractStartDate Contract start date of the user
28
+ # * [String] :email Email of the user
29
+ # * [String] :Telephone number of the user's department
30
+ # * [String] :mobile Mobile phone number of the user
31
+ # * [String] :manager Manager's distinguish name from LDAP
32
+ # * [String] :o Brands abbreviation. E.g. LM for Leroy Merlin
33
+ # * [String] :ou Organization unit
34
+ # * [Date] :birthdate Birthdate from user
35
+ # * [String] :createdBy Distinguish name from user that created the registry in LDAP
36
+ # * [String] :modifiedBy Distinguish name from user that modified the registry in LDAP
37
+ # * [Byte] :jpegPhoto Binary Base64 represeting JPEG photo.
38
+ # @return [Lmb::Developers::Error] when login failure.
39
+ def self.login username, password, user_type = 'employee'
40
+ begin
41
+ uri = URI.parse("#{configuration.url}#{AUTH_PATH}")
42
+ request = Net::HTTP::Post.new(uri)
43
+ request.content_type = "application/x-www-form-urlencoded"
44
+ request["Apikey"] = "#{configuration.api_key}"
45
+ request["Cache-Control"] = "no-cache"
46
+ request.body = "username=#{username}&password=#{password}&userType=#{user_type}"
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
+ result = JSON.parse(response.body)
54
+ if response.code.to_i == 200
55
+ result
56
+ else
57
+ fail Error, JSON.parse(response.body)
58
+ end
59
+ rescue => exception
60
+ exception
61
+ end
62
+
63
+ end
64
+
65
+ # Get configuration.
66
+ def self.configuration
67
+ @configuration = Lmb::Developers.configuration
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ module Lmb
2
+ module Developers
3
+ class Configuration
4
+ attr_accessor :api_key,
5
+ :environment
6
+ attr_reader :url
7
+
8
+ # Initial config.
9
+ def initialize
10
+ @config = {
11
+ 'TEST' => {
12
+ 'url': 'https://api-test.leroymerlin.com.br'
13
+ },
14
+ 'PROD' => {
15
+ 'url' => 'https://api.leroymerlin.com.br',
16
+ }
17
+ }
18
+ configure('TEST', nil)
19
+ end
20
+ # Configure global parameters
21
+ #
22
+ # @param environment [String] environment to consume APIs, `TEST` or `PROD`
23
+ # @param api_key [String] ApiKey to consume APIs.
24
+ # @return [Lmb::Developers::Configuration]
25
+ def configure(environment = 'TEST', api_key)
26
+ @api_key = api_key
27
+ @environment = environment
28
+ @url = @config[environment][:url]
29
+ self
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module Lmb
2
+ module Developers
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'lmb/developers/configuration'
4
+ require 'lmb/developers/auth'
5
+ require 'lmb/developers/error'
6
+ module Lmb
7
+ module Developers
8
+ class << self
9
+ attr_reader :configuration
10
+
11
+ # Configure global parameters
12
+ #
13
+ # @param environment [String] environment to consume APIs, `TEST` or `PROD`
14
+ # @param api_key [String] ApiKey to consume APIs.
15
+ # @return [Lmb::Developers::Configuration]
16
+ def configure(environment, api_key)
17
+ configuration.configure(environment, api_key)
18
+ end
19
+
20
+ # Instace or return global configuration
21
+ def configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/lmb.rb ADDED
@@ -0,0 +1 @@
1
+ require 'lmb/developers'
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'lmb-developers'
3
+ s.version = '1.1.2'
4
+ s.date = '2019-01-10'
5
+ s.summary = "Consume APIs at Leroy Merlin Brazil Developer's Portal"
6
+ s.description = "Gem to consume APIs available at Leroy Merlin Brazil Developer's Portal https://developers.leroymerlin.com.br"
7
+ s.author = "PRTE - Tecnologia e Soluções"
8
+ s.email = 'contato@prte.com.br'
9
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
10
+ s.require_paths = ['lib']
11
+ s.homepage =
12
+ 'https://github.com/somosprte/lmb-developers'
13
+ s.license = 'MIT'
14
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lmb-developers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - PRTE - Tecnologia e Soluções
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem to consume APIs available at Leroy Merlin Brazil Developer's Portal
14
+ https://developers.leroymerlin.com.br
15
+ email: contato@prte.com.br
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - README.md
22
+ - Rakefile
23
+ - lib/lmb.rb
24
+ - lib/lmb/developers.rb
25
+ - lib/lmb/developers/auth.rb
26
+ - lib/lmb/developers/configuration.rb
27
+ - lib/lmb/developers/error.rb
28
+ - lmb-developers.gemspec
29
+ homepage: https://github.com/somosprte/lmb-developers
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.7.8
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Consume APIs at Leroy Merlin Brazil Developer's Portal
53
+ test_files: []