leisureking 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a84672304ff7a742ee55a6b41583033850ae46a
4
+ data.tar.gz: 787ea92a3cfec080bc615e23941b80b11fb2d59a
5
+ SHA512:
6
+ metadata.gz: f7a45bf92772d70a4f339b0e1045f523cd33454cf100602e981f251c8a868098820c2d69bc68447ae17b29a63b8aa89323f0986d724cc76580738199d93eb7fc
7
+ data.tar.gz: 2f7808cafed3ab98fe3a39b49bedab94037d251c8ece77a1d812388bbd9f31176c016a3d4a3dc0f8fdf858fd3e017ecbf35db89d7a193cb153276bd5f7d2b7a5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/COMMENTS.md ADDED
@@ -0,0 +1,6 @@
1
+ # Comments for API Documentation team
2
+
3
+ ## Endpoint
4
+
5
+ ### https://api.leisureking.eu/v1l/assortiment/get
6
+ - {"status":"ERROR","data":{"errormessage":"Ongeldige id_vestiging meegestuurd"}}
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in leisureking.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ leisureking (0.1.0)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ domain_name (0.5.20190701)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-accept (1.7.0)
14
+ http-cookie (1.0.3)
15
+ domain_name (~> 0.5)
16
+ mime-types (3.3)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2019.1009)
19
+ netrc (0.11.0)
20
+ rake (10.5.0)
21
+ rest-client (2.1.0)
22
+ http-accept (>= 1.7.0, < 2.0)
23
+ http-cookie (>= 1.0.2, < 2.0)
24
+ mime-types (>= 1.16, < 4.0)
25
+ netrc (~> 0.8)
26
+ rspec (3.9.0)
27
+ rspec-core (~> 3.9.0)
28
+ rspec-expectations (~> 3.9.0)
29
+ rspec-mocks (~> 3.9.0)
30
+ rspec-core (3.9.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-expectations (3.9.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-mocks (3.9.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.9.0)
38
+ rspec-support (3.9.0)
39
+ unf (0.1.4)
40
+ unf_ext
41
+ unf_ext (0.0.7.6)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 2.0)
48
+ leisureking!
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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,67 @@
1
+ # Leisureking
2
+
3
+
4
+ This gem works as a simple Ruby wrapper for the Leisureking API. The Leisureking API has a very straight forward REST API.
5
+
6
+ All this gem does, is make it a little bit simpler to use the API:
7
+ - You can set your credentials via Rails config
8
+ - Authrization keys are renewed/requested automatically
9
+ - You can make REST requests right away, without having to worry about authentication
10
+
11
+
12
+ Original documentation is here: https://survey.leisureking.eu/v1l/docs/authentication
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'leisureking'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install leisureking
29
+
30
+ ## Configuration
31
+
32
+ First, obtain an API key and shared secret from LeisureKing. Set it up like this:
33
+ ```ruby
34
+ LeisureKing::Config.api_key = "MY-API-KEY"
35
+ LeisureKing::Config.api_secret = "MY-API-SHARED-SECRET"
36
+ ```
37
+
38
+ To use this gem in a Rails project:
39
+ ```ruby
40
+ # config/development.rb
41
+ config.leisure_king.api_key = "MY-API-KEY"
42
+ config.leisure_king.api_secret = "MY-API-SECRET"
43
+
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ All there is left is to use the API according to the documentation:
49
+
50
+ ```ruby
51
+ LeisureKing::API.send_request("assortiment/getassortimentdatabyassortimentid", {id_assortiment: 5625})
52
+ # => Returns Hash from JSON response
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/henkm/leisureking.
64
+
65
+ ## License
66
+
67
+ The gem is made with ❤️ by the smart people from Eskes Media. This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "leisureking"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "leisureking/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "leisureking"
7
+ spec.version = LeisureKing::VERSION
8
+ spec.authors = ["Henk Meijer"]
9
+ spec.email = ["hmeijer@eskesmedia.nl"]
10
+
11
+ spec.summary = %q{Ruby wrapper for the Leisureking API}
12
+ spec.description = %q{Ruby wrapper for the Leisureking API}
13
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.license = "MIT"
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "rest-client"
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
@@ -0,0 +1,74 @@
1
+ module LeisureKing::API
2
+
3
+ # The communication layer implements all the methods available in the LeisureKing API
4
+ class << self
5
+
6
+ require 'rest-client'
7
+ require 'json'
8
+
9
+ # Sends a request to the LeisureKing API and returns the parsed results
10
+
11
+ def base_uri
12
+ "https://api.leisureking.eu/v#{LeisureKing::Config.api_version}"
13
+ end
14
+
15
+ def send_request(endpoint, body = {})
16
+ url = "#{base_uri}/#{endpoint}"
17
+ body[:environment] = LeisureKing::Config.environment
18
+ begin
19
+ unless endpoint == "authenticate"
20
+ LeisureKing::Authentication.get_token
21
+ end
22
+ if LeisureKing::Config.verbose
23
+ puts "Sending request to #{url}"
24
+ puts "Body:\n#{body}" if body
25
+ end
26
+
27
+ begin
28
+ result = RestClient.post(url, body.to_json, headers) do |response, request, res, &block|
29
+ if [301, 302, 307].include? response.code
30
+ redirected_url = response.headers[:location]
31
+ if LeisureKing::Config.verbose
32
+ puts "Redirecting request to #{redirected_url}"
33
+ puts "Body:\n#{body}" if body
34
+ end
35
+ RestClient.post(redirected_url, body.to_json, headers)
36
+ else
37
+ response.return!(request, res, &block)
38
+ end
39
+ end
40
+ rescue RestClient::Unauthorized, RestClient::Forbidden => err
41
+ raise "Access denied. API Response:\n#{err}"
42
+ end
43
+
44
+ puts "Result:\n#{result}" if LeisureKing::Config.verbose
45
+ # begin
46
+ return JSON.parse(result)
47
+ # rescue
48
+ # return result
49
+ # end
50
+ rescue RestClient::BadRequest => err
51
+ raise "Bad Request. API Response:\n#{err.response}"
52
+ end
53
+ end
54
+
55
+ # HTTP headers to send in each request
56
+
57
+ def headers
58
+ h = {
59
+ content_type: :json,
60
+ accept: :json,
61
+ cache_control: 'no-cache'
62
+ }
63
+ # add requesters email address for human communication
64
+ if LeisureKing::Config.client_email && LeisureKing::Config.client_email != ''
65
+ h[:from] = LeisureKing::Config.client_email # email address for human communication
66
+ end
67
+ if LeisureKing::Authentication.token
68
+ h["Authorization"] = "Token #{LeisureKing::Authentication.token}"
69
+ end
70
+ return h
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ module LeisureKing::Authentication
2
+ require 'digest'
3
+ require 'base64'
4
+ require 'openssl'
5
+
6
+ # The communication layer implements all the methods available in the LeisureKing API
7
+ class << self
8
+ attr_accessor :token
9
+
10
+ # Set's the default value's to nil and false
11
+ # @return [Hash] conguration options
12
+ def init!
13
+ @defaults = {
14
+ :@token => nil,
15
+ }
16
+ end
17
+
18
+ def get_token
19
+ body = {
20
+ apikey: LeisureKing::Config.api_key,
21
+ secret: LeisureKing::Config.api_secret
22
+ }
23
+ result = LeisureKing::API.send_request("authenticate", body)
24
+ if result["status"] && result["status"] == "OK"
25
+ self.token = result["data"]["token"]
26
+ end
27
+ return result
28
+ end
29
+ end
30
+ init!
31
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Configuration object for storing some parameters required for making transactions
3
+ #
4
+
5
+ module ::LeisureKing::Config
6
+ class << self
7
+ attr_accessor :api_key
8
+ attr_accessor :api_secret
9
+ attr_accessor :verbose
10
+ attr_accessor :api_version
11
+ attr_accessor :environment
12
+ attr_accessor :client_email # Who is making the request? For optional HTTP Header
13
+
14
+
15
+
16
+ # Set's the default value's to nil and false
17
+ # @return [Hash] configuration options
18
+ def init!
19
+ @defaults = {
20
+ :@api_key => nil,
21
+ :@api_secret => nil,
22
+ :@verbose => false,
23
+ :@environment => :test,
24
+ :@client_email => '',
25
+ :@api_version => '1l'
26
+ }
27
+ end
28
+
29
+ # Resets the value's to there previous value (instance_variable)
30
+ # @return [Hash] configuration options
31
+ def reset!
32
+ @defaults.each { |key, value| instance_variable_set(key, value) }
33
+ end
34
+
35
+ # Set's the new value's as instance variables
36
+ # @return [Hash] configuration options
37
+ def update!
38
+ @defaults.each do |key, value|
39
+ instance_variable_set(key, value) unless instance_variable_defined?(key)
40
+ end
41
+ end
42
+ end
43
+ init!
44
+ reset!
45
+
46
+ end
@@ -0,0 +1,15 @@
1
+ module LeisureKing
2
+ #
3
+ # Simpel extend on the +Rails::Engine+ to add support for a new
4
+ # config section within the environment configs
5
+ #
6
+ # @example default
7
+ # # /config/environments/development.rb
8
+ # config.leisure_king.api_key = "12343465sdfgsadr324"
9
+ #
10
+
11
+ class Engine < ::Rails::Engine
12
+ isolate_namespace LeisureKing
13
+ config.leisure_king = LeisureKing::Config
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module LeisureKing
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ module LeisureKing
2
+ end
3
+
4
+ require "leisureking/version"
5
+ require "leisureking/config"
6
+ require "leisureking/engine" if defined?(Rails) && Rails::VERSION::MAJOR.to_i >= 3
7
+ require "leisureking/authentication"
8
+ require "leisureking/api"
9
+
10
+
11
+ module LeisureKing
12
+ class Error < StandardError; end
13
+
14
+
15
+ # For testing purpose only: set the username and password
16
+ # in environment variables to make the tests pass with your test
17
+ # credentials.
18
+ def self.set_credentials_from_environment
19
+ Config.api_key = ENV["LEISURE_KING_API_KEY"]
20
+ Config.api_secret = ENV["LEISURE_KING_API_SECRET"]
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leisureking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henk Meijer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-13 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Ruby wrapper for the Leisureking API
70
+ email:
71
+ - hmeijer@eskesmedia.nl
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - COMMENTS.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - leisureking.gemspec
88
+ - lib/leisureking.rb
89
+ - lib/leisureking/api.rb
90
+ - lib/leisureking/authentication.rb
91
+ - lib/leisureking/config.rb
92
+ - lib/leisureking/engine.rb
93
+ - lib/leisureking/version.rb
94
+ homepage:
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.14
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby wrapper for the Leisureking API
118
+ test_files: []