google_reviews 1.0.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: 231e90d72dc86d146d4984725b9860fa6fe711a981cab4b1243c71e4ef432b93
4
+ data.tar.gz: d1bbf7d14bd4e7cfc696b259df887846fe4307a7c699542271045e8764c80979
5
+ SHA512:
6
+ metadata.gz: 2f0ec4a36b6fbfd5ede619e3ec9d1720d69f3a95f7df799533a4953cde8a3d265e8d3437d5782816e5e4307e04f25d74d1f79d53ad42bb73901062d1a0c18065
7
+ data.tar.gz: 37b030b38eacee137834924955f92616b13db1f903269e471d55c725ee684d174f16c26ee655d8926f8741c7f3db99b7bacbafb27c6e176ad6d5932760f3b67f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/LineLength:
16
+ Exclude:
17
+ - 'spec/**/*.rb'
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - 'spec/**/*.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-07-03
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 gullariz82@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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in google_reviews.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ google_reviews (0.1.0)
5
+ i18n
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.4)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ concurrent-ruby (1.2.2)
14
+ crack (0.4.5)
15
+ rexml
16
+ diff-lcs (1.5.0)
17
+ hashdiff (1.0.1)
18
+ i18n (1.14.1)
19
+ concurrent-ruby (~> 1.0)
20
+ json (2.6.3)
21
+ language_server-protocol (3.17.0.3)
22
+ parallel (1.23.0)
23
+ parser (3.2.2.3)
24
+ ast (~> 2.4.1)
25
+ racc
26
+ public_suffix (5.0.1)
27
+ racc (1.7.1)
28
+ rainbow (3.1.1)
29
+ rake (13.0.6)
30
+ regexp_parser (2.8.1)
31
+ rexml (3.2.5)
32
+ rspec (3.12.0)
33
+ rspec-core (~> 3.12.0)
34
+ rspec-expectations (~> 3.12.0)
35
+ rspec-mocks (~> 3.12.0)
36
+ rspec-core (3.12.2)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-expectations (3.12.3)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-mocks (3.12.5)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.1)
45
+ rubocop (1.54.1)
46
+ json (~> 2.3)
47
+ language_server-protocol (>= 3.17.0)
48
+ parallel (~> 1.10)
49
+ parser (>= 3.2.2.3)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8, < 3.0)
52
+ rexml (>= 3.2.5, < 4.0)
53
+ rubocop-ast (>= 1.28.0, < 2.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 2.4.0, < 3.0)
56
+ rubocop-ast (1.29.0)
57
+ parser (>= 3.2.1.0)
58
+ ruby-progressbar (1.13.0)
59
+ unicode-display_width (2.4.2)
60
+ webmock (2.3.2)
61
+ addressable (>= 2.3.6)
62
+ crack (>= 0.3.2)
63
+ hashdiff
64
+
65
+ PLATFORMS
66
+ x86_64-darwin-21
67
+ x86_64-linux
68
+
69
+ DEPENDENCIES
70
+ google_reviews!
71
+ rake (~> 13.0)
72
+ rspec (~> 3.0)
73
+ rubocop (~> 1.21)
74
+ webmock (~> 2.0)
75
+
76
+ BUNDLED WITH
77
+ 2.3.26
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 gullariz12
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,62 @@
1
+ # Google Reviews Gem
2
+
3
+ The Google Reviews gem is a Ruby library that provides a service to fetch reviews from Google based on a place name or place ID. It utilizes the Google Places API to retrieve the reviews and provides a convenient interface for accessing the review data.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile:
8
+
9
+ ```
10
+ gem 'google_reviews'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it directly:
20
+
21
+ ```
22
+ $ gem install google_reviews
23
+ ```
24
+ ## Usage
25
+ To fetch reviews based on a place name or place ID, you can use the `GoogleReviews::Reviews` class provided by the gem. Here's an example of how to use it:
26
+
27
+ ```
28
+ require 'google_reviews'
29
+
30
+ api_key = 'YOUR_API_KEY'
31
+ place_id = 'PLACE_ID'
32
+
33
+ reviews = GoogleReviews::Reviews.fetch_reviews_by_place_id(api_key, place_id)
34
+
35
+ reviews.each do |review|
36
+ puts "Author: #{review[:author_name]}"
37
+ puts "Rating: #{review[:rating]}"
38
+ puts "Review Text: #{review[:text]}"
39
+ puts "---"
40
+ end
41
+ ```
42
+
43
+ Make sure to replace `YOUR_API_KEY` with your actual Google Places API key.
44
+
45
+ ## Error Handling
46
+
47
+ The gem provides custom error classes that you can handle to deal with specific error scenarios. Here are the error classes available:
48
+
49
+ - `GoogleReviews::ApiError:` Represents general API-related errors.
50
+ - `GoogleReviews::InvalidApiKeyError:` Indicates an invalid API key error.
51
+ - `GoogleReviews::InvalidPlaceIdError:` Indicates an invalid place ID error.
52
+ You can rescue and handle these errors to provide appropriate error handling in your application.
53
+
54
+ ## Configuration
55
+ The gem doesn't require any additional configuration. However, it's recommended to configure the locale for translations. By default, the gem uses English (`:en`) as the locale. If you want to use a different locale, you can modify the `lib/google_reviews/translations.rb file`.
56
+
57
+ ## License
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gullariz12/google_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/gullariz12/google_reviews/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # GoogleReviews module
4
+ module GoogleReviews
5
+ # Make API request to fetch google reviews
6
+ module ApiRequest
7
+ def execute(url)
8
+ http_request = build_request(url)
9
+ request_client = build_http_client(url)
10
+
11
+ response = request_client.request(http_request)
12
+
13
+ raise ApiError, error_message unless response.is_a?(Net::HTTPSuccess)
14
+
15
+ parsed_response(response)
16
+ rescue StandardError => e
17
+ raise ApiError, I18n.t("messages.api_request_error", exception: e)
18
+ end
19
+
20
+ private
21
+
22
+ def build_http_client(url)
23
+ uri = URI(url)
24
+ https = Net::HTTP.new(uri.host, uri.port)
25
+ https.use_ssl = true
26
+
27
+ https
28
+ end
29
+
30
+ def build_request(url)
31
+ uri = URI(url)
32
+
33
+ Net::HTTP::Get.new(uri.request_uri)
34
+ end
35
+
36
+ def parsed_response(response)
37
+ JSON.parse(response.body)
38
+ rescue JSON::ParserError
39
+ raise ApiError, I18n.t("messages.parser_error")
40
+ end
41
+
42
+ def error_message(response)
43
+ I18n.t("messages.failed_request", code: response.code, message: response.message)
44
+ end
45
+
46
+ module_function :execute, :build_request, :build_http_client, :parsed_response, :error_message
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ PLACE_ID_SEARCH_BASE_URI = "https://maps.googleapis.com/maps/api/place/details/json"
4
+ PLACE_TEXT_SEARCH_BASE_URI = "https://maps.googleapis.com/maps/api/place/textsearch/json"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleReviews
4
+ class Error < StandardError; end
5
+
6
+ class ApiError < Error; end
7
+ class InvalidApiKeyError < ApiError; end
8
+ class InvalidPlaceIdError < ApiError; end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+
5
+ # Load Translations
6
+ module Translations
7
+ translations_file = File.expand_path("../../locales/en.yml", __dir__)
8
+ I18n.load_path << translations_file
9
+ I18n.backend.load_translations
10
+ I18n.locale = :en
11
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # GoogleReviews module
4
+ module GoogleReviews
5
+ # Various utility methods
6
+ module Utils
7
+ def request_uri(api_key, place_id: nil, place_name: nil)
8
+ if place_id
9
+ "#{PLACE_ID_SEARCH_BASE_URI}?place_id=#{place_id}&fields=reviews&key=#{api_key}"
10
+ elsif place_name
11
+ "#{PLACE_TEXT_SEARCH_BASE_URI}?query=#{encoded_place_name(place_name)}&key=#{api_key}"
12
+ end
13
+ end
14
+
15
+ def formatted_reviews_data(reviews)
16
+ reviews.map do |review|
17
+ {
18
+ author_name: review["author_name"],
19
+ rating: review["rating"],
20
+ text: review["text"]
21
+ }
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def encoded_place_name(place_name)
28
+ URI.encode_www_form_component(place_name)
29
+ end
30
+
31
+ module_function :request_uri, :formatted_reviews_data, :encoded_place_name
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleReviews
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "json"
5
+ require "net/http"
6
+ require "google_reviews/error"
7
+ require "google_reviews/utils"
8
+ require "google_reviews/constants"
9
+ require "google_reviews/api_request"
10
+ require "google_reviews/translations"
11
+ require_relative "google_reviews/version"
12
+
13
+ module GoogleReviews
14
+ # Service to fetch reviews based on place_name or place_id
15
+ class Reviews
16
+ def self.fetch_reviews_by_place_name(api_key, place_name)
17
+ url = Utils.request_uri(api_key, place_name: place_name)
18
+
19
+ data = ApiRequest.execute(url)
20
+
21
+ raise ApiError, I18n.t("messages.search_place_api_error", exception: data["status"]) unless data["status"] == "OK"
22
+
23
+ place_id = data["results"].first["place_id"]
24
+ fetch_reviews_by_place_id(api_key, place_id)
25
+ end
26
+
27
+ def self.fetch_reviews_by_place_id(api_key, place_id)
28
+ url = Utils.request_uri(api_key, place_id: place_id)
29
+
30
+ data = ApiRequest.execute(url)
31
+
32
+ raise ApiError, I18n.t("messages.search_id_api_error", exception: data["status"]) unless data["status"] == "OK"
33
+
34
+ reviews = data["result"]["reviews"]
35
+ return [] if reviews.nil? || reviews.empty?
36
+
37
+ Utils.formatted_reviews_data(reviews)
38
+ end
39
+ end
40
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,7 @@
1
+ en:
2
+ messages:
3
+ parser_error: "Failed to parse the API response"
4
+ failed_request: "API request failed: %{code} %{message}"
5
+ api_request_error: "An error occurred while making the API request: %{exception}"
6
+ search_place_api_error: "An error occurred while searching for the place: %{exception}"
7
+ search_id_api_error: "An error occurred while retrieving reviews from the Google Places API: %{exception}"
@@ -0,0 +1,4 @@
1
+ module GoogleReviews
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_reviews
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - gullariz12
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
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: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: " Google Reviews Gem is a Ruby gem that provides an easy-to-use interface
42
+ for fetching reviews for a specific location from the Google Places API. It allows
43
+ you to retrieve reviews written by users for a given place and provides useful information
44
+ such as the author's name, rating, and review text.\n"
45
+ email:
46
+ - gullariz82@gmail.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - CHANGELOG.md
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/google_reviews.rb
61
+ - lib/google_reviews/api_request.rb
62
+ - lib/google_reviews/constants.rb
63
+ - lib/google_reviews/error.rb
64
+ - lib/google_reviews/translations.rb
65
+ - lib/google_reviews/utils.rb
66
+ - lib/google_reviews/version.rb
67
+ - locales/en.yml
68
+ - sig/google_reviews.rbs
69
+ homepage: https://github.com/gullariz12/google_reviews
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ allowed_push_host: https://rubygems.org
74
+ homepage_uri: https://github.com/gullariz12/google_reviews
75
+ source_code_uri: https://github.com/gullariz12/google_reviews
76
+ changelog_uri: https://github.com/gullariz12/google_reviews/blob/main/CHANGELOG.md
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.3.7
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A gem for retrieving reviews for a specific location from the Google Places
96
+ API
97
+ test_files: []