google_place_reviews 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.
- checksums.yaml +7 -0
- data/lib/google_place_reviews.rb +70 -0
- metadata +42 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d045f109852ec010b06279f927b12fddca479b4abba71e982ae01f0506c09f27
|
|
4
|
+
data.tar.gz: ddca1682053303cc264bde177223cfc3a1f139aa7bbf14481247b4b68287766d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1eb98e2b3fa3e8fadabd33c16ee38ab56b9f5c7044dcdcb53016e154e13602bfa666ebe721e79a6b5cd7dfcfa15a7918da133cc6ee1eca277a5955921b8bab3f
|
|
7
|
+
data.tar.gz: d700fc35f4e525c509799d2db5d33ee67f68d09cced607b2a83b81646d32d7e5ee35b4ae2df1499ef3d096258f8d1694739e19e1e223af1f02734a2e99ca8e59
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'rest-client'
|
|
2
|
+
require 'json'
|
|
3
|
+
module GooglePlaceReviews
|
|
4
|
+
|
|
5
|
+
def self.geocode(shopname,address)
|
|
6
|
+
url = 'https://maps.googleapis.com/maps/api/geocode/json?address='
|
|
7
|
+
resp = RestClient.get "#{url}#{shopname}#{address}&key=#{Rails.application.credentials.google_maps_api_key}"
|
|
8
|
+
if JSON.parse(resp.body)["status"] == "OK"
|
|
9
|
+
JSON.parse(resp.body)["results"][0]["place_id"]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.getReviewsByPlaceId(place_id)
|
|
14
|
+
url = 'https://maps.googleapis.com/maps/api/place/details/json?place_id='
|
|
15
|
+
resp = RestClient.get "#{url}#{place_id}&fields=review&key=#{Rails.application.credentials.google_maps_api_key}"
|
|
16
|
+
if JSON.parse(resp.body)["status"] == "OK"
|
|
17
|
+
result = JSON.parse(resp.body)["result"]["reviews"]
|
|
18
|
+
|
|
19
|
+
#Result store in a array(review(hash))
|
|
20
|
+
#getReviewsByPlaceId(place_id)[1][:rating] <- Return the rating from review[1]
|
|
21
|
+
review = []
|
|
22
|
+
for i in 0..4
|
|
23
|
+
review.push(:author_name => result[i]["author_name"],:rating => result[i]["rating"],:text => result[i]["text"] )
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
#Return [nil,nil] if "status" : "INVALID_REQUEST" or "result" : {}
|
|
27
|
+
return result,review
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.getOpenHoursPlaceId(place_id)
|
|
31
|
+
url = 'https://maps.googleapis.com/maps/api/place/details/json?place_id='
|
|
32
|
+
resp = RestClient.get "#{url}#{place_id}&fields=opening_hours&key=#{Rails.application.credentials.google_maps_api_key}"
|
|
33
|
+
if JSON.parse(resp.body)["status"] == "OK"
|
|
34
|
+
result = JSON.parse(resp.body)["result"]["opening_hours"]["weekday_text"]
|
|
35
|
+
|
|
36
|
+
#Result store in a array(hours) with key-value pairs
|
|
37
|
+
hours = {}
|
|
38
|
+
hours[:monday] = result[0].split(":",2).last
|
|
39
|
+
hours[:Tuesday] = result[1].split(":",2).last
|
|
40
|
+
hours[:Wednesday] = result[2].split(":",2).last
|
|
41
|
+
hours[:Thursday] = result[3].split(":",2).last
|
|
42
|
+
hours[:Friday] = result[4].split(":",2).last
|
|
43
|
+
hours[:Saturday] = result[5].split(":",2).last
|
|
44
|
+
hours[:Sunday] = result[6].split(":",2).last
|
|
45
|
+
end
|
|
46
|
+
#Return nil if "status" : "INVALID_REQUEST" or "result" : {}
|
|
47
|
+
return result,hours
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.getRatingReviewRatTotal(place_id)
|
|
52
|
+
url = 'https://maps.googleapis.com/maps/api/place/details/json?place_id='
|
|
53
|
+
resp = RestClient.get "#{url}#{place_id}&fields=rating,review,user_ratings_total&key=#{Rails.application.credentials.google_maps_api_key}"
|
|
54
|
+
if JSON.parse(resp.body)["status"] == "OK"
|
|
55
|
+
place_rating = JSON.parse(resp.body)["result"]["rating"]
|
|
56
|
+
nbRatingTotal = JSON.parse(resp.body)["result"]["user_ratings_total"]
|
|
57
|
+
reviews = JSON.parse(resp.body)["result"]["reviews"]
|
|
58
|
+
|
|
59
|
+
#Result store in a array(review(hash))
|
|
60
|
+
#getReviewsByPlaceId(place_id)[1][:rating] <- Return the rating from review[1]
|
|
61
|
+
review = []
|
|
62
|
+
for i in 0..4
|
|
63
|
+
review.push(:author_name => reviews[i]["author_name"],:rating => reviews[i]["rating"],:text => reviews[i]["text"] )
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
return place_rating,nbRatingTotal,review
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
metadata
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: google_place_reviews
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Marcio Camargo
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Fetch Place reviews using Google Places API and Geocoding API
|
|
14
|
+
email: decamargomarcio@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/google_place_reviews.rb
|
|
20
|
+
homepage: http://rubygems.org/gems/google_place_reviews
|
|
21
|
+
licenses: []
|
|
22
|
+
metadata: {}
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0'
|
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
requirements: []
|
|
38
|
+
rubygems_version: 3.0.6
|
|
39
|
+
signing_key:
|
|
40
|
+
specification_version: 4
|
|
41
|
+
summary: Fetch reviews from Google Place
|
|
42
|
+
test_files: []
|