hungrytable 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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.sw*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@hungrytable --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hungrytable.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Chapmap
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Hungrytable
2
+
3
+ The purpose of this gem is to interact with the [OpenTable](http://www.opentable.com) REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hungrytable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hungrytable
18
+
19
+ ## Usage
20
+
21
+ You need to set some environment variable for this gem to work properly:
22
+
23
+ Observe:
24
+
25
+ # In ~/.bashrc
26
+ export OT_PARTNER_ID=<YOUR OPENTABLE PARTNER ID>
27
+ export OT_PARTNER_AUTH=<YOUR OPENTABLE PARTNER AUTH> # For XML feed only...
28
+ export OT_OAUTH_KEY=<YOUR OPENTABLE OAUTH KEY>
29
+ export OT_OAUTH_SECRET=<YOUR OPENTABLE OAUTH SECRET KEY>
30
+
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/RELEASE_NOTES.md ADDED
@@ -0,0 +1,11 @@
1
+ # Hungrytable - Ruby API Client for the OpenTable REST API
2
+
3
+ ## v0.0.1 (05/11/2012)
4
+
5
+ * Get relevant details about an individual restaurant.
6
+ * Search for availability at an individual restaurant.
7
+
8
+ ### Known Issues
9
+
10
+ OpenTable's API currently returns search results as an unsupported transaction,
11
+ but it is clearly marked as a thing in their API document.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hungrytable/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hungrytable"
7
+ s.version = Hungrytable::VERSION
8
+ s.authors = ["David Chapman"]
9
+ s.email = ["david@isotope11.com"]
10
+ s.homepage = "http://www.isotope11.com/"
11
+ s.summary = %q{Gem to interact with OpenTable's REST API}
12
+ s.description = %q{Gem to interact with OpenTable's REST API}
13
+
14
+ s.rubyforge_project = "hungrytable"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+
25
+ s.add_runtime_dependency 'oauth', '~> 0.4.5'
26
+ s.add_runtime_dependency 'json', '~> 1.7.1'
27
+
28
+ s.add_development_dependency "minitest"
29
+ s.add_development_dependency "minitest-reporters"
30
+ s.add_development_dependency "rake"
31
+ s.add_development_dependency "simplecov"
32
+ s.add_development_dependency 'simplecov-rcov'
33
+ s.add_development_dependency 'rcov', '0.9.11'
34
+ s.add_development_dependency 'pry'
35
+ end
36
+
@@ -0,0 +1,9 @@
1
+ require "uri"
2
+ require "json"
3
+ require "hungrytable/base"
4
+ require "hungrytable/version"
5
+ require "hungrytable/oauth_patch"
6
+ require "hungrytable/restaurant"
7
+
8
+ module Hungrytable
9
+ end
@@ -0,0 +1,26 @@
1
+ module Hungrytable
2
+ class Base
3
+ def validate_environment_variables
4
+ raise "Please set the environment variable OT_OAUTH_KEY to your OpenTable OAuth Table." unless ENV['OT_OAUTH_KEY']
5
+ raise "Please set the environment variable OT_OAUTH_SECRET to your OpenTable OAuth Secret Key." unless ENV['OT_OAUTH_SECRET']
6
+ raise "Please set the environment variable OT_PARTNER_ID to your OpentTable Partner ID." unless ENV['OT_PARTNER_ID']
7
+ end
8
+
9
+ def parse_uri_option(option_name, options)
10
+ val = options[option_name.to_sym]
11
+ raise "Missing required option: #{option_name}" if val.nil?
12
+ if val.is_a?(String)
13
+ val = CGI.escape(val).gsub(/[+]/, '%20')
14
+ end
15
+ instance_variable_set("@#{option_name}", val)
16
+ end
17
+
18
+ def parse_uri_options(*option_names, options)
19
+ option_names.each { |option_name| parse_uri_option(option_name, options) }
20
+ end
21
+
22
+ def parse_json(string)
23
+ JSON.parse(string)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'oauth'
2
+ module OAuth::Client
3
+ class Helper
4
+ def oauth_parameters
5
+ {
6
+ 'oauth_body_hash' => options[:body_hash],
7
+ 'oauth_callback' => options[:oauth_callback],
8
+ 'oauth_consumer_key' => options[:consumer].key,
9
+ 'oauth_token' => options[:token] ? options[:token].token : '',
10
+ 'oauth_signature_method' => options[:signature_method],
11
+ 'oauth_timestamp' => timestamp,
12
+ 'oauth_nonce' => nonce,
13
+ 'oauth_verifier' => options[:oauth_verifier],
14
+ 'oauth_version' => (options[:oauth_version] || '1.0'),
15
+ 'oauth_session_handle' => options[:oauth_session_handle]
16
+ }.reject { |k,v| v.to_s == "" && k.to_s != 'oauth_token' }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ module Hungrytable
2
+ class Restaurant < ::Hungrytable::Base
3
+ def initialize
4
+ validate_environment_variables
5
+
6
+ @consumer = OAuth::Consumer.new(
7
+ ENV['OT_OAUTH_KEY'],
8
+ ENV['OT_OAUTH_SECRET'],
9
+ realm: 'http://www.opentable.com/',
10
+ site: 'https://secure.opentable.com/api/otapi_v2.ashx',
11
+ request_token_path: '',
12
+ authorize_path: '',
13
+ access_token_path: '',
14
+ oauth_token: '',
15
+ oauth_version: '1.0',
16
+ http_method: :get
17
+ )
18
+
19
+ @access_token = OAuth::AccessToken.new(@consumer)
20
+ end
21
+
22
+ def get_details(restaurant_id)
23
+ uri = "/restaurant/?pid=#{ENV['OT_PARTNER_ID']}&rid=#{restaurant_id}"
24
+ response = @access_token.get(uri)
25
+ parse_json(response.body)
26
+ end
27
+
28
+ def search(options)
29
+ parse_uri_options(:restaurant_id, :date_time, :party_size, options)
30
+ uri = "/table/?pid=#{ENV['OT_PARTNER_ID']}&st=0&rid=#{@restaurant_id}&dt=#{@date_time}&ps=#{@party_size}"
31
+ response = @access_token.get(uri)
32
+ parse_json(response.body)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Hungrytable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ describe Hungrytable do
4
+ subject { Hungrytable }
5
+ it 'should be a class' do
6
+ subject.class.must_equal Module
7
+ end
8
+ end
@@ -0,0 +1,81 @@
1
+ require 'ansi'
2
+
3
+ module MiniTest
4
+ module Reporters
5
+ # A reporter identical to the standard MiniTest reporter.
6
+ #
7
+ # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
8
+ #
9
+ # @see https://github.com/seattlerb/minitest MiniTest
10
+ class JUnitReporter
11
+ include MiniTest::Reporter
12
+
13
+ def before_suites(suites, type)
14
+ end
15
+
16
+ def before_test(suite, test)
17
+ end
18
+
19
+ def pass(suite, test, test_runner)
20
+ end
21
+
22
+ def skip(suite, test, test_runner)
23
+ end
24
+
25
+ def failure(suite, test, test_runner)
26
+ end
27
+
28
+ def error(suite, test, test_runner)
29
+ end
30
+
31
+ def after_suites(suites, type)
32
+ time = Time.now - runner.start_time
33
+ i = 0
34
+ runner.report.each do |suite, tests|
35
+ File.open("#{suite.to_s.gsub(" ", '_').downcase}.xml", 'w') do |out|
36
+ out.puts '<?xml version="1.0" encoding="UTF-8" ?>'
37
+ out.puts "<testsuite errors=\"#{runner.errors}\" failures=\"#{runner.failures}\" tests=\"#{runner.test_count}\" time=\"#{time}\" timestamp=\"#{runner.start_time.strftime('%FT%R')}\">"
38
+ tests.each do |test, test_runner|
39
+ out.print "<testcase classname=\"#{suite}\" name=\"#{test}\" time=\"0\">"
40
+ message = message_for(test_runner)
41
+ out.puts "\n#{message}" if message
42
+ out.puts '</testcase>'
43
+ end
44
+ out.puts '</testsuite>'
45
+ end
46
+ end
47
+ end
48
+
49
+ private
50
+ def location(exception)
51
+ last_before_assertion = ''
52
+
53
+ exception.backtrace.reverse_each do |s|
54
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
55
+ last_before_assertion = s
56
+ end
57
+
58
+ last_before_assertion.sub(/:in .*$/, '')
59
+ end
60
+
61
+ def message_for(test_runner)
62
+ suite = test_runner.suite
63
+ test = test_runner.test
64
+ e = test_runner.exception
65
+
66
+ case test_runner.result
67
+ when :pass then nil
68
+ when :skip then "<skipped message=\"\"/>"
69
+ when :failure then "<failure message=\"#{e.message}\" type=\"failure\">#{location(e)}:\n#{e.message}\n</failure>"
70
+ when :error then "<error message=\"#{e.message}\" type=\"error\">#{location(e)}:\n#{e.message}\n</error>"
71
+ end
72
+ end
73
+
74
+ def status
75
+ '%d tests, %d assertions, %d failures, %d errors, %d skips' %
76
+ [runner.test_count, runner.assertion_count, runner.failures, runner.errors, runner.skips]
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,23 @@
1
+ # Set up simplecov
2
+ require 'simplecov'
3
+ require 'simplecov-rcov'
4
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest/reporters'
8
+
9
+ require 'ostruct'
10
+ require 'pry'
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ # Set up minitest
16
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
17
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
18
+ if ENV['JENKINS']
19
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::JUnitReporter.new
20
+ end
21
+
22
+ # Load the app
23
+ require File.expand_path("../../lib/hungrytable.rb", __FILE__)
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ describe Hungrytable::Restaurant do
4
+ subject { Hungrytable::Restaurant }
5
+
6
+ it 'should be a class' do
7
+ subject.class.must_be_kind_of Class
8
+ end
9
+
10
+ %w{ get_details search }.each do |meth|
11
+ it "should respond to #{meth}" do
12
+ assert subject.new.respond_to?(meth.to_sym), true
13
+ end
14
+ end
15
+
16
+ describe 'when getting details' do
17
+ before do
18
+ @restaurant = subject.new
19
+ end
20
+
21
+ it 'should return relevant details about an individual restaurant' do
22
+ response = @restaurant.get_details(82591)
23
+ response.must_be_kind_of Hash
24
+ end
25
+
26
+ it 'should look for availability at an inidividual restaurant' do
27
+ date_time = Time.now.strftime "%-m/#{Time.now.day + 1}/%Y %-l:%M %p"
28
+ response = @restaurant.search({ restaurant_id: 82591, date_time: date_time, party_size: 2 })
29
+ response.must_be_kind_of Hash
30
+ end
31
+
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hungrytable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Chapman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: &6926620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *6926620
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &6925700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.7.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *6925700
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &6924760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *6924760
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest-reporters
49
+ requirement: &6923840 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *6923840
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &6922980 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *6922980
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &6922200 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *6922200
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov-rcov
82
+ requirement: &6921360 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *6921360
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &6854660 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - =
97
+ - !ruby/object:Gem::Version
98
+ version: 0.9.11
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *6854660
102
+ - !ruby/object:Gem::Dependency
103
+ name: pry
104
+ requirement: &6852260 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *6852260
113
+ description: Gem to interact with OpenTable's REST API
114
+ email:
115
+ - david@isotope11.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .rvmrc
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - RELEASE_NOTES.md
126
+ - Rakefile
127
+ - hungrytable.gemspec
128
+ - lib/hungrytable.rb
129
+ - lib/hungrytable/base.rb
130
+ - lib/hungrytable/oauth_patch.rb
131
+ - lib/hungrytable/restaurant.rb
132
+ - lib/hungrytable/version.rb
133
+ - test/hungrytable_test.rb
134
+ - test/support/minitest_junit.rb
135
+ - test/test_helper.rb
136
+ - test/unit/hungrytable/restaurant_test.rb
137
+ homepage: http://www.isotope11.com/
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project: hungrytable
157
+ rubygems_version: 1.8.10
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Gem to interact with OpenTable's REST API
161
+ test_files:
162
+ - test/hungrytable_test.rb
163
+ - test/support/minitest_junit.rb
164
+ - test/test_helper.rb
165
+ - test/unit/hungrytable/restaurant_test.rb