punky_brewster 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b42bb5db4825c866d6763a62b4972545d35bd8d5
4
- data.tar.gz: 4f0362689830ecb0c788f38215ee8e10fa1de6b8
3
+ metadata.gz: 6e187dcc2018f36ac897f7811ec2a7b7c0f050f6
4
+ data.tar.gz: c05be65d61dd21aa6429ad4dcb318c4b843fe41a
5
5
  SHA512:
6
- metadata.gz: 9cb0a32a2e36c61342dc4aef0b72381df878abcad434ecf6b90951b08c56d19dc2a4977ca0fa060e322a1f4ebcf26228286318030b7653a4de49972f05e1a665
7
- data.tar.gz: b5439ce0a32fe67f65198cc670f074659e90a0cf504dd1b5e10d63183d965c9f99ca3ae4a37b962c8c5ce46d16e1a3ed6815fec5039caaafdf4d7fa2690285c1
6
+ metadata.gz: 85e4ba0f90358f7911a59a2243d075476288d2967a2d7b5a0d9efe4a7a90c0ed39c98902ebb6bb3ff70227f25e505b7b2e4ad460ae4a71599dc4bfcb2e5da2fc
7
+ data.tar.gz: dbbbe17d5cf17ec03f79b81a8b1ffe5b87d275df07f02f36f65acce8f36987f139735bc7f4f43ea459182f619cfdc70c436dd8402f3962e07c6d6a661580c726
data/README.md CHANGED
@@ -6,7 +6,7 @@ What's on tap?
6
6
 
7
7
  gem install punky_brewster
8
8
 
9
- ## Usage
9
+ ## Command line tool
10
10
 
11
11
  $ punky_brewster
12
12
  8  WIRED  HOPWIRED $16.00/L 7.3%
@@ -29,6 +29,50 @@ What's on tap?
29
29
  GOLDEN ALE FRESH HOP $16.00/L 4.5%
30
30
  INVERCARGILL PITCHBLACK STOUT $13.50/L 4.5%
31
31
 
32
+ ## Ruby Library
33
+
34
+ ```ruby
35
+ require 'punky_brewster'
36
+ BeerListRequest.new.beers
37
+ ```
38
+
39
+ ## JSON API Server
40
+
41
+ A simple `config.ru`:
42
+
43
+ ```ruby
44
+ require 'punky_brewster/server'
45
+ run PunkyBrewster::Server
46
+ ```
47
+
48
+ ```http
49
+ $ curl -i localhost:9292
50
+
51
+ HTTP/1.1 200 OK
52
+ Content-Type: application/json
53
+ Transfer-Encoding: chunked
54
+ Connection: close
55
+ Server: thin
56
+
57
+ [{"name":"EPIC PALE ALE","price":14.0,"abv":5.4},{"name":"8 WIRED HOPWIRED","price":16.0,"abv":7.3},{"name":"MUSSEL INN CAPTAIN COOKER","price":12.5,"abv":5.7},{"name":"FUNK ESTATE NZPA FRESH HOP","price":16.0,"abv":5.5},{"name":"INVERCARGILL PITCHBLACK STOUT","price":13.5,"abv":4.5},{"name":"GOLDEN EAGLE BIG YANK","price":16.0,"abv":7.5},{"name":"RENAISSANCE PARADOX PILSENER","price":14.0,"abv":4.0}]
58
+ ```
59
+
60
+ Mount alongside other Rack apps (Rails, Sinatra, etc.):
61
+
62
+ ```ruby
63
+ require 'punky_brewster/server'
64
+ run Rack::URLMap.new("/punky_brewster/beers.json" => PunkyBrewster::Server)
65
+ ```
66
+
67
+ Need JSONP? Use the `rack-contrib` gem:
68
+
69
+ ```ruby
70
+ require 'rack/contrib/json'
71
+ require 'punky_brewster/server'
72
+ use Rack::JSONP
73
+ run PunkyBrewster::Server
74
+ ```
75
+
32
76
  ## Development
33
77
 
34
78
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -1,3 +1,5 @@
1
+ require "nokogiri"
2
+
1
3
  module PunkyBrewster
2
4
  class BeerListResponse
3
5
  def initialize(raw_response)
@@ -1,7 +1,5 @@
1
1
  require "thor"
2
2
  require "punky_brewster"
3
- require "nokogiri"
4
- require "open-uri"
5
3
 
6
4
  module PunkyBrewster
7
5
  class CLI < Thor
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+ require 'punky_brewster'
3
+
4
+ module PunkyBrewster
5
+ class Server
6
+ def self.call(env)
7
+ headers = { 'Content-Type' => 'application/json' }
8
+
9
+ begin
10
+ beers = BeerListRequest.new.beers
11
+ beers_properties = beers.map(&:to_h)
12
+ body = JSON.generate(beers_properties)
13
+ status = 200
14
+ rescue => error
15
+ body = JSON.generate(error: "#{error.class}: #{error}")
16
+ status = 500
17
+ end
18
+
19
+ [status, headers, [body]]
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module PunkyBrewster
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -20,10 +20,12 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "nokogiri"
22
22
  spec.add_runtime_dependency "thor"
23
+ spec.add_runtime_dependency "rack"
23
24
 
24
25
  spec.add_development_dependency "vcr"
25
26
  spec.add_development_dependency "webmock"
26
27
  spec.add_development_dependency "bundler", "~> 1.8"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
28
29
  spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "rack-test"
29
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punky_brewster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Nicholls
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
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'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: vcr
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
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'
111
139
  description:
112
140
  email:
113
141
  - pete@metanation.com
@@ -130,6 +158,7 @@ files:
130
158
  - lib/punky_brewster/beer_list_request.rb
131
159
  - lib/punky_brewster/beer_list_response.rb
132
160
  - lib/punky_brewster/cli.rb
161
+ - lib/punky_brewster/server.rb
133
162
  - lib/punky_brewster/version.rb
134
163
  - punky_brewster.gemspec
135
164
  homepage: https://github.com/Aupajo/punky_brewster