-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Unpakt
committed
Feb 7, 2013
0 parents
commit 30b86ba
Showing
28 changed files
with
932 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp | ||
.pairs | ||
user_reviews-*.gem | ||
scripts | ||
scripts/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in user_reviews.gemspec | ||
gemspec | ||
|
||
group :test do | ||
gem 'rspec' | ||
gem 'pry' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
user_reviews (0.0.7) | ||
activesupport (~> 3.2.11) | ||
httparty | ||
json | ||
oauth | ||
rake | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (3.2.11) | ||
i18n (~> 0.6) | ||
multi_json (~> 1.0) | ||
coderay (1.0.8) | ||
diff-lcs (1.1.3) | ||
httparty (0.10.2) | ||
multi_json (~> 1.0) | ||
multi_xml (>= 0.5.2) | ||
i18n (0.6.1) | ||
json (1.7.6) | ||
method_source (0.8.1) | ||
multi_json (1.5.0) | ||
multi_xml (0.5.2) | ||
oauth (0.4.7) | ||
pry (0.9.11.4) | ||
coderay (~> 1.0.5) | ||
method_source (~> 0.8) | ||
slop (~> 3.4) | ||
rake (10.0.3) | ||
rspec (2.12.0) | ||
rspec-core (~> 2.12.0) | ||
rspec-expectations (~> 2.12.0) | ||
rspec-mocks (~> 2.12.0) | ||
rspec-core (2.12.2) | ||
rspec-expectations (2.12.1) | ||
diff-lcs (~> 1.1.3) | ||
rspec-mocks (2.12.2) | ||
slop (3.4.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
pry | ||
rspec | ||
user_reviews! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Unpakt LLC | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# UserReviews | ||
|
||
[![Build Status](https://secure.travis-ci.org/Unpakt/user_reviews.png?branch=master)](http://travis-ci.org/unpakt/user_reviews) | ||
|
||
Is a simple api wrapper for: | ||
|
||
* Yelp | ||
* Citysearch | ||
* Google Ratings | ||
|
||
## Getting started | ||
|
||
### Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'user_reviews' | ||
``` | ||
|
||
### And then execute: | ||
|
||
```console | ||
$ bundle | ||
``` | ||
|
||
### Or install it yourself as: | ||
|
||
```console | ||
$ gem install user_reviews | ||
``` | ||
|
||
## Usage | ||
|
||
### Create an api_provider | ||
|
||
### For Citysearch | ||
|
||
```ruby | ||
auth_info = {publisher_key: 'your_city_search_api_key'} | ||
city_search = UserReviews.provider_factory(:citysearch, auth_info) | ||
``` | ||
|
||
### For Google Reviews | ||
|
||
```ruby | ||
auth_info = {key: 'your_google_api_key'} | ||
google = UserReviews.provider_factory(:google, auth_info) | ||
``` | ||
|
||
### For Yelp | ||
|
||
```ruby | ||
auth_info = {consumer_key: 'yelp_consumer_key', consumer_secret:'yelp_consumer_secret' ,token:'yelp_token' , token_secret:'yelp_token_secret'} | ||
yelp = UserReviews.provider_factory(:yelp, auth_info) | ||
``` | ||
|
||
### Get reviews for a business | ||
|
||
```ruby | ||
city_search.find_reviews_for_business city_search_business_id | ||
``` | ||
|
||
### Get information about a business | ||
|
||
```ruby | ||
city_search.find_business_by_id(business_id) | ||
``` | ||
|
||
Each Review object has 4 attributes: | ||
* author_name | ||
* rating | ||
* reviewed_at | ||
* comment | ||
|
||
Each Business object has 4 attributes: | ||
* name | ||
* address | ||
* reference | ||
* average_rating | ||
* url | ||
|
||
|
||
More information about each API: | ||
|
||
* Yelp: http://www.yelp.com/developers/documentation/v2/overview | ||
* CitySearch: http://www.citygridmedia.com/developer/ | ||
* GoogleReviews: https://developers.google.com/places/documentation/ | ||
|
||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Add your own provider folder which inherits from the Providers::Base class and tests | ||
4. Commit your changes (`git commit -am 'Add some feature'`) | ||
5. Push to the branch (`git push origin my-new-feature`) | ||
6. Create new Pull Request | ||
|
||
## License | ||
|
||
MIT License. Copyright 2013. http://www.unpakt.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "bundler/gem_tasks" | ||
require 'bundler' | ||
require 'rspec/core/rake_task' | ||
|
||
Bundler::GemHelper.install_tasks | ||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'httparty' | ||
require 'oauth' | ||
require 'json' | ||
require 'open-uri' | ||
require 'date' | ||
|
||
module Providers | ||
class Base | ||
|
||
def find_business_by_name(name, business_type, city_state = "") | ||
end | ||
|
||
def find_reviews_for_business(ref) | ||
end | ||
|
||
def find_business_by_id(id) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module Providers | ||
module Citysearch | ||
class Api < Providers::Base | ||
|
||
LOCALHOST_IP = "127.0.0.1" | ||
|
||
def initialize(options) | ||
@key = options[:publisher_key] | ||
@ip = options[:client_ip] || LOCALHOST_IP | ||
end | ||
|
||
def find_business_by_name(name, business_type, city_state) | ||
request_url = business_search_url(name, business_type, city_state) | ||
json_results = HTTParty.get(request_url) | ||
parse_business_results(json_results) | ||
end | ||
|
||
def find_business_by_id(citysearch_id) | ||
request_url = business_url(citysearch_id) | ||
json_results = HTTParty.get(request_url) | ||
json = json_results["locations"] || [] | ||
|
||
return json if json.empty? | ||
Providers::Citysearch::Business.build_business(json.first) | ||
end | ||
|
||
def find_reviews_for_business(citysearch_id) | ||
request_url = reviews_url(citysearch_id) | ||
json_results = HTTParty.get(request_url) | ||
parse_reviews_results(json_results) | ||
end | ||
|
||
private | ||
|
||
def business_url(citysearch_id) | ||
"http://api.citygridmedia.com/content/places/v2/detail?publisher=#{@key}&id=#{citysearch_id}&id_type=cs&client_ip=127.0.0.1&format=json" | ||
end | ||
|
||
def business_search_url(name, business_type = "", city_state) | ||
"http://api.citygridmedia.com/content/places/v2/search/where?where=#{URI::encode(city_state)}&what=#{URI::encode(name)}&publisher=#{@key}&format=json" | ||
end | ||
|
||
def reviews_url(citysearch_id) | ||
"http://api.citygridmedia.com/content/reviews/v2/search/where?listing_id=#{citysearch_id}&publisher=#{@key}&format=json" | ||
end | ||
|
||
def parse_business_results(json) | ||
result = [] | ||
return result if json.nil? || json["results"].nil? | ||
|
||
json = json["results"] || [] | ||
json["locations"].each do |e| | ||
result.push(Providers::Citysearch::Business.build_business(e)) | ||
end | ||
|
||
result | ||
end | ||
|
||
def parse_reviews_results(json) | ||
result = [] | ||
return result if json.nil? || json["results"].nil? | ||
|
||
json = json["results"] || [] | ||
json["reviews"].each do |e| | ||
result.push(Providers::Citysearch::Review.new(e)) | ||
end | ||
|
||
result | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Providers | ||
module Citysearch | ||
class Business | ||
attr_accessor :name, :address, :reference, :average_rating, :total_reviews | ||
|
||
def self.build_business(node) | ||
return nil if [node["name"], node["address"], node["review_info"], node["id"]].include?(nil) | ||
new(node) | ||
end | ||
|
||
private | ||
|
||
def initialize(node) | ||
@name = node["name"] | ||
full_address = node["address"] | ||
@address = [full_address["street"], full_address["city"], full_address["state"], full_address["postal_code"]].join(" ") | ||
@reference = node["id"] | ||
@total_reviews = node['review_info']['total_user_reviews'] | ||
@average_rating = node['review_info']['overall_review_rating'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
module Providers | ||
module Citysearch | ||
class Review | ||
attr_accessor :rating, :author_name, :reviewed_at, :comment | ||
|
||
def initialize(node) | ||
@rating = node["review_rating"] | ||
@author_name = node["review_author"] | ||
@reviewed_at = DateTime.parse(node["review_date"]).to_time | ||
@comment = node["review_text"] | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.