beer_mapping 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Phil McClure
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ = Beer Mapping
2
+
3
+ A ruby wrapper for the beermapping.com site. So the ruby community can ejoy beer whenever, whereever.
4
+
5
+ * {API Guidelines}[http://beermapping.com/api/]
6
+
7
+ == Installation
8
+
9
+ gem install beer_mapping
10
+
11
+ == Example
12
+
13
+ require 'rubygems'
14
+ require 'beer_mapping'
15
+
16
+ beer = BeerMapping::API.new("YOUR_API_KEY")
17
+ beer.find_by_location("chicago") # OR beer.find_by_name("Pub Name")
18
+
19
+ beer.locations.each do |location|
20
+ # Standard data
21
+ puts location.name # Pub name
22
+ puts location.city
23
+ puts location.state
24
+
25
+ # Geo Data
26
+ puts location.geo.lng # Geo lontitude
27
+ puts location.geo.lat # Geo Latitude
28
+
29
+ # Rating Data
30
+ puts location.ratings.service
31
+ puts location.ratings.atmosphere
32
+ puts location.ratings.selection
33
+ puts location.ratings.overall
34
+
35
+ # Related Images
36
+ location.images.each do |image|
37
+ image.url
38
+ image.thumburl
39
+ image.caption
40
+ image.height
41
+ image.width
42
+ end
43
+ end
44
+
45
+ == Note on Patches/Pull Requests
46
+
47
+ * Fork the project.
48
+ * Make your feature addition or bug fix.
49
+ * Add tests for it. This is important so I don't break it in a
50
+ future version unintentionally.
51
+ * Commit, do not mess with rakefile, version, or history.
52
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
53
+ * Send me a pull request. Bonus points for topic branches.
54
+
55
+ == Copyright
56
+
57
+ Copyright (c) 2010 Phil McClure. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "beer_mapping"
8
+ gem.summary = %Q{Ruby wrapper for beermapping.com}
9
+ gem.description = %Q{Allows you to find where pubs are, how they are rating etc.}
10
+ gem.email = "phil.mcclure@gmail.com"
11
+ gem.homepage = "http://github.com/overture8/beer_mapping"
12
+ gem.authors = ["Phil McClure"]
13
+ gem.files = Dir["lib/**/*"] + ["LICENSE", "README.rdoc", "Rakefile", "CHANGELOG.rdoc"]
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'cgi'
2
+ require 'open-uri'
3
+ require 'hpricot'
4
+ require File.expand_path(File.dirname(__FILE__) + '/beer_mapping/API')
5
+ require File.expand_path(File.dirname(__FILE__) + '/beer_mapping/geo')
6
+ require File.expand_path(File.dirname(__FILE__) + '/beer_mapping/image')
7
+ require File.expand_path(File.dirname(__FILE__) + '/beer_mapping/location')
8
+ require File.expand_path(File.dirname(__FILE__) + '/beer_mapping/rating')
@@ -0,0 +1,37 @@
1
+ module BeerMapping
2
+ class API
3
+ attr_reader :locations
4
+
5
+ def initialize(api_key)
6
+ $api_key = api_key
7
+ @locations = []
8
+ end
9
+
10
+ def find_by_name(search_name)
11
+ locations = open("http://beermapping.com/webservice/locquery/#{$api_key}/#{CGI.escape(search_name)}") {|f| Hpricot.XML(f) }
12
+ get_locations(locations)
13
+ end
14
+
15
+ def find_by_location(search_location)
16
+ locations = open("http://beermapping.com/webservice/loccity/#{$api_key}/#{CGI.escape(search_location)}") {|f| Hpricot.XML(f) }
17
+ get_locations(locations)
18
+ end
19
+
20
+ def get_locations(locations)
21
+ @locations.clear
22
+ locations.search("//location").each do |location|
23
+ lid = location.at("//id").innerText
24
+ name = location.at("//name").innerText
25
+ street = location.at("//street").innerText
26
+ city = location.at("//city").innerText
27
+ state = location.at("//state").innerText
28
+ zip = location.at("//zip").innerText
29
+ country = location.at("//country").innerText
30
+ phone = location.at("//phone").innerText
31
+ image_count = location.at("//imagecount").innerText
32
+ @locations << Location.new(lid, name, street, city, state, zip, country, phone, image_count)
33
+ end
34
+ end
35
+ private :get_locations
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module BeerMapping
2
+ class Geo
3
+ attr_reader :lat, :lng, :map, :altmap
4
+
5
+ def initialize(lat, lng, map, altmap)
6
+ @lat, @lng, @map, @altmap = lat, lng, map, altmap
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module BeerMapping
2
+ class Image
3
+ attr_reader :url, :thumburl, :width, :height, :caption, :credit, :created_date
4
+
5
+ def initialize(url, thumburl, width, height, caption, credit, created_date)
6
+ @url, @thumburl, @width, @height, @caption, @credit, @created_date = url, thumburl, width, height, caption, credit, created_date
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ module BeerMapping
2
+ class Location
3
+ attr_reader :id, :name, :street, :city, :state, :zip, :country, :phone, :image_count
4
+
5
+ def initialize(id, name, street, city, state, zip, country, phone, image_count)
6
+ @id, @name, @street, @city, @state, @zip, @country, @phone, @image_count = id, name, street, city, state, zip, country, phone, image_count
7
+ @images ||= []
8
+ end
9
+
10
+ def geo
11
+ # Lazy load geo data
12
+ unless instance_variable_defined? :@geo
13
+ geo = open("http://beermapping.com/webservice/locmap/#{$api_key}/#{@id}") {|f| Hpricot.XML(f) }
14
+ lat = geo.at("//location/lat").innerText
15
+ lng = geo.at("//location/lng").innerText
16
+ map = geo.at("//location/map").innerText
17
+ altmap = geo.at("//location/altmap").innerText
18
+ @geo = Geo.new(lat, lng, map, altmap)
19
+ else
20
+ @geo
21
+ end
22
+ end
23
+
24
+ def images
25
+ # Lazy load images
26
+ if @images.size == 0
27
+ images = open("http://beermapping.com/webservice/locimage/#{$api_key}/#{@id}") {|f| Hpricot.XML(f) }
28
+ images.search("//location").each do |image|
29
+ url = image.at("//imageurl").innerText
30
+ thumburl = image.at("//thumburl").innerText
31
+ width = image.at("//width").innerText
32
+ height = image.at("//height").innerText
33
+ caption = image.at("//caption").innerText
34
+ credit = image.at("//credit").innerText
35
+ created_date = image.at("//imagedate").innerText
36
+ @images << Image.new(url, thumburl, width, height, caption, credit, created_date)
37
+ end
38
+ else
39
+ @images
40
+ end
41
+ end
42
+
43
+ def ratings
44
+ # Lazy load ratings
45
+ unless instance_variable_defined? :@ratings
46
+ ratings = open("http://beermapping.com/webservice/locscore/#{$api_key}/#{@id}") {|f| Hpricot.XML(f) }
47
+ overall = ratings.at("//location/overall").innerText
48
+ selection = ratings.at("//location/selection").innerText
49
+ service = ratings.at("//location/service").innerText
50
+ atmosphere = ratings.at("//location/atmosphere").innerText
51
+ food = ratings.at("//location/food").innerText
52
+ reviewcount = ratings.at("//location/reviewcount").innerText
53
+ fbscore = ratings.at("//location/fbscore").innerText
54
+ fbcount = ratings.at("//location/fbcount").innerText
55
+ @ratings = Rating.new(overall, selection, service, atmosphere, food, reviewcount, fbscore, fbcount)
56
+ else
57
+ @ratings
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ module BeerMapping
2
+ class Rating
3
+ attr_reader :overall, :selection, :service, :food, :reviewcount, :fbscore, :fbcount
4
+
5
+ def initialize(overall, selection, service, atmosphere, food, reviewcount, fbscore, fbcount)
6
+ @overall, @selection, @service, @atmosphere, @food, @reviewcount, @fbscore, @fbcount = overall, selection, service, atmosphere, food, reviewcount, fbscore, fbcount
7
+ end
8
+ end
9
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'beer_mapping'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBeerMapping < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beer_mapping
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Phil McClure
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-19 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Allows you to find where pubs are, how they are rating etc.
23
+ email: phil.mcclure@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.rdoc
31
+ files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ - Rakefile
35
+ - lib/beer_mapping.rb
36
+ - lib/beer_mapping/API.rb
37
+ - lib/beer_mapping/geo.rb
38
+ - lib/beer_mapping/image.rb
39
+ - lib/beer_mapping/location.rb
40
+ - lib/beer_mapping/rating.rb
41
+ - test/test_beer_mapping.rb
42
+ - test/helper.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/overture8/beer_mapping
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Ruby wrapper for beermapping.com
77
+ test_files:
78
+ - test/test_beer_mapping.rb
79
+ - test/helper.rb