google-business-reviews 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47b83a665fd35fb2cf79b448a29349c564b7ab59c52f165cbd512d9fbaf88246
4
+ data.tar.gz: ebd02051e5106398a9f157b525d9c58a3b1ffefa879f8f2ecb3f7f51b9d32667
5
+ SHA512:
6
+ metadata.gz: e681536f50b10a498c1f7e5ab79756168e4a96e0b21b4380aaec880a8a4bad6e51a19daa64d26f65f4f622a54c4739bf9a07e3d3b31f4edebc6b1189881b20d5
7
+ data.tar.gz: ca243b6ce2c3d9937b7e478205dd6538216b923222f79d03bab8458057b9b8c3f728827d9b750666731be4102999c4af57e14a3920ab3db6c73208550c249bc3
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ require: rubocop-rake
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.7
5
+ NewCops: enable
6
+
7
+ Style/StringLiterals:
8
+ Enabled: true
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/NumericLiterals:
12
+ Enabled: false
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Layout/IndentationStyle:
22
+ EnforcedStyle: tabs
23
+
24
+ Layout/IndentationWidth:
25
+ Width: 1
26
+
27
+ Layout/LineLength:
28
+ Max: 150
29
+
30
+ Metrics/AbcSize:
31
+ CountRepeatedAttributes: false
32
+ Max: 20
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-10-08
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at gabhawaladhairya@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in google-business-reviews.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ google-business-reviews (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ minitest (5.14.4)
11
+ parallel (1.21.0)
12
+ parser (3.0.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rubocop (1.22.1)
19
+ parallel (~> 1.10)
20
+ parser (>= 3.0.0.0)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ regexp_parser (>= 1.8, < 3.0)
23
+ rexml
24
+ rubocop-ast (>= 1.12.0, < 2.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (>= 1.4.0, < 3.0)
27
+ rubocop-ast (1.12.0)
28
+ parser (>= 3.0.1.1)
29
+ rubocop-minitest (0.15.1)
30
+ rubocop (>= 0.90, < 2.0)
31
+ rubocop-rake (0.6.0)
32
+ rubocop (~> 1.0)
33
+ ruby-progressbar (1.11.0)
34
+ unicode-display_width (2.1.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ google-business-reviews!
41
+ minitest (~> 5.14, >= 5.14.4)
42
+ rake (~> 13.0)
43
+ rubocop (~> 1.7)
44
+ rubocop-minitest
45
+ rubocop-rake
46
+
47
+ BUNDLED WITH
48
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Dhairya Gabhawala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Google Business Reviews
2
+
3
+ Google Business Reviews ruby gem uses Google Places API to fetch review for a particular location by using place_id.
4
+
5
+ [![Ruby](https://github.com/dhairyagabha/google-business-reviews/actions/workflows/main.yml/badge.svg)](https://github.com/dhairyagabha/google-business-reviews/actions/workflows/main.yml)
6
+
7
+ ## Requirements
8
+
9
+ ### Obtain Google API Key
10
+ 1. Open Google Developers console.
11
+ 2. Create a project dedicated to your application.
12
+ 3. Enable Places API nested in Google Maps API.
13
+ 4. Create or attach a billing account to your project.
14
+ 5. Generate and save the API key.
15
+
16
+ ### Obtain Place ID
17
+ 1. Visit the [link](https://developers.google.com/maps/documentation/places/web-service/place-id) and search for your location.
18
+ 2. Copy the place_id as shown in the image below.
19
+ ![](place_id_example.png "Google Place ID Finder Screenshot")
20
+ 3. Examples:
21
+ 1. `ChIJpQunTLG7j4ARaSCG1AlurCI`
22
+ 2. `ChIJgUbEo8cfqokR5lP9_Wh_DaM`
23
+ 3. `GhIJQWDl0CIeQUARxks3icF8U8A`
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'google-business-reviews'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle install
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install google-business-reviews
40
+
41
+ ## Usage
42
+ Simply include the module, add the Google API Key as environment variable for security reasons and fetch reviews by passing the `place_id`.
43
+ ```ruby
44
+ class Business < ApplicationRecord
45
+ include Google::Business::Reviews
46
+
47
+ def reviews
48
+ get_business_reviews(ENV["GOOGLE_API_KEY"], self.place_id)
49
+ end
50
+ end
51
+ ```
52
+ Response is converted to RUBY objects `Review` and `Author`.
53
+ ```ruby
54
+ # Google::Business::Reviews::Author
55
+ # ---------------------------------
56
+ # Attributes
57
+ # ----------
58
+ # [String] Name: Author name
59
+ # [String] URL: Author Google reviews profile
60
+ # [String] Avatar: Author profile avatar url
61
+ #
62
+ # Methods
63
+ # -------
64
+ # [JSON] as_json: Returns a JSON object with all attributes.
65
+ # [JSON] to_s: Returns a string with pattern "Name: #{name} Url: #{url} Avatar: #{avatar}"
66
+
67
+
68
+ # Google::Business::Reviews::Review
69
+ # ---------------------------------
70
+ # Attributes
71
+ # ----------
72
+ # [Author] Author: Review Author
73
+ # [String] Language: Language of the review
74
+ # [Integer] Rating: 1-5 review rating for the location
75
+ # [String] Content: Text content of the review
76
+ # [String] Time: Time returned as date and timestamp
77
+ # [String] Relative Time: Text time such as "a month ago"
78
+ #
79
+ # Methods
80
+ # -------
81
+ # [JSON] as_json: Returns a JSON object with all attributes.
82
+ # [JSON] to_s: Returns a string with pattern "#{author.name} wrote #{content} about #{relative_time}"
83
+ ```
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google-business-reviews. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/google-business-reviews/blob/master/CODE_OF_CONDUCT.md).
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the Google::Business::Reviews project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/google-business-reviews/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "rake/testtask"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :rubocop
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << "test"
13
+ t.libs << "lib"
14
+ t.test_files = FileList["test/**/test_*.rb"]
15
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "google/business/reviews"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Google
4
+ module Business
5
+ module Reviews
6
+ class Author
7
+ attr_reader :name, :url, :avatar
8
+
9
+ def initialize(name, url, avatar)
10
+ @name = name
11
+ @url = url
12
+ @avatar = avatar
13
+ end
14
+
15
+ def to_s
16
+ "Name: #{name}, Url: #{url}, Avatar: #{avatar}"
17
+ end
18
+
19
+ def as_json
20
+ {
21
+ name: name,
22
+ url: url,
23
+ avatar: avatar
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "author"
4
+
5
+ module Google
6
+ module Business
7
+ module Reviews
8
+ class Review
9
+ attr_reader :author, :language, :rating, :content, :time, :relative_time
10
+
11
+ def initialize(rev)
12
+ @author = Google::Business::Reviews::Author.new(rev[:author_name], rev[:author_url], rev[:profile_photo_url])
13
+ @language = rev[:language]
14
+ @rating = rev[:rating]
15
+ @content = rev[:text]
16
+ @time = Time.at(rev[:time])
17
+ @relative_time = rev[:relative_time_description]
18
+ end
19
+
20
+ def to_s
21
+ "#{author.name} wrote #{content} about #{relative_time}"
22
+ end
23
+
24
+ def as_json
25
+ {
26
+ author: author.to_json,
27
+ language: language,
28
+ rating: rating,
29
+ content: content,
30
+ time: time,
31
+ relative_time: relative_time
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Google
4
+ module Business
5
+ module Reviews
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "reviews/version"
4
+ require_relative "reviews/review"
5
+ require_relative "reviews/author"
6
+ require "uri"
7
+ require "net/http"
8
+ require "json"
9
+ require "time"
10
+
11
+ module Google
12
+ module Business
13
+ module Reviews
14
+ # Service to fetch reviews based on place_id
15
+ class Error < StandardError; end
16
+
17
+ ENDPOINT = "https://maps.googleapis.com/maps/api/place/details/json"
18
+
19
+ def get_business_reviews(api_key, place_id)
20
+ url = URI("#{ENDPOINT}?key=#{api_key}&place_id=#{place_id}&fields=review")
21
+
22
+ https = Net::HTTP.new(url.host, url.port)
23
+ https.use_ssl = true
24
+
25
+ request = Net::HTTP::Get.new(url)
26
+ response = https.request(request)
27
+ response = JSON.parse(response.read_body)
28
+
29
+ raise StandardError, "[google-business-reviews] #{response["status"]}: #{response["error_message"]}" if response["status"] != "OK"
30
+
31
+ reviews = response["result"]["reviews"].map { |r| Review.new r }
32
+ reviews || []
33
+ end
34
+ end
35
+ end
36
+ end
Binary file
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-business-reviews
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dhairya Gabhawala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.14'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.14.4
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.14'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.14.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: rubocop
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.22'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.22'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop-minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Convenient way of adding Google Business Reviews to your application.
76
+ email:
77
+ - gabhawaladhairya@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".rubocop.yml"
83
+ - CHANGELOG.md
84
+ - CODE_OF_CONDUCT.md
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - lib/google/business/reviews.rb
93
+ - lib/google/business/reviews/author.rb
94
+ - lib/google/business/reviews/review.rb
95
+ - lib/google/business/reviews/version.rb
96
+ - place_id_example.png
97
+ homepage: https://github.com/dhairyagabha/google-business-reviews
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://github.com/dhairyagabha/google-business-reviews
102
+ source_code_uri: https://github.com/dhairyagabha/google-business-reviews
103
+ changelog_uri: https://github.com/dhairyagabha/google-business-reviews/blob/main/CHANGELOG.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.7.0
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.1.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Convenient way of adding Google Business Reviews to your application.
123
+ test_files: []