rbvore 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class Resource
5
+ module Fetchers
6
+ def api
7
+ @api ||= API.new
8
+ end
9
+
10
+ def endpoint(id: nil, location_id: nil, ticket_id: nil) # rubocop:disable Metrics/MethodLength
11
+ case
12
+ when self == Location
13
+ API.endpoint(Location, id || location_id)
14
+ when self == Ticket
15
+ check_required("location_id", location_id)
16
+ API.endpoint(Location, location_id, Ticket, id || ticket_id)
17
+ when [TenderType, Table, Employee, RevenueCenter].include?(self)
18
+ check_required("location_id", location_id)
19
+ API.endpoint(Location, location_id, self, id)
20
+ else
21
+ check_required("location_id", location_id)
22
+ check_required("ticket_id", ticket_id)
23
+ API.endpoint(Location, location_id, Ticket, ticket_id, self, id)
24
+ end
25
+ end
26
+
27
+ def check_required(name, value)
28
+ raise Error, "#{name} is required" if value.nil?
29
+ end
30
+
31
+ def fetch_one(id: nil, location_id: nil, ticket_id: nil, params: {}, api_key: nil)
32
+ check_required("id", id)
33
+ api.fetch_one(
34
+ endpoint(id: id, location_id: location_id, ticket_id: ticket_id),
35
+ self,
36
+ params: params,
37
+ api_key: api_key,
38
+ )
39
+ end
40
+
41
+ def fetch_all(location_id: nil, ticket_id: nil, params: {}, api_key: nil)
42
+ api.fetch_all(
43
+ endpoint(location_id: location_id, ticket_id: ticket_id),
44
+ self,
45
+ params: params,
46
+ api_key: api_key,
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class Resource
5
+ module Names
6
+ def underscore(value)
7
+ return value unless /[A-Z-]/.match?(value)
8
+
9
+ word = value.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
10
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
11
+ word.tr!("-", "_")
12
+ word.downcase!
13
+ word
14
+ end
15
+
16
+ def singularize
17
+ @singularize ||= underscore(name.split("::").last)
18
+ end
19
+
20
+ def list_name
21
+ @list_name ||= "#{singularize}_list"
22
+ end
23
+
24
+ def pluralize
25
+ @pluralize ||=
26
+ case
27
+ when singularize.end_with?('y')
28
+ singularize[0..-2] + 'ies'
29
+ else
30
+ singularize + "s"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class Resource
5
+ module Parsers
6
+ def parse_collection(ary, klass)
7
+ if ary.is_a? Hash
8
+ list = ary.dig("_embedded", klass.pluralize)
9
+ ary = list if list.is_a? Array
10
+ end
11
+ ary.map { |obj|
12
+ parse_object(obj, klass)
13
+ }
14
+ end
15
+
16
+ def parse_object(obj, klass)
17
+ if obj.is_a?(Hash)
18
+ Rbvore.constantize(klass).new(obj)
19
+ else
20
+ obj
21
+ end
22
+ end
23
+
24
+ def parse_timestamp(value)
25
+ return nil if value.nil?
26
+
27
+ if value.is_a? Time
28
+ value
29
+ else
30
+ Time.at(value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class RevenueCenter < Resource
5
+ attr_accessor :id, :name, :pos_id, :default
6
+
7
+ def initialize(hash)
8
+ set_attributes(hash)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class Table < Resource
5
+ attr_accessor :id, :available, :name, :number, :pos_id, :seats
6
+ attr_collections open_tickets: "ticket"
7
+ attr_objects revenue_center: "revenue_center"
8
+
9
+ def initialize(hash)
10
+ set_attributes(hash)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class TenderType < Resource
5
+ attr_accessor :id, :allows_tips, :name, :pos_id
6
+
7
+ def initialize(hash)
8
+ set_attributes(hash)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class Ticket < Resource
5
+ attr_accessor :id, :pos_id, :guest_count, :name, :open, :ticket_number, :totals,
6
+ :location_id, :auto_send, :fire_date, :fire_time, :ready_date,
7
+ :ready_time, :void
8
+ attr_timestamp_accessor :closed_at, :opened_at
9
+ attr_collections(
10
+ items: Item,
11
+ payments: Payment,
12
+ service_charges: TicketServiceCharge,
13
+ discounts: TicketDiscount,
14
+ voided_items: VoidedItem,
15
+ )
16
+ attr_objects(
17
+ table: Table,
18
+ employee: Employee,
19
+ order_type: OrderType,
20
+ revenue_center: RevenueCenter,
21
+ )
22
+
23
+ def self.fetch_all(location_id:, open: nil, table_id: nil, api_key: nil)
24
+ super(
25
+ location_id: location_id,
26
+ params: build_where_clause(open: open, table_id: table_id),
27
+ api_key: api_key,
28
+ )
29
+ end
30
+
31
+ def self.build_where_clause(open: nil, table_id: nil) # rubocop:disable Metrics/CyclomaticComplexity
32
+ case
33
+ when !open.nil? && table_id.nil?
34
+ { where: "eq(open,#{open})" }
35
+ when open.nil? && !table_id.nil?
36
+ { where: "eq(@table.id,'#{table_id}')" }
37
+ when !open.nil? && !table_id.nil?
38
+ { where: "and(eq(open,#{open}),eq(@table.id,'#{table_id}'))" }
39
+ end
40
+ end
41
+
42
+ def initialize(hash)
43
+ set_attributes(hash)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class TicketDiscount < Resource
5
+ attr_accessor :id, :name, :value, :comment
6
+ attr_objects discount: Discount
7
+
8
+ def initialize(hash)
9
+ set_attributes(hash)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ class TicketServiceCharge < Resource
5
+ attr_accessor :id, :name, :price, :comment
6
+
7
+ def initialize(hash)
8
+ set_attributes(hash)
9
+ end
10
+
11
+ def self.create(location_id:, ticket_id:, name:, amount:, api_key: nil)
12
+ response = api.request(
13
+ :post,
14
+ API.endpoint(Location, location_id, Ticket, ticket_id, "service_charges"),
15
+ body: [{ service_charge: name, amount: amount }],
16
+ api_key: api_key,
17
+ )
18
+ raise response.error unless response.success?
19
+
20
+ TicketServiceCharge.new(response.json_body)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbvore
4
+ VERSION = "0.1.1"
5
+ end
data/rbvore.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rbvore/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rbvore"
7
+ spec.version = Rbvore::VERSION
8
+ spec.authors = ["Scott Yoder"]
9
+ spec.email = ["syoder@radiusnetworks.com"]
10
+
11
+ spec.summary = %q{Ruby interface to Omnivore's API}
12
+ spec.description = %q{Ruby interface to Omnivore's API}
13
+ spec.homepage = "https://github.com/radiusnetworks/rbvore"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/radiusnetworks/rbvore"
18
+ spec.metadata["changelog_uri"] = "https://github.com/radiusnetworks/rbvore"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbvore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Yoder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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 interface to Omnivore's API
56
+ email:
57
+ - syoder@radiusnetworks.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/rspec
74
+ - bin/rubocop
75
+ - bin/setup
76
+ - lib/rbvore.rb
77
+ - lib/rbvore/api.rb
78
+ - lib/rbvore/discount.rb
79
+ - lib/rbvore/employee.rb
80
+ - lib/rbvore/item.rb
81
+ - lib/rbvore/item_modifier.rb
82
+ - lib/rbvore/link.rb
83
+ - lib/rbvore/location.rb
84
+ - lib/rbvore/menu_category.rb
85
+ - lib/rbvore/menu_item.rb
86
+ - lib/rbvore/order_type.rb
87
+ - lib/rbvore/payment.rb
88
+ - lib/rbvore/resource.rb
89
+ - lib/rbvore/resource/fetchers.rb
90
+ - lib/rbvore/resource/names.rb
91
+ - lib/rbvore/resource/parsers.rb
92
+ - lib/rbvore/revenue_center.rb
93
+ - lib/rbvore/table.rb
94
+ - lib/rbvore/tender_type.rb
95
+ - lib/rbvore/ticket.rb
96
+ - lib/rbvore/ticket_discount.rb
97
+ - lib/rbvore/ticket_service_charge.rb
98
+ - lib/rbvore/version.rb
99
+ - rbvore.gemspec
100
+ homepage: https://github.com/radiusnetworks/rbvore
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: https://github.com/radiusnetworks/rbvore
105
+ source_code_uri: https://github.com/radiusnetworks/rbvore
106
+ changelog_uri: https://github.com/radiusnetworks/rbvore
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Ruby interface to Omnivore's API
126
+ test_files: []