beerdb 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,20 @@
3
3
 
4
4
  <h2>Examples</h2>
5
5
 
6
+ <h3>Get random beer <code>/beer/rand</code></h3>
7
+
8
+ <table>
9
+ <tr>
10
+ <td>
11
+ <code>
12
+ <a href='<%= url("/beer/rand") %>'>
13
+ /beer/<span class='params'>rand</span>
14
+ </a>
15
+ </code>
16
+ </td>
17
+ </tr>
18
+ </table>
19
+
6
20
  <h3>Get beer by key <code>/beer/<span class='params'>:key</span></code></h3>
7
21
 
8
22
  <table>
@@ -69,6 +83,20 @@
69
83
  </table>
70
84
 
71
85
 
86
+ <h3>Get random brewery <code>/brewery/rand</code></h3>
87
+
88
+ <table>
89
+ <tr>
90
+ <td>
91
+ <code>
92
+ <a href='<%= url("/brewery/rand") %>'>
93
+ /brewery/<span class='params'>rand</span>
94
+ </a>
95
+ </code>
96
+ </td>
97
+ </tr>
98
+ </table>
99
+
72
100
  <h3>Get brewery by key <code>/brewery/<span class='params'>:key</span></code></h3>
73
101
 
74
102
  <table>
data/lib/beerdb/server.rb CHANGED
@@ -63,8 +63,20 @@ class Server < Sinatra::Base
63
63
  erb :debug
64
64
  end
65
65
 
66
+ ## todo: add support for beer of the day, of the week, of the month, of the year?
67
+ ## /beer/day|d | /beer/month|m | beer/year|y ??
68
+ ##
69
+ ## add table daily_beer, weekly_beer, etc. ??
70
+
66
71
  get '/beer/:key' do |key|
67
- beer = Beer.find_by_key!( key )
72
+
73
+ if ['r', 'rnd', 'rand', 'random'].include?( key )
74
+ # special key for random beer
75
+ beer_id = rand( Beer.count )+1 # nb: assumes record ids sequence from 1-n
76
+ beer = Beer.find( beer_id )
77
+ else
78
+ beer = Beer.find_by_key!( key )
79
+ end
68
80
 
69
81
  brewery = {}
70
82
  if beer.brewery.present?
@@ -82,18 +94,26 @@ class Server < Sinatra::Base
82
94
  title: beer.country.title
83
95
  }
84
96
 
85
- data = { beer: { key: beer.key, title: beer.title, synonyms: beer.synonyms,
97
+ data = { key: beer.key, title: beer.title, synonyms: beer.synonyms,
86
98
  abv: beer.abv, srm: beer.srm, og: beer.og,
87
99
  tags: tags,
88
100
  brewery: brewery,
89
- country: country }}
101
+ country: country }
90
102
 
91
103
  json_or_jsonp( data )
92
104
  end
93
105
 
94
106
 
95
107
  get '/brewery/:key' do |key|
96
- brewery = Brewery.find_by_key!( key )
108
+
109
+ if ['r', 'rnd', 'rand', 'random'].include?( key )
110
+ # special key for random brewery
111
+ brewery_id = rand( Brewery.count )+1 # nb: assumes record ids sequence from 1-n
112
+ brewery = Brewery.find( brewery_id )
113
+ else
114
+ brewery = Brewery.find_by_key!( key )
115
+ end
116
+
97
117
 
98
118
  beers = []
99
119
  brewery.beers.each do |b|
@@ -110,16 +130,16 @@ class Server < Sinatra::Base
110
130
  title: brewery.country.title
111
131
  }
112
132
 
113
- data = { brewery: { key: brewery.key,
114
- title: brewery.title,
115
- synonyms: brewery.synonyms,
116
- since: brewery.since,
117
- address: brewery.address,
118
- web: brewery.web,
119
- prod: brewery.prod, # (estimated) annual production in hl e.g. 2_000 hl
120
- tags: tags,
121
- beers: beers,
122
- country: country }}
133
+ data = { key: brewery.key,
134
+ title: brewery.title,
135
+ synonyms: brewery.synonyms,
136
+ since: brewery.since,
137
+ address: brewery.address,
138
+ web: brewery.web,
139
+ prod: brewery.prod, # (estimated) annual production in hl e.g. 2_000 hl
140
+ tags: tags,
141
+ beers: beers,
142
+ country: country }
123
143
 
124
144
  json_or_jsonp( data )
125
145
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module BeerDb
3
- VERSION = '0.6.4'
3
+ VERSION = '0.6.5'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beerdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &83421770 !ruby/object:Gem::Requirement
16
+ requirement: &75736340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83421770
24
+ version_requirements: *75736340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: worlddb
27
- requirement: &83421550 !ruby/object:Gem::Requirement
27
+ requirement: &75736120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.6'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *83421550
35
+ version_requirements: *75736120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: commander
38
- requirement: &83421330 !ruby/object:Gem::Requirement
38
+ requirement: &75735900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 4.1.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *83421330
46
+ version_requirements: *75735900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &83421110 !ruby/object:Gem::Requirement
49
+ requirement: &75735680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.10'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *83421110
57
+ version_requirements: *75735680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &83420890 !ruby/object:Gem::Requirement
60
+ requirement: &75735460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *83420890
68
+ version_requirements: *75735460
69
69
  description: beerdb - beer.db command line tool
70
70
  email: beerdb@googlegroups.com
71
71
  executables: