enviso 0.1.5
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/enviso.gemspec +44 -0
- data/lib/enviso.rb +22 -0
- data/lib/enviso/api.rb +86 -0
- data/lib/enviso/authentication.rb +93 -0
- data/lib/enviso/config.rb +48 -0
- data/lib/enviso/engine.rb +15 -0
- data/lib/enviso/version.rb +3 -0
- metadata +106 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 868fa4f07cd6d42b1a22917a7e45982f0e569c31ef96f497e6239a9982270429
|
|
4
|
+
data.tar.gz: 14ce3150ee9ce8b0d0c5b6fa7d500bb2e5e1e5b33d81a9920de7270c0ae1fe59
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ba681cca43b4abab40b191118e9b105d0517c83bd843255f525cd18b9b37c5be05ebc41f0762c5ede5680ed2c3eeb9002edde46bdc13ac46130d770b687296bb
|
|
7
|
+
data.tar.gz: 491c5d20966bbcf2fda9b90905dbb98e1073bc609f345e6dc8b7636255c81b12925f61fcfa4553166872dda258c48da2ea010be6027f0d09dbc9e2c5cac60720
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at meijerhenk@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
enviso (0.1.2)
|
|
5
|
+
openssl
|
|
6
|
+
rest-client
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
diff-lcs (1.3)
|
|
12
|
+
domain_name (0.5.20190701)
|
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
14
|
+
http-accept (1.7.0)
|
|
15
|
+
http-cookie (1.0.3)
|
|
16
|
+
domain_name (~> 0.5)
|
|
17
|
+
mime-types (3.3)
|
|
18
|
+
mime-types-data (~> 3.2015)
|
|
19
|
+
mime-types-data (3.2019.1009)
|
|
20
|
+
netrc (0.11.0)
|
|
21
|
+
openssl (2.1.2)
|
|
22
|
+
rest-client (2.1.0)
|
|
23
|
+
http-accept (>= 1.7.0, < 2.0)
|
|
24
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
25
|
+
mime-types (>= 1.16, < 4.0)
|
|
26
|
+
netrc (~> 0.8)
|
|
27
|
+
rspec (3.9.0)
|
|
28
|
+
rspec-core (~> 3.9.0)
|
|
29
|
+
rspec-expectations (~> 3.9.0)
|
|
30
|
+
rspec-mocks (~> 3.9.0)
|
|
31
|
+
rspec-core (3.9.0)
|
|
32
|
+
rspec-support (~> 3.9.0)
|
|
33
|
+
rspec-expectations (3.9.0)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.9.0)
|
|
36
|
+
rspec-mocks (3.9.0)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.9.0)
|
|
39
|
+
rspec-support (3.9.0)
|
|
40
|
+
unf (0.1.4)
|
|
41
|
+
unf_ext
|
|
42
|
+
unf_ext (0.0.7.6)
|
|
43
|
+
|
|
44
|
+
PLATFORMS
|
|
45
|
+
ruby
|
|
46
|
+
|
|
47
|
+
DEPENDENCIES
|
|
48
|
+
enviso!
|
|
49
|
+
rspec (~> 3.0)
|
|
50
|
+
|
|
51
|
+
BUNDLED WITH
|
|
52
|
+
2.0.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Henk Meijer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Enviso
|
|
2
|
+
|
|
3
|
+
This gem works as a simple Ruby wrapper for the Enviso API. The Enviso API has a very straight forward REST API.
|
|
4
|
+
|
|
5
|
+
All this gem does, is make it a little bit simpler to use the API:
|
|
6
|
+
- You can set your credentials via Rails config
|
|
7
|
+
- Authrization keys are renewed/requested automatically
|
|
8
|
+
- You can make REST requests right away, without having to worry about authentication
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'enviso'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install enviso
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
First, obtain an API key and shared secret from Enviso. Set it up like this:
|
|
30
|
+
```ruby
|
|
31
|
+
Enviso::Config.api_key = "MY-API-KEY"
|
|
32
|
+
Enviso::Config.api_secret = "MY-API-SHARED-SECRET" # pubic key
|
|
33
|
+
Enviso::Config.tenant_key = "TENANT-KEY"
|
|
34
|
+
Enviso::Config.verbose = false # set 'true' to show raw API input/output
|
|
35
|
+
Enviso::Config.api_link = "https://api.staging-enviso.io/resellingapi/"
|
|
36
|
+
Enviso::Config.api_version = 1
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To use this gem in a Rails project:
|
|
40
|
+
```ruby
|
|
41
|
+
# config/development.rb
|
|
42
|
+
config.enviso.api_key = "MY-API-KEY"
|
|
43
|
+
config.enviso.api_secret = "MY-API-SHARED-SECRET" # pubic key
|
|
44
|
+
config.enviso.tenant_key = "TENANT-KEY"
|
|
45
|
+
config.enviso.verbose = false # set 'true' to show raw API input/output
|
|
46
|
+
config.enviso.api_link = "https://api.staging-enviso.io/resellingapi/"
|
|
47
|
+
config.enviso.api_version = 1
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
All there is left is to use the API according to the documentation:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
Enviso::API.send_request(type: :get, endpoint: "venues/84/offers")
|
|
56
|
+
# => Returns Hash from JSON response
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Code of Conduct
|
|
60
|
+
|
|
61
|
+
Everyone interacting in the Enviso project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/Enviso/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "Enviso"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/enviso.gemspec
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "enviso/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "enviso"
|
|
8
|
+
spec.version = Enviso::VERSION
|
|
9
|
+
spec.authors = ["Henk Meijer"]
|
|
10
|
+
spec.email = ["hmeijer@eskesmedia.nl"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Ruby wrapper for the Enviso API}
|
|
13
|
+
spec.description = %q{Ruby wrapper for the Enviso API}
|
|
14
|
+
spec.homepage = "https://bitbucket.org/eskes_media/enviso"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
# spec.metadata["allowed_push_host"] = "https://bitbucket.org/eskes_media/enviso"
|
|
21
|
+
|
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
23
|
+
spec.metadata["source_code_uri"] = "https://bitbucket.org/eskes_media/enviso"
|
|
24
|
+
else
|
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
26
|
+
"public gem pushes."
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
33
|
+
end
|
|
34
|
+
spec.bindir = "exe"
|
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
36
|
+
spec.require_paths = ["lib"]
|
|
37
|
+
|
|
38
|
+
spec.add_dependency "rest-client"
|
|
39
|
+
# spec.add_dependency "digest"
|
|
40
|
+
spec.add_dependency "openssl"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
44
|
+
end
|
data/lib/enviso.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Enviso
|
|
2
|
+
end
|
|
3
|
+
|
|
4
|
+
require "enviso/config"
|
|
5
|
+
require "enviso/engine" if defined?(Rails) && Rails::VERSION::MAJOR.to_i >= 3
|
|
6
|
+
require "enviso/api"
|
|
7
|
+
require "enviso/authentication"
|
|
8
|
+
|
|
9
|
+
module Enviso
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
# For testing purpose only: set the username and password
|
|
13
|
+
# in environment variables to make the tests pass with your test
|
|
14
|
+
# credentials.
|
|
15
|
+
def self.set_credentials_from_environment
|
|
16
|
+
Config.api_key = ENV["ENVISO_API_KEY"]
|
|
17
|
+
Config.api_secret = ENV["ENVISO_API_SECRET"]
|
|
18
|
+
Config.tenant_key = ENV["ENVISO_TENANT_KEY"]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
end
|
data/lib/enviso/api.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Enviso::API
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# The communication layer implements all the methods available in the Enviso API
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
require 'rest-client'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
# Sends a request to the Enviso API and returns the parsed results
|
|
11
|
+
|
|
12
|
+
def send_request(type: :get, endpoint: String, body: nil, token: nil)
|
|
13
|
+
url = "#{Enviso::Config.api_link}v#{Enviso::Config.api_version}/#{endpoint}"
|
|
14
|
+
begin
|
|
15
|
+
|
|
16
|
+
if token.nil?
|
|
17
|
+
unless endpoint.include?("apis")
|
|
18
|
+
Enviso::Authentication.get_new_token
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if Enviso::Config.verbose
|
|
23
|
+
puts "[ENVISO] Sending #{type.upcase} request to #{url}"
|
|
24
|
+
puts "[ENVISO] Body:\n#{body}" if body
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if type.to_sym == :post
|
|
28
|
+
begin
|
|
29
|
+
result = RestClient.post url, body.to_json, headers
|
|
30
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
|
31
|
+
raise "Access denied. API Response:\n#{err.response}"
|
|
32
|
+
end
|
|
33
|
+
elsif type.to_sym == :put
|
|
34
|
+
begin
|
|
35
|
+
result = RestClient.put url, body.to_json, headers
|
|
36
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
|
37
|
+
raise "Access denied. API Response:\n#{err.response}"
|
|
38
|
+
end
|
|
39
|
+
elsif type.to_sym == :delete
|
|
40
|
+
begin
|
|
41
|
+
# result = RestClient.delete url, headers
|
|
42
|
+
result = RestClient::Request.execute(
|
|
43
|
+
method: :delete,
|
|
44
|
+
url: url,
|
|
45
|
+
body: body,
|
|
46
|
+
headers: headers)
|
|
47
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
|
48
|
+
raise "Access denied. API Response:\n#{err.response}"
|
|
49
|
+
end
|
|
50
|
+
elsif type.to_sym == :get
|
|
51
|
+
begin
|
|
52
|
+
result = RestClient.get url, headers
|
|
53
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
|
54
|
+
raise "Access denied. API Response:\n#{err.response}"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
puts "[ENVISO] Result:\n#{result}" if Enviso::Config.verbose
|
|
59
|
+
begin
|
|
60
|
+
return JSON.parse(result)
|
|
61
|
+
rescue
|
|
62
|
+
return result
|
|
63
|
+
end
|
|
64
|
+
rescue RestClient::BadRequest => err
|
|
65
|
+
raise "Bad Request. API Response:\n#{err.response}"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# HTTP headers to send in each request
|
|
70
|
+
|
|
71
|
+
def headers
|
|
72
|
+
h = {
|
|
73
|
+
content_type: :json,
|
|
74
|
+
accept: :json,
|
|
75
|
+
cache_control: 'no-cache',
|
|
76
|
+
'x-api-key' => Enviso::Config.api_key,
|
|
77
|
+
'x-tenantsecretkey' => Enviso::Config.tenant_key
|
|
78
|
+
}
|
|
79
|
+
if Enviso::Authentication.auth_token
|
|
80
|
+
h["Authorization"] = "bearer #{Enviso::Authentication.auth_token}"
|
|
81
|
+
end
|
|
82
|
+
return h
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Enviso::Authentication
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
|
|
6
|
+
# The communication layer implements all the methods available in the Enviso API
|
|
7
|
+
class << self
|
|
8
|
+
attr_accessor :auth_token
|
|
9
|
+
attr_accessor :refresh_token
|
|
10
|
+
|
|
11
|
+
# Set's the default value's to nil and false
|
|
12
|
+
# @return [Hash] configuration options
|
|
13
|
+
def init!
|
|
14
|
+
@defaults = {
|
|
15
|
+
:@auth_token => nil,
|
|
16
|
+
:@refresh_token => nil
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# in the authentication documentation, chapter 4.1:
|
|
22
|
+
# 1. Concatenate the API key with the current timestamp in the format below:
|
|
23
|
+
# <<APIKEY>>_<<timestamp(yyyy'-'MM'-'ddTHH:mm:ss.fffZ)>>
|
|
24
|
+
# NOTE: The timestamp is in ISO 8601
|
|
25
|
+
def timestamp_for_authentication
|
|
26
|
+
return Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# The method calculates the login signature, as described
|
|
30
|
+
# 2. Create a SHA256 hash of this value. Based on the hashed value, a digital signature will be created.
|
|
31
|
+
|
|
32
|
+
def calculate_login_signature(timestamp)
|
|
33
|
+
api_key = Enviso::Config.api_key
|
|
34
|
+
return Digest::SHA256.hexdigest("#{api_key}_#{timestamp}")
|
|
35
|
+
# return OpenSSL::Digest::SHA256.new("#{api_key}_#{timestamp}")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Signs the login signature hash
|
|
40
|
+
# From the authentication documentation, chapter 4.1:
|
|
41
|
+
# 3. The combination of the created signature along with the provided API secret key will act as the digital signature of the call.
|
|
42
|
+
|
|
43
|
+
def sign_login_signature(key)
|
|
44
|
+
secret = Enviso::Config.api_secret
|
|
45
|
+
public_key = OpenSSL::PKey::RSA.new(secret)
|
|
46
|
+
encrypted_string = Base64.encode64(public_key.public_encrypt(key))
|
|
47
|
+
return encrypted_string
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# This method combines all the login steps
|
|
51
|
+
# 1. generate a key (SHA256)
|
|
52
|
+
# 2. signs the key with public_key
|
|
53
|
+
# 3. sends request to API endpoint
|
|
54
|
+
|
|
55
|
+
def login(signed_key: nil)
|
|
56
|
+
self.auth_token = nil # reset to prevent giving auth token in login request headers
|
|
57
|
+
|
|
58
|
+
timestamp = timestamp_for_authentication
|
|
59
|
+
key = calculate_login_signature(timestamp)
|
|
60
|
+
signed_key = sign_login_signature(key) unless signed_key
|
|
61
|
+
|
|
62
|
+
body = {
|
|
63
|
+
apikey: Enviso::Config.api_key,
|
|
64
|
+
timestamp: timestamp,
|
|
65
|
+
signature: signed_key
|
|
66
|
+
}
|
|
67
|
+
result = Enviso::API.send_request(type: :post, endpoint: "apis/login", body: body)
|
|
68
|
+
if result["authToken"]
|
|
69
|
+
self.refresh_token = result["refreshToken"]
|
|
70
|
+
self.auth_token = result["authToken"]
|
|
71
|
+
end
|
|
72
|
+
return result
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Get new access token using refresh token from login request response
|
|
76
|
+
def get_new_token
|
|
77
|
+
body = { refreshToken: refresh_token }
|
|
78
|
+
puts "Refreshing token" if Enviso::Config.verbose
|
|
79
|
+
begin
|
|
80
|
+
result = Enviso::API.send_request(type: :post, endpoint: "apis/getnewtoken", body: body)
|
|
81
|
+
if result["token"]
|
|
82
|
+
self.auth_token = result["token"]
|
|
83
|
+
end
|
|
84
|
+
return result
|
|
85
|
+
rescue
|
|
86
|
+
puts "Signing in again to refresh token" if Enviso::Config.verbose
|
|
87
|
+
login
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
init!
|
|
93
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Configuration object for storing some parameters required for making transactions
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module ::Enviso::Config
|
|
6
|
+
class << self
|
|
7
|
+
attr_accessor :api_key
|
|
8
|
+
attr_accessor :api_secret
|
|
9
|
+
attr_accessor :tenant_key
|
|
10
|
+
attr_accessor :verbose
|
|
11
|
+
attr_accessor :api_link
|
|
12
|
+
attr_accessor :api_version
|
|
13
|
+
attr_accessor :environment
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Set's the default value's to nil and false
|
|
18
|
+
# @return [Hash] configuration options
|
|
19
|
+
def init!
|
|
20
|
+
@defaults = {
|
|
21
|
+
:@api_key => nil,
|
|
22
|
+
:@api_secret => nil,
|
|
23
|
+
:@tenant_key => nil,
|
|
24
|
+
:@verbose => false,
|
|
25
|
+
:@environment => :test,
|
|
26
|
+
:@api_version => 1,
|
|
27
|
+
:@api_link => "https://api.staging-enviso.io/resellingapi/"
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Resets the value's to there previous value (instance_variable)
|
|
32
|
+
# @return [Hash] configuration options
|
|
33
|
+
def reset!
|
|
34
|
+
@defaults.each { |key, value| instance_variable_set(key, value) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Set's the new value's as instance variables
|
|
38
|
+
# @return [Hash] configuration options
|
|
39
|
+
def update!
|
|
40
|
+
@defaults.each do |key, value|
|
|
41
|
+
instance_variable_set(key, value) unless instance_variable_defined?(key)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
init!
|
|
46
|
+
reset!
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Enviso
|
|
2
|
+
#
|
|
3
|
+
# Simpel extend on the +Rails::Engine+ to add support for a new config section within
|
|
4
|
+
# the environment configs
|
|
5
|
+
#
|
|
6
|
+
# @example default
|
|
7
|
+
# # /config/environments/development.rb
|
|
8
|
+
# config.enviso.api_key = "12343465sdfgsadr324"
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
class Engine < ::Rails::Engine
|
|
12
|
+
isolate_namespace Enviso
|
|
13
|
+
config.enviso = Enviso::Config
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: enviso
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.5
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Henk Meijer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rest-client
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: openssl
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: Ruby wrapper for the Enviso API
|
|
56
|
+
email:
|
|
57
|
+
- hmeijer@eskesmedia.nl
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".travis.yml"
|
|
65
|
+
- CODE_OF_CONDUCT.md
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- enviso.gemspec
|
|
74
|
+
- lib/enviso.rb
|
|
75
|
+
- lib/enviso/api.rb
|
|
76
|
+
- lib/enviso/authentication.rb
|
|
77
|
+
- lib/enviso/config.rb
|
|
78
|
+
- lib/enviso/engine.rb
|
|
79
|
+
- lib/enviso/version.rb
|
|
80
|
+
homepage: https://bitbucket.org/eskes_media/enviso
|
|
81
|
+
licenses:
|
|
82
|
+
- MIT
|
|
83
|
+
metadata:
|
|
84
|
+
homepage_uri: https://bitbucket.org/eskes_media/enviso
|
|
85
|
+
source_code_uri: https://bitbucket.org/eskes_media/enviso
|
|
86
|
+
post_install_message:
|
|
87
|
+
rdoc_options: []
|
|
88
|
+
require_paths:
|
|
89
|
+
- lib
|
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
100
|
+
requirements: []
|
|
101
|
+
rubyforge_project:
|
|
102
|
+
rubygems_version: 2.7.6
|
|
103
|
+
signing_key:
|
|
104
|
+
specification_version: 4
|
|
105
|
+
summary: Ruby wrapper for the Enviso API
|
|
106
|
+
test_files: []
|