daily_menu_app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c655bb57637cb41b79d7b6ba340d520aff35d6f8
4
+ data.tar.gz: b8666eebc32906fb7fd57f144be483a89b0334ad
5
+ SHA512:
6
+ metadata.gz: d7c21478332dd9a7a7ee521628cae151249b03323e8eb5a4eda9ebffbb6a6ae23aee4fa93965c2e65f14fd057c7f92deab0339e03f98f59569f5c73d942bcd31
7
+ data.tar.gz: 1a08320e313d4744a2903c9d1210a837fb4342607eee48117429df3816730d7526b1560bed4d42f913d260dedee8d386c1102553d789bfe3a9e6bc81accc2079
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-version
7
+ .ruby-gemset
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ Gemfile.lock
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Documentation:
2
+ Enabled: false
3
+ LineLength:
4
+ Enabled: true
5
+ Max: 120
6
+ MethodLength:
7
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # DailyMenu Application
2
+
3
+ [![Build Status](https://travis-ci.org/raszi/daily_menu_app.png?branch=master)](https://travis-ci.org/raszi/daily_menu_app)
4
+
5
+ ## Contributing
6
+
7
+ 1. Fork it
8
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
9
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
10
+ 4. Push to the branch (`git push origin my-new-feature`)
11
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ require 'rubocop/rake_task'
10
+ Rubocop::RakeTask.new
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'daily_menu_app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'daily_menu_app'
8
+ spec.version = DailyMenuApp::VERSION
9
+ spec.authors = ['Karaszi István']
10
+ spec.email = ['github@spam.raszi.hu']
11
+ spec.description = %q{This is the application for fetching daily menus}
12
+ spec.summary = %q{}
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.required_ruby_version = '>= 2.0.0'
20
+
21
+ spec.add_dependency 'daily_menu', '~> 0.0.3'
22
+ spec.add_dependency 'sinatra'
23
+ spec.add_dependency 'memcachier'
24
+ spec.add_dependency 'dalli'
25
+ spec.add_dependency 'rack-cache'
26
+ spec.add_dependency 'thin'
27
+
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'rack-test'
33
+ spec.add_development_dependency 'simplecov'
34
+ end
@@ -0,0 +1,38 @@
1
+ require 'sinatra'
2
+ require 'rack-cache'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ module DailyMenuApp
7
+ class Application < Sinatra::Application
8
+ if ENV['MEMCACHIER_SERVERS']
9
+ servers = ENV['MEMCACHIER_SERVERS'].split(',')
10
+
11
+ dalli_client = Dalli::Client.new(servers, {
12
+ username: ENV['MEMCACHIER_USERNAME'],
13
+ password: ENV['MEMCACHIER_PASSWORD']
14
+ })
15
+
16
+ use Rack::Cache, {
17
+ metastore: dalli_client,
18
+ entitystore: dalli_client
19
+ }
20
+ end
21
+
22
+ logger = Logger.new(STDOUT)
23
+ fetcher = Fetcher.new(logger)
24
+
25
+ get '/menus/*' do
26
+ cache_control :public, max_age: 1800
27
+
28
+ begin
29
+ location = params[:splat].first
30
+
31
+ content_type :json
32
+ fetcher.fetch(location).to_json
33
+ rescue NotFound
34
+ status 404
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module DailyMenuApp
2
+ class InvalidRequest < StandardError
3
+ end
4
+
5
+ class NotFound < StandardError
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ require 'daily_menu'
2
+ require 'json'
3
+
4
+ module DailyMenuApp
5
+ class Fetcher
6
+ def initialize(logger)
7
+ @logger = logger
8
+ end
9
+
10
+ def fetch(location)
11
+ menus = fetch_menus(location).map do |restaurant, entry|
12
+ [restaurant.name, convert_entry(entry)]
13
+ end
14
+ Hash[menus]
15
+ end
16
+
17
+ def fetch_menus(location)
18
+ DailyMenu.menus_for(location)
19
+ rescue RuntimeError => e
20
+ expectation = expectation_class_from(e).new(e.message)
21
+ expectation.set_backtrace(e.backtrace)
22
+ raise expectation
23
+ end
24
+
25
+ def convert_entry(entry)
26
+ {
27
+ menu: entry.content,
28
+ date: entry.time.to_time.utc
29
+ }
30
+ end
31
+ private :convert_entry
32
+
33
+ def expectation_class_from(e)
34
+ case e.message
35
+ when /No configuration found/
36
+ NotFound
37
+ else
38
+ RuntimeError
39
+ end
40
+ end
41
+ private :expectation_class_from
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module DailyMenuApp
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'daily_menu_app/version'
2
+
3
+ module DailyMenuApp
4
+ end
5
+
6
+ require 'daily_menu_app/exceptions'
7
+ require 'daily_menu_app/fetcher'
8
+ require 'daily_menu_app/application'
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'rack/test'
3
+ require 'time'
4
+
5
+ describe DailyMenuApp::Application do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ described_class
10
+ end
11
+
12
+ describe '/menus/' do
13
+ let(:location) { '/menus/Foo/Bar' }
14
+
15
+ context 'when no location found' do
16
+ it 'should respond with an error' do
17
+ get(location)
18
+
19
+ expect(last_response).to_not be_ok
20
+ expect(last_response.status).to eq(404)
21
+ end
22
+ end
23
+
24
+ context 'when there is a configuration for the location' do
25
+ context 'when no menus could be fetched' do
26
+ before do
27
+ DailyMenu.stub(:menus_for) { [] }
28
+ end
29
+
30
+ it 'should respond an empty JSON object' do
31
+ get(location)
32
+
33
+ expect(last_response).to be_ok
34
+ expect(last_response.content_type).to match(/application\/json/)
35
+ expect(last_response.body).to eq('{}')
36
+ end
37
+ end
38
+
39
+ context 'when menus could be fetched' do
40
+ let(:restaurant_name) { 'Example Restaurant' }
41
+ let(:restaurant) { double('Restaurant', name: restaurant_name) }
42
+ let(:time) { DateTime.now }
43
+ let(:entry) { double('Entry', content: 'Menu', time: time) }
44
+
45
+ before do
46
+ DailyMenu.stub(:menus_for) { [[restaurant, entry]] }
47
+ end
48
+
49
+ it 'should respond with a JSON object' do
50
+ get(location)
51
+
52
+ expect(last_response).to be_ok
53
+ expect(last_response.content_type).to match(/application\/json/)
54
+ response = JSON.parse(last_response.body)
55
+
56
+ expect(response).to have_key(restaurant_name)
57
+ expect(response[restaurant_name]).to have_key('menu')
58
+ expect(response[restaurant_name]).to have_key('date')
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe DailyMenuApp do
4
+ describe 'VERSION' do
5
+ it 'should not be nil' do
6
+ expect(described_class::VERSION).to_not be_nil
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'daily_menu_app'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ config.order = 'random'
12
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daily_menu_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Karaszi István
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: daily_menu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: memcachier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dalli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-cache
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thin
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack-test
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: This is the application for fetching daily menus
182
+ email:
183
+ - github@spam.raszi.hu
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - .gitignore
189
+ - .rspec
190
+ - .rubocop.yml
191
+ - .travis.yml
192
+ - Gemfile
193
+ - README.md
194
+ - Rakefile
195
+ - daily_menu_app.gemspec
196
+ - lib/daily_menu_app.rb
197
+ - lib/daily_menu_app/application.rb
198
+ - lib/daily_menu_app/exceptions.rb
199
+ - lib/daily_menu_app/fetcher.rb
200
+ - lib/daily_menu_app/version.rb
201
+ - spec/daily_menu_app/application_spec.rb
202
+ - spec/daily_menu_app_spec.rb
203
+ - spec/spec_helper.rb
204
+ homepage:
205
+ licenses: []
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: 2.0.0
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - '>='
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubyforge_project:
223
+ rubygems_version: 2.0.6
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: ''
227
+ test_files:
228
+ - spec/daily_menu_app/application_spec.rb
229
+ - spec/daily_menu_app_spec.rb
230
+ - spec/spec_helper.rb