google_place_reviews 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/google_place_reviews.rb +70 -0
  3. metadata +42 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd0cdba21f8b25da09e7ce9b51d0319507469bd70dd5737eea9fa3ec30f34065
4
+ data.tar.gz: 0ec9fca3bf56bf3ba0ddda6e8ee69823e075b262a5602dfb915f206b17570199
5
+ SHA512:
6
+ metadata.gz: 1f3314a2d94729757cd7ec8584ba193ade0deadb27a8c8f200b18a720724734583903440f3b74f48222c0eafee275b9e3f16b16414b4bf2774d8c2576d290ed5
7
+ data.tar.gz: f371397b5b9de9adf871f9e14f927d785363042bf6d2959d57f4af68a7edf2880cab4fd7f5d1849f2605e747b577bcccbc57993c718975103d673edfd40baa0b
@@ -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 if "status" : "INVALID_REQUEST" or "result" : {}
27
+ return result,review
28
+ end
29
+
30
+ def 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 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.1
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.1
39
+ signing_key:
40
+ specification_version: 4
41
+ summary: Fetch reviews from Google Place
42
+ test_files: []