citygrid 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,11 +31,13 @@ Sign up for a CityGrid API key: [http://developer.citysearch.com/member/register
31
31
 
32
32
  #### Examples
33
33
 
34
- >> citygrid.search_locations(:what => "roots coffee", :where => "76180", :rpp => 1)
35
- => {"results"=>{"region"=>{"name"=>"76180", "latitude"=>"32.86399", "type"=>"postal_code", "longitude"=>"-97.215194", "defaultradius"=>"4.3600"}, "firsthit"=>"1", "uri"=>"http://api.citysearch.com/search/locations?what=roots+coffee&where=76180&rpp=1&publisher=acme", "location"=>{"name"=>"Roots Coffeehouse", "address"=>{"city"=>"N Richland Hills", "postalcode"=>"76180", "street"=>"9101 Boulevard 26", "state"=>"TX"}, "rating"=>nil, "latitude"=>"32.849869", "userreviewcount"=>"0", "profile"=>"http://national.citysearch.com/profile/613027480/n_richland_hills_tx/roots_coffeehouse.html", "featured"=>"false", "phonenumber"=>"8175037344", "offers"=>nil, "id"=>"613027480", "hasvideo"=>"false", "hasoffers"=>"false", "neighborhood"=>nil, "longitude"=>"-97.193291", "samplecategories"=>"Coffeehouses"}, "queryid"=>"", "totalhits"=>"1", "histogram"=>{"name"=>"Categories", "item"=>"http://api.citysearch.com/search/locations?what=roots+coffee&tag=1726&where=76180&rpp=1&publisher=acme"}, "lasthit"=>"1"}}
34
+ >> spot = citygrid.search_locations(:what => "roots coffee", :where => "76180", :rpp => 1)
35
+ >> spot.results.location.name
36
+ => "Roots Coffeehouse"
36
37
 
37
- >> citygrid.profile(:listing_id => '613027480', :client_ip => 'any_client_ip')
38
- => {"locations"=>{"location"=>{"display_ad"=>"true", "name"=>"Roots Coffeehouse", "address"=>{"city"=>"N Richland Hills", "latitude"=>"32.849869", "postal_code"=>"76180", "street"=>"9101 Boulevard 26", "delivery_point"=>nil, "cross_street"=>nil, "longitude"=>"-97.193291", "state"=>"TX"}, "urls"=>{"email_link"=>"http://national.citysearch.com/profile/email_business/613027480/n_richland_hills_tx/roots_coffeehouse.html", "reviews_url"=>"http://national.citysearch.com/review/613027480", "video_url"=>nil, "website_url"=>"http://national.citysearch.com/profile/external/613027480/n_richland_hills_tx/roots_coffeehouse.html", "map_url"=>"http://national.citysearch.com/profile/map/613027480/n_richland_hills_tx/roots_coffeehouse.html", "custom_link_1"=>nil, "profile_url"=>"http://national.citysearch.com/profile/613027480/n_richland_hills_tx/roots_coffeehouse.html", "custom_link_2"=>nil, "menu_url"=>nil, "reservation_url"=>nil, "send_to_friend_url"=>"http://national.citysearch.com/profile/sendto/613027480/n_richland_hills_tx/roots_coffeehouse.html"}, "markets"=>{"market"=>"Fort Worth, TX Metro"}, "offers"=>nil, "attributes"=>nil, "contact_info"=>{"display_phone"=>"8175037344", "display_url"=>"http://national.citysearch.com/profile/613027480/n_richland_hills_tx/roots_coffeehouse.html"}, "customer_content"=>{"customer_message_url"=>nil, "customer_message"=>nil, "bullets"=>nil}, "tips"=>nil, "id"=>"613027480", "reference_id"=>"1", "parking"=>nil, "images"=>nil, "infousa_id"=>"695618793", "teaser"=>nil, "neighborhoods"=>nil, "business_hours"=>nil, "reviews"=>{"total_user_reviews"=>nil, "total_user_reviews_shown"=>nil, "overall_review_rating"=>"NA"}, "categories"=>{"category"=>{"name"=>"Coffeehouses", "parent"=>"Restaurants", "parentid"=>"1722", "nameid"=>"1726"}}, "editorials"=>nil}}}
38
+ >> profile = citygrid.profile(:listing_id => '613027480', :client_ip => 'any_client_ip')
39
+ >> profile.locations.location.categories
40
+ => <#Hashie::Mash category=<#Hashie::Mash name="Coffeehouses" nameid="1726" parent="Restaurants" parentid="1722">>
39
41
 
40
42
  You can search for locations and events, get reviews, and get business profiles.
41
43
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/citygrid.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{citygrid}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Johnny Khai Nguyen"]
12
+ s.date = %q{2010-06-27}
13
+ s.description = %q{Ruby wrapper for the CityGrid API}
14
+ s.email = %q{johnnyn@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "citygrid.gemspec",
24
+ "init.rb",
25
+ "install.rb",
26
+ "lib/citygrid.rb",
27
+ "lib/citygrid/client.rb",
28
+ "pkg/citygrid-0.1.0.gem",
29
+ "tasks/citygrid_tasks.rake",
30
+ "test/citygrid_test.rb",
31
+ "test/test_helper.rb",
32
+ "uninstall.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/phuphighter/citygrid}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Ruby wrapper for the CityGrid API}
39
+ s.test_files = [
40
+ "test/citygrid_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.0"])
50
+ else
51
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
55
+ end
56
+ end
57
+
data/lib/citygrid.rb CHANGED
@@ -2,9 +2,12 @@
2
2
  require 'rubygems'
3
3
  gem 'httparty'
4
4
  require 'httparty'
5
+ require 'hashie'
5
6
 
6
7
  directory = File.expand_path(File.dirname(__FILE__))
7
8
 
9
+ Hash.send :include, Hashie::HashExtensions
10
+
8
11
  module Citygrid
9
12
 
10
13
  # create config/initializers/citygrid.rb
@@ -11,23 +11,23 @@ module Citygrid
11
11
  end
12
12
 
13
13
  def search_locations(options={})
14
- response = self.class.get("/search/locations", :query => options.merge(self.default_options))
14
+ mashup(self.class.get("/search/locations", :query => options.merge(self.default_options)))
15
15
  end
16
16
 
17
17
  def search_events(options={})
18
- response = self.class.get("/search/events", :query => options.merge(self.default_options))
18
+ mashup(self.class.get("/search/events", :query => options.merge(self.default_options)))
19
19
  end
20
20
 
21
21
  def profile(options={})
22
22
  if options[:client_ip].nil?
23
23
  puts "Dude, a client_ip is required."
24
24
  else
25
- response = self.class.get("/profile/", :query => options.merge(self.default_options))
25
+ mashup(self.class.get("/profile/", :query => options.merge(self.default_options)))
26
26
  end
27
27
  end
28
28
 
29
29
  def reviews(options={})
30
- response = self.class.get("/reviews/", :query => options.merge(self.default_options))
30
+ mashup(self.class.get("/reviews/", :query => options.merge(self.default_options)))
31
31
  end
32
32
 
33
33
  protected
@@ -36,5 +36,20 @@ module Citygrid
36
36
  {:api_key => @api_key, :publisher => "acme"}
37
37
  end
38
38
 
39
- end
39
+ def mashup(response)
40
+ case response.code
41
+ when 200
42
+ if response.is_a?(Hash)
43
+ Hashie::Mash.new(response)
44
+ else
45
+ if response.first.is_a?(Hash)
46
+ response.map{|item| Hashie::Mash.new(item)}
47
+ else
48
+ response
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
40
55
  end
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Johnny Khai Nguyen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-26 00:00:00 -05:00
17
+ date: 2010-06-27 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -44,10 +44,12 @@ files:
44
44
  - README.md
45
45
  - Rakefile
46
46
  - VERSION
47
+ - citygrid.gemspec
47
48
  - init.rb
48
49
  - install.rb
49
50
  - lib/citygrid.rb
50
51
  - lib/citygrid/client.rb
52
+ - pkg/citygrid-0.1.0.gem
51
53
  - tasks/citygrid_tasks.rake
52
54
  - test/citygrid_test.rb
53
55
  - test/test_helper.rb