omnivore-io 0.0.1

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
+ SHA1:
3
+ metadata.gz: 45be8df81ea56b02b94b19fd0e72bb1586de33b2
4
+ data.tar.gz: d5234db929409f4bd3c4ddeebb0837b8f6327ca2
5
+ SHA512:
6
+ metadata.gz: 2a063d4d8a67e70412e63271f73f2b6bd4c6bb816d3cad1eaed73f4fc58dd7c0b178cf419c88bb2f1017ca0bcf318bcdbf37f4757007c5edfe7588d3f9794518
7
+ data.tar.gz: 03c7a081b78b49833ffd6d5acde2e5e5fab46a97c5dcfb4b47984d9134073e5fb2c9345083a31d79d79430bbedaa85a9ece9495bf9ab131d9525cdeb0a878943
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ .ruby-version
3
+ .ruby-gemset
4
+ *.gem
5
+ .bundle
6
+ Gemfile.lock
7
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omnivore-io.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Amvse, Inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ Omnivore.io Ruby Client
2
+ =======================
3
+
4
+ The Omnivore.io Ruby Client is used to interact with the [Omnivore API](https://panel.omnivore.io/docs/api) from Ruby.
5
+
6
+ Usage
7
+ -----
8
+
9
+ Start by creating a connection to Omnivore with your credentials:
10
+
11
+ ```ruby
12
+ require 'omnivore-io'
13
+ $omnivore_io = OmnivoreIO::API.new(api_key: "API_KEY_HERE")
14
+ ```
15
+
16
+ Now you can make requests to the API.
17
+
18
+ Requests
19
+ --------
20
+
21
+ *TODO*
22
+
23
+ Meta
24
+ ----
25
+
26
+ Based heavily on [heroku.rb](https://github.com/heroku/heroku.rb), originally authored by geemus (Wesley Beary) and Pedro Belo. Thanks, Heroku!
27
+
28
+ Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
@@ -0,0 +1 @@
1
+ require(File.join(File.dirname(__FILE__), "omnivore-io", "api"))
@@ -0,0 +1,105 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ unless $LOAD_PATH.include?(__LIB_DIR__)
6
+ $LOAD_PATH.unshift(__LIB_DIR__)
7
+ end
8
+
9
+ require "omnivore-io/api/errors"
10
+ require "omnivore-io/api/version"
11
+
12
+ module OmnivoreIO
13
+ module OmnivoreObject
14
+
15
+ def self.included base
16
+ base.send :include, InstanceMethods
17
+ base.extend ClassMethods
18
+ end
19
+
20
+ module ClassMethods
21
+ attr_accessor :_json_attributes
22
+
23
+ def json_attr_accessor(*attributes)
24
+ self._json_attributes = attributes
25
+ attributes.each do |attribute|
26
+ attr_accessor attribute
27
+ end
28
+ end
29
+ end
30
+
31
+ module InstanceMethods
32
+
33
+ def as_json(options={})
34
+ json = {}
35
+ self.class._json_attributes.each do |attr|
36
+ val = self.send attr
37
+ json[attr] = val
38
+ end
39
+ json
40
+ end
41
+
42
+ def merge!(object)
43
+ self.class._json_attributes.each do |attr|
44
+ if object.respond_to?(attr)
45
+ if val = object.send(attr)
46
+ self.send "#{attr}=".to_sym, val
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ class API
57
+
58
+ HEADERS = {
59
+ :content_type => :json,
60
+ :accept => :json,
61
+ :'Api-Key' => 'API_KEY_HERE'
62
+ }
63
+
64
+ OPTIONS = {
65
+ :host => 'https://api.omnivore.io/',
66
+ :api_version => '0.1'
67
+ }
68
+
69
+ def initialize(options={})
70
+ options = OPTIONS.merge(options)
71
+
72
+ @api_key = options.delete(:api_key) || ENV['OMNIVORE_IO_API_KEY']
73
+ end
74
+
75
+ def api_key
76
+ @api_key
77
+ end
78
+
79
+ def request(method, endpoint, query={}, headers={})
80
+ headers.merge!({ 'content_type' => :json, 'Api-Key' => self.api_key })
81
+ response = case method
82
+ when :get
83
+ url = "#{OPTIONS[:host]}#{OPTIONS[:api_version]}#{endpoint}"
84
+ if query.keys.length
85
+ url << "?"
86
+ url << URI.encode_www_form(query)
87
+ end
88
+ RestClient.get url, headers
89
+ when :post
90
+ url = "#{OPTIONS[:host]}#{OPTIONS[:api_version]}#{endpoint}"
91
+ payload = query.as_json.to_json
92
+ RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers)
93
+ end
94
+ # TODO: handle errors
95
+ JSON.parse(response.to_str)
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ require "omnivore-io/api/location"
102
+ require "omnivore-io/api/menu_item"
103
+ require "omnivore-io/api/modifier"
104
+ require "omnivore-io/api/order_type"
105
+ require "omnivore-io/api/ticket"
@@ -0,0 +1,28 @@
1
+ module OmnivoreIO
2
+ class API
3
+ module Errors
4
+ class Error < StandardError; end
5
+
6
+ class ErrorWithResponse < Error
7
+ attr_reader :response
8
+
9
+ def initialize(message, response)
10
+ message = message << "\nbody: #{response.body.inspect}"
11
+ super message
12
+ @response = response
13
+ end
14
+ end
15
+
16
+ class Unauthorized < ErrorWithResponse; end
17
+ class VerificationRequired < ErrorWithResponse; end
18
+ class Forbidden < ErrorWithResponse; end
19
+ class NotFound < ErrorWithResponse; end
20
+ class Timeout < ErrorWithResponse; end
21
+ class Locked < ErrorWithResponse; end
22
+ class RateLimitExceeded < ErrorWithResponse; end
23
+ class RequestFailed < ErrorWithResponse; end
24
+ class NilApp < ErrorWithResponse; end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,57 @@
1
+ module OmnivoreIO
2
+ class Location
3
+ include OmnivoreObject
4
+
5
+ attr_accessor :client
6
+ json_attr_accessor :id, :address, :name, :phone, :website, :status
7
+
8
+ def initialize(client, attributes={})
9
+ self.client = client
10
+ attributes.each do |key, value|
11
+ if self.respond_to? "#{key}=".to_sym
12
+ self.send "#{key}=".to_sym, value
13
+ end
14
+ end
15
+ end
16
+
17
+ def menu_items(options={})
18
+ client.get_menu_items(self.id, options)
19
+ end
20
+
21
+ def order_types(options={})
22
+ client.get_order_types(self.id, options)
23
+ end
24
+
25
+ def tickets(options={})
26
+ client.get_tickets(self.id, options)
27
+ end
28
+
29
+ def online?
30
+ self.status == 'online'
31
+ end
32
+
33
+ end
34
+
35
+ class API
36
+
37
+ def get_locations(options={})
38
+ response = request(
39
+ :get,
40
+ '/locations',
41
+ options
42
+ )
43
+ (response['_embedded']['locations'] || []).map do |location_hash|
44
+ OmnivoreIO::Location.new self, location_hash
45
+ end
46
+ end
47
+
48
+ def get_location(location_id)
49
+ response = request(
50
+ :get,
51
+ "/locations/#{location_id}"
52
+ )
53
+ OmnivoreIO::Location.new self, response
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ module OmnivoreIO
2
+ class MenuItem
3
+ include OmnivoreObject
4
+
5
+ attr_accessor :client
6
+ json_attr_accessor :id, :location_id, :name, :price, :price_levels,
7
+ :in_stock, :modifier_groups_count
8
+
9
+ def initialize(client, attributes={})
10
+ self.client = client
11
+ attributes.each do |key, value|
12
+ if self.respond_to? "#{key}=".to_sym
13
+ self.send "#{key}=".to_sym, value
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ class API
21
+
22
+ def get_menu_items(location_id, options={})
23
+ response = request(:get, "/locations/#{location_id}/menu/items", options)
24
+ (response['_embedded']['menu_items'] || []).map do |menu_item_hash|
25
+ OmnivoreIO::MenuItem.new self, menu_item_hash.merge(location_id: location_id)
26
+ end
27
+ end
28
+
29
+ def get_menu_item(location_id, menu_item_id)
30
+ response = request(:get, "/locations/#{location_id}/menu/items/#{menu_item_id}")
31
+ OmnivoreIO::MenuItem.new self, response.merge(location_id: location_id)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module OmnivoreIO
2
+ class Modifier
3
+ include OmnivoreObject
4
+
5
+ attr_accessor :client
6
+ json_attr_accessor :id, :name, :price, :price_levels,
7
+ :price_per_unit
8
+
9
+ def initialize(client, attributes={})
10
+ self.client = client
11
+ attributes.each do |key, value|
12
+ if self.respond_to? "#{key}=".to_sym
13
+ self.send "#{key}=".to_sym, value
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ class API
21
+
22
+ def get_modifiers(location_id, options={})
23
+ response = request(:get, "/locations/#{location_id}/menu/modifiers", options)
24
+ (response['_embedded']['modifiers'] || []).map do |modifier_hash|
25
+ OmnivoreIO::Modifier.new self, modifier_hash.merge(location_id: location_id)
26
+ end
27
+ end
28
+
29
+ def get_modifier(location_id, modifier_id)
30
+ response = request(:get, "/locations/#{location_id}/menu/modifiers/#{modifier_id}")
31
+ OmnivoreIO::Modifier.new self, response.merge(location_id: location_id)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ module OmnivoreIO
2
+ class OrderType
3
+ include OmnivoreObject
4
+
5
+ attr_accessor :client
6
+ json_attr_accessor :id, :location_id, :available, :name
7
+
8
+ def initialize(client, attributes={})
9
+ self.client = client
10
+ attributes.each do |key, value|
11
+ if self.respond_to? "#{key}=".to_sym
12
+ self.send "#{key}=".to_sym, value
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ class API
20
+
21
+ def get_order_types(location_id, options={})
22
+ response = request(:get, "/locations/#{location_id}/order_types", options)
23
+ (response['_embedded']['order_types'] || []).map do |order_type_hash|
24
+ OmnivoreIO::OrderType.new self, order_type_hash.merge(location_id: location_id)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,63 @@
1
+ module OmnivoreIO
2
+ class Ticket
3
+ include OmnivoreObject
4
+
5
+ attr_accessor :client, :items
6
+ json_attr_accessor :id, :location_id, :auto_send, :closed_at,
7
+ :guest_count, :name, :open, :opened_at, :ticket_number, :totals, :employee, :order_type, :revenue_center
8
+
9
+ def initialize(client, attributes={})
10
+ self.client = client
11
+ self.items = []
12
+ attributes.each do |key, value|
13
+ if self.respond_to? "#{key}=".to_sym
14
+ self.send "#{key}=".to_sym, value
15
+ end
16
+ end
17
+ end
18
+
19
+ def open!
20
+ payload = {
21
+ "employee" => self.employee,
22
+ "order_type" => self.order_type,
23
+ "revenue_center" => self.revenue_center,
24
+ "guest_count" => self.guest_count,
25
+ "name" => self.name,
26
+ "auto_send" => self.auto_send
27
+ }
28
+ self.merge! self.client.open_ticket(self.location_id, payload)
29
+ end
30
+
31
+ end
32
+
33
+ class API
34
+
35
+ def get_tickets(location_id, options={})
36
+ response = request(:get, "/locations/#{location_id}/tickets", options)
37
+ (response['_embedded']['tickets'] || []).map do |ticket_hash|
38
+ OmnivoreIO::Ticket.new self, ticket_hash.merge(location_id: location_id)
39
+ end
40
+ end
41
+
42
+ def get_ticket(location_id, ticket_id)
43
+ response = request(:get, "/locations/#{location_id}/tickets/#{ticket_id}")
44
+ OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
45
+ end
46
+
47
+ def open_ticket(location_id, ticket_json)
48
+ response = request(:post, "/locations/#{location_id}/tickets", ticket_json)
49
+ OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
50
+ end
51
+
52
+ def add_menu_item_to_ticket(location_id, ticket_id, payload_json)
53
+ response = request(:post, "/locations/#{location_id}/tickets/#{ticket_id}/items", payload_json)
54
+ OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
55
+ end
56
+
57
+ def add_payment_to_ticket(location_id, ticket_id, payload_json)
58
+ response = request(:post, "/locations/#{location_id}/tickets/#{ticket_id}/payments", payload_json)
59
+ response
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module OmnivoreIO
2
+ class API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omnivore-io/api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omnivore-io"
7
+ s.version = OmnivoreIO::API::VERSION
8
+ s.authors = ["Zane Shannon"]
9
+ s.email = ["zcs@amvse.com"]
10
+ s.homepage = "http://github.com/amvse/omnivore-io"
11
+ s.license = 'MIT'
12
+ s.summary = %q{Ruby Client for the Omnivore.io API}
13
+ s.description = %q{Ruby Client for the Omnivore.io API}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency 'rest_client'
21
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnivore-io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zane Shannon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-21 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
+ description: Ruby Client for the Omnivore.io API
28
+ email:
29
+ - zcs@amvse.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.md
37
+ - README.md
38
+ - lib/omnivore-io.rb
39
+ - lib/omnivore-io/api.rb
40
+ - lib/omnivore-io/api/errors.rb
41
+ - lib/omnivore-io/api/location.rb
42
+ - lib/omnivore-io/api/menu_item.rb
43
+ - lib/omnivore-io/api/modifier.rb
44
+ - lib/omnivore-io/api/order_type.rb
45
+ - lib/omnivore-io/api/ticket.rb
46
+ - lib/omnivore-io/api/version.rb
47
+ - omnivore-io.gemspec
48
+ homepage: http://github.com/amvse/omnivore-io
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.8
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Ruby Client for the Omnivore.io API
72
+ test_files: []