user_reviews_alt 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7fae1107bfb80666e31fa43f1512ecf61199d9bf4433b8018e7142b471517fb6
4
+ data.tar.gz: 9cead4937c9e719ec989fad65e656bb67b5cd93a59acfea1ee5383987e7c4b96
5
+ SHA512:
6
+ metadata.gz: 87752c30f6d694c5b187eb145ae90dca3d8f9caacaf756d90acee2d6f7a43b58b145f81e8aa2be9e5840d2f6705f799073372e5ac30f6571b7a1975e75ebd69e
7
+ data.tar.gz: 2d4376e88483f2ff5a2ff905fee8c535e2255c9ddd6d6c8f9d96ac6a3227c4a673355852849632aa9d823fa4ffb7941946ea90d707be874d9a98e70e5bcaa6de
@@ -0,0 +1,19 @@
1
+ *.rbc
2
+ .bundle
3
+ .config
4
+ .yardoc
5
+ InstalledFiles
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ .pairs
17
+ user_reviews-*.gem
18
+ scripts
19
+ scripts/**/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in user_reviews.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ user_reviews_alt (0.0.2)
5
+ httparty
6
+ json
7
+ oauth
8
+ rake
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ httparty (0.16.3)
14
+ mime-types (~> 3.0)
15
+ multi_xml (>= 0.5.2)
16
+ json (2.1.0)
17
+ mime-types (3.2.2)
18
+ mime-types-data (~> 3.2015)
19
+ mime-types-data (3.2018.0812)
20
+ multi_xml (0.6.0)
21
+ oauth (0.5.4)
22
+ rake (12.3.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ user_reviews_alt!
29
+
30
+ BUNDLED WITH
31
+ 1.17.1
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Unpakt LLC
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ # UserReviews
2
+
3
+ [![Build Status](https://secure.travis-ci.org/Unpakt/user_reviews.png?branch=master)](http://travis-ci.org/unpakt/user_reviews)
4
+
5
+ Is a simple api wrapper for:
6
+
7
+ * Yelp
8
+ * Citysearch
9
+ * Google Ratings
10
+
11
+ ## Getting started
12
+
13
+ ### Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'user_reviews'
17
+ ```
18
+
19
+ ### And then execute:
20
+
21
+ ```console
22
+ $ bundle
23
+ ```
24
+
25
+ ### Or install it yourself as:
26
+
27
+ ```console
28
+ $ gem install user_reviews
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Create an api_provider
34
+
35
+ ### For Citysearch
36
+
37
+ ```ruby
38
+ auth_info = {publisher_key: 'your_city_search_api_key'}
39
+ city_search = UserReviews.provider_factory(:citysearch, auth_info)
40
+ ```
41
+
42
+ ### For Google Reviews
43
+
44
+ ```ruby
45
+ auth_info = {key: 'your_google_api_key'}
46
+ google = UserReviews.provider_factory(:google, auth_info)
47
+ ```
48
+
49
+ ### For Yelp
50
+
51
+ ```ruby
52
+ auth_info = {consumer_key: 'yelp_consumer_key', consumer_secret:'yelp_consumer_secret' ,token:'yelp_token' , token_secret:'yelp_token_secret'}
53
+ yelp = UserReviews.provider_factory(:yelp, auth_info)
54
+ ```
55
+
56
+ ### Get reviews for a business
57
+
58
+ ```ruby
59
+ city_search.find_reviews_for_business city_search_business_id
60
+ ```
61
+
62
+ ### Get information about a business
63
+
64
+ ```ruby
65
+ city_search.find_business_by_id(business_id)
66
+ ```
67
+
68
+ Each Review object has 4 attributes:
69
+ * author_name
70
+ * rating
71
+ * reviewed_at
72
+ * comment
73
+
74
+ Each Business object has 4 attributes:
75
+ * name
76
+ * address
77
+ * reference
78
+ * average_rating
79
+ * url
80
+
81
+
82
+ More information about each API:
83
+
84
+ * Yelp: http://www.yelp.com/developers/documentation/v2/overview
85
+ * CitySearch: http://www.citygridmedia.com/developer/
86
+ * GoogleReviews: https://developers.google.com/places/documentation/
87
+
88
+
89
+ ## Contributing
90
+
91
+ 1. Fork it
92
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
93
+ 3. Add your own provider folder which inherits from the Providers::Base class and tests
94
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 5. Push to the branch (`git push origin my-new-feature`)
96
+ 6. Create new Pull Request
97
+
98
+ ## License
99
+
100
+ MIT License. Copyright 2013. http://www.unpakt.com
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bundler'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+
10
+
@@ -0,0 +1,20 @@
1
+ require 'httparty'
2
+ require 'oauth'
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'date'
6
+
7
+ module Providers
8
+ class Base
9
+
10
+ def find_business_by_name(name, business_type, city_state = "")
11
+ end
12
+
13
+ def find_reviews_for_business(ref)
14
+ end
15
+
16
+ def find_business_by_id(id)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,72 @@
1
+ module Providers
2
+ module Citysearch
3
+ class Api < Providers::Base
4
+
5
+ LOCALHOST_IP = "127.0.0.1"
6
+
7
+ def initialize(options)
8
+ @key = options[:publisher_key]
9
+ @ip = options[:client_ip] || LOCALHOST_IP
10
+ end
11
+
12
+ def find_business_by_name(name, business_type, city_state)
13
+ request_url = business_search_url(name, business_type, city_state)
14
+ json_results = HTTParty.get(request_url)
15
+ parse_business_results(json_results)
16
+ end
17
+
18
+ def find_business_by_id(citysearch_id)
19
+ request_url = business_url(citysearch_id)
20
+ json_results = HTTParty.get(request_url)
21
+ json = json_results["locations"] || []
22
+
23
+ return json if json.empty?
24
+ Providers::Citysearch::Business.build_business(json.first)
25
+ end
26
+
27
+ def find_reviews_for_business(citysearch_id)
28
+ request_url = reviews_url(citysearch_id)
29
+ json_results = HTTParty.get(request_url)
30
+ parse_reviews_results(json_results)
31
+ end
32
+
33
+ private
34
+
35
+ def business_url(citysearch_id)
36
+ "http://api.citygridmedia.com/content/places/v2/detail?publisher=#{@key}&id=#{citysearch_id}&id_type=cs&client_ip=127.0.0.1&format=json"
37
+ end
38
+
39
+ def business_search_url(name, business_type = "", city_state)
40
+ "http://api.citygridmedia.com/content/places/v2/search/where?where=#{URI::encode(city_state)}&what=#{URI::encode(name)}&publisher=#{@key}&format=json"
41
+ end
42
+
43
+ def reviews_url(citysearch_id)
44
+ "http://api.citygridmedia.com/content/reviews/v2/search/where?listing_id=#{citysearch_id}&publisher=#{@key}&format=json"
45
+ end
46
+
47
+ def parse_business_results(json)
48
+ result = []
49
+ return result if json.nil? || json.parsed_response.nil? || json.parsed_response["results"].nil?
50
+
51
+ json = json.parsed_response["results"]
52
+ json["locations"].each do |e|
53
+ result.push(Providers::Citysearch::Business.build_business(e))
54
+ end
55
+
56
+ result
57
+ end
58
+
59
+ def parse_reviews_results(json)
60
+ result = []
61
+ return result if json.nil? || json["results"].nil?
62
+
63
+ json = json["results"] || []
64
+ json["reviews"].each do |e|
65
+ result.push(Providers::Citysearch::Review.new(e))
66
+ end
67
+
68
+ result
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,30 @@
1
+ module Providers
2
+ module Citysearch
3
+ class Business
4
+ attr_accessor :name, :address, :reference, :average_rating, :total_reviews, :url
5
+
6
+ def self.build_business(node)
7
+ return nil if node.nil? ||
8
+ node["id"].nil? ||
9
+ node["name"].nil? ||
10
+ node["address"].nil?
11
+
12
+ new(node)
13
+ end
14
+
15
+ private
16
+
17
+ def initialize(node)
18
+ @name = node["name"]
19
+ full_address = node["address"]
20
+ @address = [full_address["street"], full_address["city"], full_address["state"], full_address["postal_code"]].join(" ")
21
+ @reference = node["id"]
22
+ @url = node["profile"]
23
+ if node.has_key?("review_info")
24
+ @total_reviews = node["review_info"].fetch("total_user_reviews", nil)
25
+ @average_rating = node["review_info"]["overall_review_rating"]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module Providers
3
+ module Citysearch
4
+ class Review
5
+ attr_accessor :rating, :author_name, :reviewed_at, :comment
6
+
7
+ def initialize(node)
8
+ @rating = node["review_rating"]
9
+ @author_name = node["review_author"]
10
+ @reviewed_at = DateTime.parse(node["review_date"]).to_time
11
+ @comment = node["review_text"]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,73 @@
1
+ module Providers
2
+ module Google
3
+ class ExceededQueryLimitError < StandardError; end
4
+
5
+ class Api < Providers::Base
6
+
7
+ def initialize(options)
8
+ @key = options[:key]
9
+ end
10
+
11
+ def find_business_by_name(name, business_type, city_state = "")
12
+ request_url = business_url(name, business_type)
13
+ @json_results = HTTParty.get(request_url)
14
+ parse_business_results(@json_results)
15
+ end
16
+
17
+ def find_reviews_for_business(ref)
18
+ request_url = reviews_url(ref)
19
+ @json_results = HTTParty.get(request_url)
20
+ parse_reviews_results(@json_results)
21
+ end
22
+
23
+ def find_business_by_id(google_id)
24
+ request_url = reviews_url(google_id)
25
+ @json_results = HTTParty.get(request_url)
26
+ return @json_results if @json_results.nil?
27
+
28
+ json = @json_results["result"]
29
+ return json if json.nil?
30
+
31
+ Providers::Google::Business.build_business(json)
32
+ end
33
+
34
+ private
35
+
36
+ def query_limit_has_been_reached?
37
+ @json_results["status"] == 'OVER_QUERY_LIMIT'
38
+ end
39
+
40
+ def business_url(business_name, business_type)
41
+ "https://maps.googleapis.com/maps/api/place/textsearch/json?key=#{@key}&query=#{URI::encode(business_name, /\W/)}=&sensor=false&type=#{URI::encode(business_type)}"
42
+ end
43
+
44
+ def reviews_url(reference)
45
+ "https://maps.googleapis.com/maps/api/place/details/json?key=#{@key}&reference=#{reference}&sensor=false"
46
+ end
47
+
48
+ def parse_business_results(json)
49
+ raise Providers::Google::ExceededQueryLimitError if query_limit_has_been_reached?
50
+
51
+ result = []
52
+ return result if json.nil? || json["results"].nil?
53
+
54
+ json["results"].each do |e|
55
+ result.push(Providers::Google::Business.build_business(e))
56
+ end
57
+
58
+ result
59
+ end
60
+
61
+ def parse_reviews_results(json)
62
+ result = []
63
+ return result if json.nil? || json["result"].nil? || json["result"]["reviews"].nil?
64
+
65
+ json["result"]["reviews"].each do |e|
66
+ result.push(Providers::Google::Review.new(e))
67
+ end
68
+
69
+ result
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,22 @@
1
+ module Providers
2
+ module Google
3
+ class Business
4
+ attr_accessor :name, :address, :reference, :average_rating, :url, :total_number_of_ratings
5
+
6
+ def self.build_business(node)
7
+ return nil if [node["name"], node["formatted_address"], node["reference"]].include?(nil)
8
+ new(node)
9
+ end
10
+
11
+ private
12
+ def initialize(node)
13
+ @name = node["name"]
14
+ @address = node["formatted_address"]
15
+ @reference = node["reference"]
16
+ @average_rating = node["rating"]
17
+ @total_number_of_ratings = node["user_ratings_total"]
18
+ @url = node["url"]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Providers
2
+ module Google
3
+ class Review
4
+ attr_accessor :rating, :author_name, :reviewed_at, :comment
5
+
6
+ def initialize(node)
7
+ @rating = node["rating"]
8
+ @author_name = node["author_name"]
9
+ @reviewed_at = Time.at(node["time"].to_i)
10
+ @comment = node["text"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,76 @@
1
+ module Providers
2
+ module Yelp
3
+ class Api < Providers::Base
4
+
5
+ def initialize(options)
6
+ @consumer_key = options[:consumer_key]
7
+ @consumer_secret = options[:consumer_secret]
8
+ @token = options[:token]
9
+ @token_secret = options[:token_secret]
10
+ end
11
+
12
+ def find_business_by_name(name, business_type, city_state)
13
+ access_token = create_oauth_token
14
+ response = JSON.parse(access_token.get(business_path(name, business_type, city_state)).body)
15
+ parse_businesses(response["businesses"])
16
+ end
17
+
18
+ def find_reviews_for_business(yelp_id)
19
+ access_token = create_oauth_token
20
+ response = JSON.parse(access_token.get(review_path(yelp_id)).body)
21
+ parse_reviews(response["reviews"])
22
+ end
23
+
24
+ def find_business_by_id(yelp_id)
25
+ access_token = create_oauth_token
26
+ response = JSON.parse(access_token.get(review_path(yelp_id)).body)
27
+ Providers::Yelp::Business.build_business(response) if response &&
28
+ response["location"] &&
29
+ response["location"]["display_address"]
30
+
31
+ end
32
+
33
+ private
34
+
35
+ def create_oauth_token
36
+ consumer_key = @consumer_key
37
+ consumer_secret = @consumer_secret
38
+ token = @token
39
+ token_secret = @token_secret
40
+
41
+ consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: "http://api.yelp.com")
42
+ OAuth::AccessToken.new(consumer, token, token_secret)
43
+ end
44
+
45
+ def business_path(name, business_type, city_state)
46
+ "/v2/search?term=#{URI::encode(name)}&category_filter=#{URI::encode(business_type)}&location=#{URI::encode(city_state)}"
47
+ end
48
+
49
+ def review_path(yelp_id)
50
+ "/v2/business/#{yelp_id}"
51
+ end
52
+
53
+ def parse_businesses(business_list)
54
+ result = []
55
+ return result if business_list.nil? || business_list.empty?
56
+
57
+ business_list.each do |business|
58
+ result.push(Providers::Yelp::Business.build_business(business))
59
+ end
60
+
61
+ result
62
+ end
63
+
64
+ def parse_reviews(review_list)
65
+ result = []
66
+ return result if review_list.nil?
67
+
68
+ review_list.each do |review|
69
+ result.push(Providers::Yelp::Review.new(review))
70
+ end
71
+
72
+ result
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,29 @@
1
+ module Providers
2
+ module Yelp
3
+ class Business
4
+ attr_accessor :name, :address, :yelp_id, :average_rating, :total_reviews, :url
5
+
6
+ def self.build_business(node)
7
+ return nil if node.nil? ||
8
+ node["id"].nil? ||
9
+ node["name"].nil? ||
10
+ node["location"].nil? ||
11
+ node["location"].empty? ||
12
+ node["location"]["display_address"].nil?
13
+
14
+ new(node)
15
+ end
16
+
17
+ private
18
+
19
+ def initialize(node)
20
+ @address = node["location"]["display_address"].join(" ")
21
+ @name = node["name"]
22
+ @average_rating = node["rating"]
23
+ @total_reviews = node["review_count"]
24
+ @yelp_id = node["id"]
25
+ @url = node["url"]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ module Providers
2
+ module Yelp
3
+ class Review
4
+ attr_accessor :rating, :author_name, :reviewed_at, :comment
5
+
6
+ def initialize(node)
7
+ @rating = node["rating"]
8
+ @author_name = node["name"]
9
+ @reviewed_at = Time.at(node["time_created"].to_i)
10
+ @comment = node["excerpt"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require "user_reviews/version"
2
+ require 'active_support/inflector'
3
+
4
+ Dir[File.dirname(__FILE__) + "/providers/*.rb"].each do |file|
5
+ require "#{file}"
6
+ end
7
+
8
+ Dir[File.dirname(__FILE__) + "/providers/**/*.rb"].each do |file|
9
+ require "#{file}"
10
+ end
11
+
12
+ module UserReviews
13
+ class ProviderNotFoundError < StandardError; end
14
+
15
+ include ActiveSupport::Inflector
16
+
17
+ def self.provider_factory(service, init_options)
18
+ service = service.to_s.classify
19
+
20
+ begin
21
+ "Providers::#{service}::Api".constantize.new(init_options)
22
+ rescue => e
23
+ raise ProviderNotFoundError.new(e)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module UserReviews
2
+ VERSION = "0.0.2".freeze
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Citysearch::Api do
4
+
5
+ describe "#initialize" do
6
+ it "initializes a new CitySearch provider" do
7
+ Providers::Citysearch::Api.new(publisher_key: "").should be
8
+ end
9
+ end
10
+
11
+ describe "#find_business_by_name" do
12
+ let(:json_result) { { "address" => {} } }
13
+ let(:business_url) { "http://www.example.com" }
14
+ let(:citysearch_wrapper) { Providers::Citysearch::Api.new(key: "") }
15
+ let(:query_result) { [Providers::Citysearch::Business.build_business(json_result)] }
16
+
17
+ it "returns an array of possible businesses" do
18
+ citysearch_wrapper.should_receive(:business_search_url).with("Unpakt", "moving company", "NY,NY") { business_url }
19
+ HTTParty.should_receive(:get).with(business_url) { json_result }
20
+ citysearch_wrapper.should_receive(:parse_business_results).with(json_result) { query_result }
21
+
22
+ citysearch_wrapper.find_business_by_name("Unpakt", "moving company", "NY,NY").should eq query_result
23
+ end
24
+ end
25
+
26
+
27
+ describe "#find_reviews_for_business" do
28
+ let(:citysearch_id) { stub }
29
+ let(:json_result) { {"review_date" => "2007-03-07T21:53:41.000Z"} }
30
+ let(:reviews_url) { "http://www.example.com" }
31
+ let(:citysearch_wrapper) { Providers::Citysearch::Api.new(key: "") }
32
+ let(:query_result) { [Providers::Citysearch::Review.new(json_result)] }
33
+
34
+ it "returns the rating for a given entity" do
35
+ citysearch_wrapper.should_receive(:reviews_url).with(citysearch_id) { reviews_url }
36
+ HTTParty.should_receive(:get).with(reviews_url) { json_result }
37
+ citysearch_wrapper.should_receive(:parse_reviews_results).with(json_result) { query_result }
38
+
39
+ citysearch_wrapper.find_reviews_for_business(citysearch_id).should eq query_result
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Citysearch::Business do
4
+ describe "#initialize" do
5
+ let(:address) { {"street" => '', "city" => '', "state" => '', "postal_code" => '' } }
6
+
7
+ context "when required fields are not present" do
8
+ let(:node) do
9
+ {
10
+ "address" => address,
11
+ "id" => stub,
12
+ "rating" => stub,
13
+ "review_info" => {}
14
+ }
15
+ end
16
+
17
+ it "returns nil" do
18
+ biz = Providers::Citysearch::Business.build_business(node)
19
+ biz.should be_nil
20
+ end
21
+ end
22
+
23
+ context "when required fields are present" do
24
+ let(:node) do
25
+ {
26
+ "name" => '',
27
+ "address" => address,
28
+ "id" => stub,
29
+ "rating" => stub,
30
+ "user_review_count" => stub,
31
+ "profile" => stub
32
+ }
33
+ end
34
+
35
+ it "returns an Bussiness object" do
36
+ Providers::Citysearch::Business.build_business(node).should be
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Google::Api do
4
+
5
+ describe "#initialize" do
6
+ it "initializes a new GoogleReviews provider" do
7
+ Providers::Google::Api.new(key: "").should be
8
+ end
9
+ end
10
+
11
+ describe "#find_business_by_name" do
12
+ let(:json_result) { "{}" }
13
+ let(:business_url) { "http://www.example.com" }
14
+ let(:google_wrapper) { Providers::Google::Api.new(key: "") }
15
+ let(:query_result) { [Providers::Google::Business.build_business(json_result)] }
16
+
17
+ context "when the api is valid" do
18
+ it "returns an array of possible businesses" do
19
+ google_wrapper.should_receive(:business_url).with("Unpakt", "moving_company") { business_url }
20
+ HTTParty.should_receive(:get).with(business_url) { json_result }
21
+ google_wrapper.should_receive(:parse_business_results).with(json_result) { query_result }
22
+
23
+ google_wrapper.find_business_by_name("Unpakt", "moving_company").should eq query_result
24
+ end
25
+ end
26
+
27
+ context "when the api query limit is reached" do
28
+ let(:json_result) { {'status' => 'OVER_QUERY_LIMIT'} }
29
+
30
+ it "raises an error" do
31
+ google_wrapper.should_receive(:business_url).with("Unpakt", "moving_company") { business_url }
32
+ HTTParty.should_receive(:get).with(business_url) { json_result }
33
+ lambda { google_wrapper.find_business_by_name("Unpakt", "moving_company") }.should raise_error Providers::Google::ExceededQueryLimitError
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#find_reviews_for_business" do
39
+ let(:reference) { stub }
40
+ let(:json_result) { "{}" }
41
+ let(:reviews_url) { "http://www.example.com" }
42
+ let(:google_wrapper) { Providers::Google::Api.new(key: "") }
43
+ let(:query_result) { [Providers::Google::Review.new(json_result)] }
44
+
45
+ it "returns the rating for a given entity" do
46
+ google_wrapper.should_receive(:reviews_url).with(reference) { reviews_url }
47
+ HTTParty.should_receive(:get).with(reviews_url) { json_result }
48
+ google_wrapper.should_receive(:parse_reviews_results).with(json_result) { query_result }
49
+
50
+ google_wrapper.find_reviews_for_business(reference).should eq query_result
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Google::Business do
4
+ describe "#initialize" do
5
+ let(:node) do
6
+ {
7
+ "name" => '',
8
+ "formatted_address" => '',
9
+ "reference" => stub,
10
+ "url" => stub,
11
+ "rating" => stub,
12
+ "user_ratings_total" => stub
13
+ }
14
+ end
15
+
16
+ context "when required fields are not present" do
17
+ let(:node) { Hash.new(nil) }
18
+ it "returns nil" do
19
+ biz = Providers::Google::Business.build_business(node)
20
+ biz.should be_nil
21
+ end
22
+ end
23
+
24
+ context "when required fields are present" do
25
+ it "returns an Bussiness object" do
26
+ Providers::Google::Business.build_business(node).should be
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Yelp::Api do
4
+
5
+ describe "#initialize" do
6
+ it "initializes a new GoogleReviews provider" do
7
+ Providers::Yelp::Api.new(consumer_key: "",
8
+ consumer_secret: "",
9
+ token: "",
10
+ token_secret: "").should be
11
+ end
12
+ end
13
+
14
+ describe "#find_business_by_name" do
15
+ let(:token) { stub }
16
+ let(:api_result) { stub }
17
+ let(:response_body) { stub }
18
+ let(:business_path) { "super_path" }
19
+ let(:business_place) do
20
+ {"location" => {"display_address" => ["1 Place", "NY"]}}
21
+ end
22
+ let(:json_result) {{"businesses" => business_places }}
23
+ let(:business_places) { [business_place] }
24
+ let(:yelp_wrapper) { Providers::Yelp::Api.new({}) }
25
+ let(:query_result) { [Providers::Yelp::Business.build_business(business_place)] }
26
+
27
+ it "returns an array of possible businesses" do
28
+ yelp_wrapper.should_receive(:create_oauth_token) { token }
29
+ yelp_wrapper.should_receive(:business_path).with("Unpakt", "movers", "NY,NY") { business_path }
30
+ token.should_receive(:get).with(business_path) { api_result }
31
+ api_result.should_receive(:body) { response_body }
32
+
33
+
34
+ JSON.should_receive(:parse).with(response_body) { json_result }
35
+ yelp_wrapper.should_receive(:parse_businesses).with(business_places) { query_result }
36
+
37
+ yelp_wrapper.find_business_by_name("Unpakt", "movers", "NY,NY").should eq query_result
38
+ end
39
+ end
40
+
41
+
42
+ describe "#find_reviews_for_business" do
43
+ let(:token) { stub }
44
+ let(:api_result) { stub }
45
+ let(:response_body) { stub }
46
+ let(:review_path) { "super_path" }
47
+ let(:review) {{"rating" => 1}}
48
+ let(:reviews) { [review] }
49
+ let(:json_result) {{"reviews" => reviews }}
50
+ let(:yelp_wrapper) { Providers::Yelp::Api.new({}) }
51
+ let(:query_result) { [Providers::Yelp::Review.new(review)] }
52
+
53
+ it "returns an array of possible businesses" do
54
+ yelp_wrapper.should_receive(:create_oauth_token) { token }
55
+ yelp_wrapper.should_receive(:review_path).with("yelp-Unpakt") { review_path }
56
+ token.should_receive(:get).with(review_path) { api_result }
57
+ api_result.should_receive(:body) { response_body }
58
+
59
+
60
+ JSON.should_receive(:parse).with(response_body) { json_result }
61
+ yelp_wrapper.should_receive(:parse_reviews).with(reviews) { query_result }
62
+
63
+ yelp_wrapper.find_reviews_for_business("yelp-Unpakt").should eq query_result
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Providers::Yelp::Business do
4
+ describe "#initialize" do
5
+ context "when required fields are not present" do
6
+ let(:node) do
7
+ {
8
+ "location" => {},
9
+ "rating" => '',
10
+ "id" => stub,
11
+ }
12
+ end
13
+
14
+ it "returns nil" do
15
+ biz = Providers::Yelp::Business.build_business(node)
16
+ biz.should be_nil
17
+ end
18
+ end
19
+
20
+ context "when required fields are present" do
21
+ let(:node) do
22
+ {
23
+ "location" => { "display_address" => ["City", "Zip"] },
24
+ "rating" => stub,
25
+ "name" => stub,
26
+ "url" => stub,
27
+ "review_count" => stub,
28
+ "id" => stub,
29
+ }
30
+ end
31
+
32
+ it "returns an Bussiness object" do
33
+ Providers::Yelp::Business.build_business(node).should be
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require_relative File.dirname(__FILE__) + "/../lib/user_reviews"
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
21
+
22
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe UserReviews do
4
+ describe "::provider_factory" do
5
+ context "when the provider exists" do
6
+ it "returns a new Yelp api provider object" do
7
+ UserReviews.provider_factory(:yelp, {}).should be_an_instance_of Providers::Yelp::Api
8
+ end
9
+
10
+ it "returns a new google api provider object" do
11
+ UserReviews.provider_factory(:google, {}).should be_an_instance_of Providers::Google::Api
12
+ end
13
+
14
+ it "returns a new citysearch api provider object" do
15
+ UserReviews.provider_factory(:citysearch, {}).should be_an_instance_of Providers::Citysearch::Api
16
+ end
17
+ end
18
+
19
+ context "when the :not_found provider doesn't exist" do
20
+ it "raises a provider not found error" do
21
+ lambda {UserReviews.provider_factory(:foobar, {}) }.should raise_error UserReviews::ProviderNotFoundError
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'user_reviews/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "user_reviews_alt"
8
+ gem.version = UserReviews::VERSION.dup
9
+ gem.authors = ["Unpakt LLC"]
10
+ gem.email = ["info@unpakt.com"]
11
+ gem.description = %q{Wrapper for mulitple user review APIs}
12
+ gem.summary = %q{Wrapper for mulitple user review APIs}
13
+ gem.homepage = "http://www.unpakt.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rake"
21
+ gem.add_dependency "httparty"
22
+ gem.add_dependency "oauth"
23
+ gem.add_dependency "json"
24
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user_reviews_alt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Unpakt LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Wrapper for mulitple user review APIs
70
+ email:
71
+ - info@unpakt.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/providers/base.rb
84
+ - lib/providers/citysearch/api.rb
85
+ - lib/providers/citysearch/business.rb
86
+ - lib/providers/citysearch/review.rb
87
+ - lib/providers/google/api.rb
88
+ - lib/providers/google/business.rb
89
+ - lib/providers/google/review.rb
90
+ - lib/providers/yelp/api.rb
91
+ - lib/providers/yelp/business.rb
92
+ - lib/providers/yelp/review.rb
93
+ - lib/user_reviews.rb
94
+ - lib/user_reviews/version.rb
95
+ - spec/providers/citysearch/api_spec.rb
96
+ - spec/providers/citysearch/business_spec.rb
97
+ - spec/providers/google/api_spec.rb
98
+ - spec/providers/google/business_spec.rb
99
+ - spec/providers/yelp/api_spec.rb
100
+ - spec/providers/yelp/business_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/user_reviews_spec.rb
103
+ - user_reviews.gemspec
104
+ homepage: http://www.unpakt.com
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.7.7
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Wrapper for mulitple user review APIs
127
+ test_files:
128
+ - spec/providers/citysearch/api_spec.rb
129
+ - spec/providers/citysearch/business_spec.rb
130
+ - spec/providers/google/api_spec.rb
131
+ - spec/providers/google/business_spec.rb
132
+ - spec/providers/yelp/api_spec.rb
133
+ - spec/providers/yelp/business_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/user_reviews_spec.rb