res_os_ruby 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d2d34967bb8f5e60ad866b461fe0eaebef59c7ff2f48745ce01fe0b2136588b
4
+ data.tar.gz: 6e69dbdd270740c5486d8c3416056f98b0aedb5ef36c7787575b2555445ed8fa
5
+ SHA512:
6
+ metadata.gz: caeae122307f53ce2fe569ff3f734fe88980e8eccc5d22d4d22014987f9956413b9b2d14538bba95dd5c3f1349b4022daa71183977fc953048daf0877569f398
7
+ data.tar.gz: 241e97f102ccc3b116db7388d1833359ffee98d03038bfebc4ecdbdba342f70813e0f8339e95d36698dc6863ce7c79254e4df2820442c0240dd3a04bec984e12
@@ -0,0 +1,13 @@
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
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in res_os_ruby.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rest-client"
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ res_os_ruby (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ domain_name (0.5.20190701)
11
+ unf (>= 0.0.5, < 1.0.0)
12
+ http-accept (1.7.0)
13
+ http-cookie (1.0.3)
14
+ domain_name (~> 0.5)
15
+ mime-types (3.3.1)
16
+ mime-types-data (~> 3.2015)
17
+ mime-types-data (3.2020.0512)
18
+ netrc (0.11.0)
19
+ rake (12.3.3)
20
+ rest-client (2.1.0)
21
+ http-accept (>= 1.7.0, < 2.0)
22
+ http-cookie (>= 1.0.2, < 2.0)
23
+ mime-types (>= 1.16, < 4.0)
24
+ netrc (~> 0.8)
25
+ rspec (3.9.0)
26
+ rspec-core (~> 3.9.0)
27
+ rspec-expectations (~> 3.9.0)
28
+ rspec-mocks (~> 3.9.0)
29
+ rspec-core (3.9.3)
30
+ rspec-support (~> 3.9.3)
31
+ rspec-expectations (3.9.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-mocks (3.9.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-support (3.9.3)
38
+ unf (0.1.4)
39
+ unf_ext
40
+ unf_ext (0.0.7.7)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ rake (~> 12.0)
47
+ res_os_ruby!
48
+ rest-client
49
+ rspec (~> 3.0)
50
+
51
+ BUNDLED WITH
52
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Thomas
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.
@@ -0,0 +1,74 @@
1
+ # ResOS Wrapper for Ruby
2
+
3
+ This will help you access the ResOs API as described on https://documenter.getpostman.com/view/3308304/SzzehLGp?version=latesthttps://documenter.getpostman.com/view/3308304/SzzehLGp?version=latest
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'res_os_ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install res_os_ruby
20
+
21
+ ## Usage
22
+
23
+ ### CONFIGURATION
24
+
25
+ ```ruby
26
+ ResOs.configure do |config|
27
+ config.api_key = "<Your API key>"
28
+ end
29
+ ```
30
+
31
+ ### USAGE
32
+ #### Collection of bookings:
33
+ ```ruby
34
+ ResOs.bookings
35
+ ```
36
+
37
+ #### Collection of bookings for a specific date
38
+ ```ruby
39
+ ResOs.bookings(date: '2020-12-01')
40
+ ```
41
+ You can also pass in `:limit` and `:skip`.
42
+
43
+ #### Single booking:
44
+ ```ruby
45
+ ResOs.bookings(id: '<Booking ID>')
46
+ ```
47
+ #### Create booking:
48
+ ```ruby
49
+ ResOs.bookings(type: :post, <pass in bookings details>)
50
+ ```
51
+
52
+ #### Update booking
53
+ ```ruby
54
+ ResOs.bookings(
55
+ type: :put,
56
+ id: '<Booking ID>'
57
+ <pass in bookings details>
58
+ )
59
+ ```
60
+
61
+ ## Development
62
+
63
+ 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.
64
+
65
+ 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).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/res_os_ruby.
70
+
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "res_os_ruby"
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__)
@@ -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,3 @@
1
+ module ResOs
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'res_os/version'
4
+
5
+ module ResOs
6
+ class Configuration
7
+ attr_accessor :api_key, :api_url
8
+
9
+ def initialize
10
+ @api_key = ''
11
+ @api_url = 'https://api.resos.com/v1'
12
+ end
13
+
14
+ def headers
15
+ {
16
+ Authorization: "Basic #{Base64.strict_encode64 @api_key}"
17
+ }.freeze
18
+ end
19
+ end
20
+
21
+ def self.configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def self.reset
26
+ @configuration = Configuration.new
27
+ end
28
+
29
+ def self.configure
30
+ yield(configuration)
31
+ end
32
+
33
+ def self.tables
34
+ response = RestClient.get(
35
+ configuration.api_url + '/tables',
36
+ headers = configuration.headers
37
+ )
38
+ JSON.parse response.body.force_encoding('UTF-8')
39
+ end
40
+
41
+ def self.bookings(options = {})
42
+ method = (options[:type] || :get)
43
+ case method
44
+ when :post
45
+ payload = booking_options(options).to_json
46
+ headers = configuration.headers.deep_dup.merge!(content_type: :json, accept: :json)
47
+ when :put
48
+ raise StandardError, 'No booking id given' unless options[:id]
49
+
50
+ payload = booking_options(options).to_json
51
+ headers = configuration.headers.deep_dup.merge!(content_type: :json, accept: :json)
52
+ when :get
53
+ params = bookings_period(options)
54
+ headers = configuration.headers.deep_dup.merge!(params: params)
55
+ end
56
+ request = RestClient::Request.new(
57
+ method: method,
58
+ url: configuration.api_url + "/bookings#{options[:id] && '/' + options[:id]}",
59
+ payload: payload,
60
+ headers: headers
61
+ )
62
+ begin
63
+ response = request.execute
64
+ rescue StandardError => e
65
+ error = e
66
+ end
67
+ JSON.parse response.body.force_encoding('UTF-8')
68
+ end
69
+
70
+ private
71
+
72
+ def self.booking_options(options = {})
73
+ booking_options = { date: (options[:date] || Date.today.to_s),
74
+ time: (options[:time] || '12:15'),
75
+ people: (options[:people] || 2),
76
+ duration: (options[:duration] || 60),
77
+ guest: { name: (options[:name] || 'Walk-in Guest'),
78
+ email: (options[:email] || 'info@bocado.se'),
79
+ notificationEmail: (options[:notificationEmail] || false),
80
+ notificationSms: (options[:notificationSms] || false),
81
+ phone: (options[:phone] || '') },
82
+ languageCode: 'sv' }
83
+ booking_options
84
+ end
85
+
86
+ def self.bookings_period(options = {})
87
+ date = DateTime.parse(options[:date] || Date.today.to_s)
88
+ bookings_period =
89
+ {
90
+ fromDateTime: date.beginning_of_day.to_s,
91
+ toDateTime: date.end_of_day.to_s,
92
+ limit: (options[:limit] || 10),
93
+ skip: (options[:skip] || 0)
94
+ }
95
+ bookings_period
96
+ end
97
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/res_os/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "res_os_ruby"
5
+ spec.version = ResOs::VERSION
6
+ spec.authors = ["Thomas"]
7
+ spec.email = ["thomas@craftacademy.se"]
8
+
9
+ spec.summary = %q{Ruby wrapper for ResOs API.}
10
+ spec.description = %q{ This will help you access the ResOs API as described on https://documenter.getpostman.com/view/3308304/SzzehLGp?version=latesthttps://documenter.getpostman.com/view/3308304/SzzehLGp?version=latest }
11
+ spec.homepage = "https://github.com/CraftAcademyLabs/res_os_ruby"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/CraftAcademyLabs/res_os_ruby"
19
+ spec.metadata["changelog_uri"] = "https://github.com/CraftAcademyLabs/res_os_ruby/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: res_os_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Thomas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " This will help you access the ResOs API as described on https://documenter.getpostman.com/view/3308304/SzzehLGp?version=latesthttps://documenter.getpostman.com/view/3308304/SzzehLGp?version=latest "
14
+ email:
15
+ - thomas@craftacademy.se
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/res_os/version.rb
31
+ - lib/res_os_ruby.rb
32
+ - res_os_ruby.gemspec
33
+ homepage: https://github.com/CraftAcademyLabs/res_os_ruby
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/CraftAcademyLabs/res_os_ruby
38
+ source_code_uri: https://github.com/CraftAcademyLabs/res_os_ruby
39
+ changelog_uri: https://github.com/CraftAcademyLabs/res_os_ruby/CHANGELOG.md
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.7.9
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Ruby wrapper for ResOs API.
60
+ test_files: []