allmenus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/fixtures/allmenus_cassettes/*.yml
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'minitest', '4.7.5'
5
+ gem 'webmock'
6
+ gem 'vcr'
7
+ gem 'pry'
8
+ gem 'pry-debugger'
9
+ gem 'guard'
10
+ gem 'guard-minitest'
11
+ gem 'turn'
12
+ end
13
+ # Specify your gem's dependencies in allmenus.gemspec
14
+ gemspec
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+
5
+ guard :minitest do
6
+ ## with Minitest::Unit
7
+ #watch(%r{^test/(.*)\/?test_(.*)\.rb})
8
+ #watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
9
+ #watch(%r{^test/test_helper\.rb}) { 'test' }
10
+
11
+ #with Minitest::Spec
12
+ watch(%r{^spec/(.*)_spec\.rb})
13
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ watch(%r{^spec/spec_helper\.rb}) { 'spec' }
15
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 gregory
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.
@@ -0,0 +1,35 @@
1
+ # Allmenus
2
+
3
+ This is the unofficial ruby wrapper for the Allmenus.com API, the nation's largest, fastest growing network of restaurants
4
+
5
+ [http://developer.allmenus.com/](http://developer.allmenus.com/)
6
+
7
+ Still a wip for the moment but if you want to contribute feel free to hit me up
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'allmenus'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install allmenus
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ Allmenus.configure{|c| c.api_key = ENV['ALLMENUS_API_KEY']; c.log_request = true}
27
+ Allmenus::Menu.find(menu_id)
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'libs/allmenus'
6
+ t.test_files = FileList['spec/lib/allmenus/*_spec.rb', 'spec/lib/*_spec.rb']
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'allmenus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "allmenus"
8
+ spec.version = Allmenus::VERSION
9
+ spec.authors = ["gregory"]
10
+ spec.email = ["greg2502@gmail.com"]
11
+ spec.description = %q{A ruby client for the allmenus API}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/gregory/allmenus"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "bundler", "~> 1.3"
22
+ spec.add_dependency "rack"
23
+ spec.add_dependency "faraday"
24
+ spec.add_dependency "json"
25
+ spec.add_dependency "happymapper"
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'rack'
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'happymapper'
5
+
6
+ Dir[File.dirname(__FILE__) + '/allmenus/*.rb'].each do |file|
7
+ require file
8
+ end
9
+
10
+ module Allmenus
11
+ class<<self
12
+ attr_accessor :config
13
+ end
14
+
15
+ def self.configure
16
+ self.config = Allmenus::Configuration.new.tap do |configuration|
17
+ yield(configuration)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Allmenus
2
+ class Configuration < Struct.new(:api_key, :log_request)
3
+ def log_request
4
+ self[:log_request] || false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module Allmenus
2
+ class Connection
3
+ API_URL = 'http://api.allmenus.com'
4
+ API_VERSION = '2'
5
+
6
+ def self.connection(faraday_adapter=Faraday.default_adapter)
7
+ Faraday.new(url: self.url) do |faraday|
8
+ faraday.response :logger if Allmenus.config.log_request# log the requests to stdout
9
+ faraday.adapter faraday_adapter
10
+ end
11
+ end
12
+
13
+ def self.get(params={})
14
+ self.connection.get(self.uri(params)).tap do |response|
15
+ response.env[:body] = response.body.gsub(/\t|\n/, '') #clean the dirty response
16
+ end
17
+ end
18
+
19
+ def self.uri query_params
20
+ params = {
21
+ v: API_VERSION,
22
+ api_key: ::Allmenus.config.api_key
23
+ }
24
+ params.merge! query_params
25
+ q = ::Rack::Utils.build_query params
26
+ "/restaurant?#{q}"
27
+ end
28
+
29
+ def self.url
30
+ API_URL
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module Allmenus
2
+ class Location
3
+ attr_reader :address, :city, :state, :zip_code
4
+
5
+ def initialize(address, city, state, zip_code)
6
+ @address = address
7
+ @city = city
8
+ @state = state
9
+ @zip_cde = zip_code
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'menus/group'
2
+ module Allmenus
3
+ class Menu
4
+ include ::HappyMapper
5
+
6
+ attribute :id, Integer, tag: 'id'
7
+ has_many :groups, Menus::Group
8
+
9
+ def self.find(id)
10
+ response = Allmenus::Connection.get({restaurant_id: id, type: 'menu'})
11
+ self.parse(response.body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'item'
2
+ module Allmenus::Menus
3
+ class Category
4
+ include ::HappyMapper
5
+
6
+ attribute :id, Integer
7
+ element :name, String
8
+ element :description, String
9
+ has_many :items, Allmenus::Menus::Item
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'category'
2
+
3
+ module Allmenus::Menus
4
+ class Group
5
+ include ::HappyMapper
6
+
7
+ attribute :id, Integer
8
+ element :name, String
9
+ has_many :categories, Allmenus::Menus::Category
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Allmenus::Menus
2
+ class Item
3
+ include ::HappyMapper
4
+
5
+ attribute :id, Integer, tag: 'id'
6
+ element :name, String
7
+ element :description, String
8
+ element :size, Float, tag: 'sizes'
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module Allmenus
2
+ class Restaurant
3
+ include ::HappyMapper
4
+
5
+ attribute :id, Integer, tag: 'id'
6
+ element :name, String, tag: 'restaurant_name'
7
+ element :phone_number, String
8
+ element :address, String
9
+ element :city, String
10
+ element :state, String
11
+ element :zip_code, Integer
12
+ attr_accessor :location
13
+
14
+ def self.find(id)
15
+ response = Allmenus::Connection.get({restaurant_id: id, type: 'info'})
16
+ self.parse(response.body).tap do |r|
17
+ r.location = Location.new(r.address, r.city, r.state, r.zip_code)
18
+ end
19
+ end
20
+
21
+ def menu
22
+ @_menu ||= Allmenus::Menu.find(self.id)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Allmenus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Allmenus::Configuration do
4
+ subject { Allmenus::Configuration.new }
5
+
6
+ it "let's us assign api_key" do
7
+ subject.api_key = "foo"
8
+ subject.api_key.must_equal "foo"
9
+ end
10
+ it "let's set the logging to true" do
11
+ subject.log_request = true
12
+ subject.log_request.must_equal true
13
+ end
14
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Allmenus::Connection do
4
+ subject { Allmenus::Connection }
5
+
6
+ describe '.url' do
7
+ it 'returns the url of the api' do
8
+ subject.url.must_equal 'http://api.allmenus.com'
9
+ end
10
+ end
11
+
12
+ describe '.uri' do
13
+ let(:api_key) { ENV['ALLMENUS_API_KEY'] }
14
+ let(:params) do
15
+ {
16
+ restaurant_id: 12345,
17
+ type: 'request_type',
18
+ return_type: 'bar'
19
+ }
20
+ end
21
+
22
+ before do
23
+ Allmenus.configure do |c|
24
+ c.api_key = api_key
25
+ end
26
+ end
27
+
28
+ it 'contains the required parameters in the uri' do
29
+ uri = subject.uri(params)
30
+
31
+ uri.must_match %r{restaurant\?}
32
+ uri.must_match Regexp.new("type=#{params[:type]}")
33
+ uri.must_match Regexp.new("restaurant_id=#{params[:restaurant_id]}")
34
+ uri.must_match Regexp.new("v=#{subject::API_VERSION}")
35
+ uri.must_match Regexp.new("api_key=#{api_key}")
36
+ end
37
+ end
38
+
39
+ describe '.connection(faraday_adapter)' do
40
+ let(:faraday_adapter) { Faraday::Adapter::NetHttp }
41
+
42
+ it 'returns a Faraday::Connection with the right params' do
43
+ connection = subject.connection(Faraday.default_adapter)
44
+ connection.must_be_instance_of Faraday::Connection
45
+ connection.builder.handlers.must_include faraday_adapter
46
+ end
47
+
48
+ it 'returns a Faraday::Connection with a default adapter' do
49
+ subject.connection.builder.handlers.must_include faraday_adapter
50
+ end
51
+
52
+ it "wont log the request by default" do
53
+ subject.connection.builder.handlers.wont_include Faraday::Response::Logger
54
+ end
55
+ end
56
+
57
+ describe '.get(params)' do
58
+ before do
59
+ VCR.insert_cassette 'restaurant', record: :new_episodes
60
+ end
61
+ after do
62
+ VCR.eject_cassette
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../../spec_helper'
2
+ describe Allmenus::Menu do
3
+ subject{ Allmenus::Menu }
4
+
5
+ before do
6
+ VCR.insert_cassette 'menu', record: :new_episodes
7
+ end
8
+ after do
9
+ VCR.eject_cassette
10
+ end
11
+
12
+ describe '.find' do
13
+ subject{ Allmenus::Menu.find(58736) }
14
+
15
+ it 'returns a new menu with at least 1 group' do
16
+ subject.id.must_equal 58736
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../spec_helper'
2
+ describe Allmenus::Restaurant do
3
+ subject{ Allmenus::Restaurant }
4
+
5
+ before do
6
+ VCR.insert_cassette 'restaurant'
7
+ end
8
+ after do
9
+ VCR.eject_cassette
10
+ end
11
+
12
+ describe '.find' do
13
+ subject { Allmenus::Restaurant.find(294063) }
14
+
15
+ it 'returns a new restaurant' do
16
+ subject.must_be_instance_of Allmenus::Restaurant
17
+ end
18
+
19
+ [:name, :phone_number, :address, :city, :state, :zip_code].each do |attribute|
20
+ it "returns a restaurant with a #{attribute}" do
21
+ subject.must_respond_to attribute
22
+ subject.send(attribute).wont_be_nil
23
+ end
24
+ end
25
+
26
+ it 'returns a restaurant with a location' do
27
+ subject.must_respond_to :location
28
+ subject.location.must_be_instance_of Allmenus::Location
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../../spec_helper'
2
+ require "allmenus/version"
3
+
4
+ describe Allmenus do
5
+ it 'will always have a version' do
6
+ Allmenus::VERSION.wont_be_nil
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Allmenus do
4
+ subject { Allmenus }
5
+
6
+ describe '.configure' do
7
+ let(:api_key) { 'THE_api_key' }
8
+
9
+ before do
10
+ subject.configure do |config|
11
+ config.api_key = api_key
12
+ end
13
+ end
14
+
15
+ it 'has an appropriate api_key' do
16
+ subject.config.api_key.must_equal api_key
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:test)
4
+
5
+ require_relative '../lib/allmenus'
6
+ require 'minitest/autorun'
7
+ require 'minitest/pride'
8
+ require 'webmock/minitest'
9
+
10
+ Turn.config do |c|
11
+ c.format = :outline
12
+ c.natural = true
13
+ end
14
+
15
+ VCR.configure do |c|
16
+ c.cassette_library_dir = 'spec/fixtures/allmenus_cassettes'
17
+ c.hook_into :webmock
18
+ end
19
+
20
+ MiniTest::Spec.before :each do
21
+ Allmenus.configure do |c|
22
+ c.api_key = ENV['ALLMENUS_API_KEY']
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allmenus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - gregory
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ none: false
21
+ name: bundler
22
+ type: :runtime
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.3'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: rack
38
+ type: :runtime
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ none: false
53
+ name: faraday
54
+ type: :runtime
55
+ prerelease: false
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ none: false
69
+ name: json
70
+ type: :runtime
71
+ prerelease: false
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ none: false
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ none: false
85
+ name: happymapper
86
+ type: :runtime
87
+ prerelease: false
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ none: false
94
+ description: A ruby client for the allmenus API
95
+ email:
96
+ - greg2502@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - Guardfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - allmenus.gemspec
108
+ - lib/allmenus.rb
109
+ - lib/allmenus/configuration.rb
110
+ - lib/allmenus/connection.rb
111
+ - lib/allmenus/location.rb
112
+ - lib/allmenus/menu.rb
113
+ - lib/allmenus/menus/category.rb
114
+ - lib/allmenus/menus/group.rb
115
+ - lib/allmenus/menus/item.rb
116
+ - lib/allmenus/restaurant.rb
117
+ - lib/allmenus/version.rb
118
+ - spec/fixtures/allmenus_cassettes/restaurant.yml
119
+ - spec/lib/allmenus/configuration_spec.rb
120
+ - spec/lib/allmenus/connection_spec.rb
121
+ - spec/lib/allmenus/menu_spec.rb
122
+ - spec/lib/allmenus/restaurant_spec.rb
123
+ - spec/lib/allmenus/version_spec.rb
124
+ - spec/lib/allmenus_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: https://github.com/gregory/allmenus
127
+ licenses:
128
+ - MIT
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ none: false
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ none: false
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.23
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: A ruby client for the allmenus API
151
+ test_files:
152
+ - spec/fixtures/allmenus_cassettes/restaurant.yml
153
+ - spec/lib/allmenus/configuration_spec.rb
154
+ - spec/lib/allmenus/connection_spec.rb
155
+ - spec/lib/allmenus/menu_spec.rb
156
+ - spec/lib/allmenus/restaurant_spec.rb
157
+ - spec/lib/allmenus/version_spec.rb
158
+ - spec/lib/allmenus_spec.rb
159
+ - spec/spec_helper.rb
160
+ has_rdoc: