citygrid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +46 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/citygrid/client.rb +40 -0
- data/lib/citygrid.rb +36 -0
- data/tasks/citygrid_tasks.rake +4 -0
- data/test/citygrid_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +87 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
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.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Citygrid
|
2
|
+
|
3
|
+
This is a Ruby wrapper for the [CityGrid API](http://developer.citysearch.com/home).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
As a gem:
|
8
|
+
|
9
|
+
sudo gem install citygrid
|
10
|
+
|
11
|
+
As a plugin (in your Rails directory:
|
12
|
+
|
13
|
+
script/plugin install git://github.com/phuphighter/citygrid.git
|
14
|
+
|
15
|
+
## Get a Citygrid API key
|
16
|
+
|
17
|
+
Sign up for a CityGrid API key: [http://developer.citysearch.com/member/register](http://developer.citysearch.com/member/register)
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Instantiate a client
|
22
|
+
|
23
|
+
>> citygrid = Citygrid::Client.new(:api_key => 'your_api_key')
|
24
|
+
|
25
|
+
### or configure once
|
26
|
+
|
27
|
+
>> Citygrid.configure do |config|
|
28
|
+
>> config.api_key = 'your_api_key'
|
29
|
+
>> end
|
30
|
+
>> citygrid = Citygrid::Client.new
|
31
|
+
|
32
|
+
#### Examples
|
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"}}
|
36
|
+
|
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}}}
|
39
|
+
|
40
|
+
You can search for locations and events, get reviews, and get business profiles.
|
41
|
+
|
42
|
+
## Copyright
|
43
|
+
|
44
|
+
Contact me if you have any suggestions and feel free to fork it!
|
45
|
+
|
46
|
+
Copyright (c) 2009 Johnny Khai Nguyen, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "citygrid"
|
9
|
+
gem.summary = %Q{Ruby wrapper for the CityGrid API}
|
10
|
+
gem.description = %Q{Ruby wrapper for the CityGrid API}
|
11
|
+
gem.email = "johnnyn@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/phuphighter/citygrid"
|
13
|
+
gem.authors = ["Johnny Khai Nguyen"]
|
14
|
+
|
15
|
+
gem.add_dependency('httparty', '>= 0.5.0')
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Default: run unit tests.'
|
23
|
+
task :default => :test
|
24
|
+
|
25
|
+
desc 'Test the citygrid plugin.'
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Generate documentation for the citygrid plugin.'
|
34
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
35
|
+
rdoc.rdoc_dir = 'rdoc'
|
36
|
+
rdoc.title = 'Citygrid'
|
37
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
38
|
+
rdoc.rdoc_files.include('README')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Citygrid
|
2
|
+
|
3
|
+
class Client
|
4
|
+
include HTTParty
|
5
|
+
base_uri "http://api2.citysearch.com"
|
6
|
+
|
7
|
+
attr_reader :api_key
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@api_key = options[:api_key] || Citygrid.api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def search_locations(options={})
|
14
|
+
response = self.class.get("/search/locations", :query => options.merge(self.default_options))
|
15
|
+
end
|
16
|
+
|
17
|
+
def search_events(options={})
|
18
|
+
response = self.class.get("/search/events", :query => options.merge(self.default_options))
|
19
|
+
end
|
20
|
+
|
21
|
+
def profile(options={})
|
22
|
+
if options[:client_ip].nil?
|
23
|
+
puts "Dude, a client_ip is required."
|
24
|
+
else
|
25
|
+
response = self.class.get("/profile/", :query => options.merge(self.default_options))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def reviews(options={})
|
30
|
+
response = self.class.get("/reviews/", :query => options.merge(self.default_options))
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def default_options
|
36
|
+
{:api_key => @api_key, :publisher => "acme"}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/citygrid.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Citygrid
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'httparty'
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
module Citygrid
|
9
|
+
|
10
|
+
# create config/initializers/citygrid.rb
|
11
|
+
#
|
12
|
+
# Citygrid.configure do |config|
|
13
|
+
# config.api_key = 'api_key'
|
14
|
+
# end
|
15
|
+
# client = Citygrid::Client.new
|
16
|
+
#
|
17
|
+
# or
|
18
|
+
#
|
19
|
+
# Citygrid.api_key = 'api_key'
|
20
|
+
#
|
21
|
+
# or
|
22
|
+
#
|
23
|
+
# Citygrid::Client.new(:api_key => 'api_key')
|
24
|
+
|
25
|
+
def self.configure
|
26
|
+
yield self
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
class << self
|
31
|
+
attr_accessor :api_key
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
require File.join(directory, 'citygrid', 'client')
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: citygrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Johnny Khai Nguyen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-26 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 5
|
30
|
+
- 0
|
31
|
+
version: 0.5.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Ruby wrapper for the CityGrid API
|
35
|
+
email: johnnyn@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README.md
|
42
|
+
files:
|
43
|
+
- MIT-LICENSE
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- VERSION
|
47
|
+
- init.rb
|
48
|
+
- install.rb
|
49
|
+
- lib/citygrid.rb
|
50
|
+
- lib/citygrid/client.rb
|
51
|
+
- tasks/citygrid_tasks.rake
|
52
|
+
- test/citygrid_test.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
- uninstall.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/phuphighter/citygrid
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Ruby wrapper for the CityGrid API
|
85
|
+
test_files:
|
86
|
+
- test/citygrid_test.rb
|
87
|
+
- test/test_helper.rb
|