google_reviews 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 231e90d72dc86d146d4984725b9860fa6fe711a981cab4b1243c71e4ef432b93
4
- data.tar.gz: d1bbf7d14bd4e7cfc696b259df887846fe4307a7c699542271045e8764c80979
3
+ metadata.gz: 18e5a9dff07ce24f915090ed258356c3652f70aadb44942115d14b8e49504373
4
+ data.tar.gz: 28a08e8dee6488b27985aee1239646fd4625444db814638305e57f083e19831a
5
5
  SHA512:
6
- metadata.gz: 2f0ec4a36b6fbfd5ede619e3ec9d1720d69f3a95f7df799533a4953cde8a3d265e8d3437d5782816e5e4307e04f25d74d1f79d53ad42bb73901062d1a0c18065
7
- data.tar.gz: 37b030b38eacee137834924955f92616b13db1f903269e471d55c725ee684d174f16c26ee655d8926f8741c7f3db99b7bacbafb27c6e176ad6d5932760f3b67f
6
+ metadata.gz: 99ebab61a5641a91e3994cba74e10efb991646624e9ed0d1151c83b1fe51b25369134328ab1e2a3aaf3e70573f48c108c0e5db979ccd58b647ecfcc5cdc55d66
7
+ data.tar.gz: 619febead0a09e3cede3bbbffef2270b6b86316e1a41700511d00b9977e21354bfd76dbaf0079961e25df8f88d46361fb005ef2420d7f63bf3e83f03c8db2d9c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-07-03
3
+ ## [1.0.0] - 2023-07-03
4
4
 
5
5
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_reviews (0.1.0)
4
+ google_reviews (1.0.1)
5
5
  i18n
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -54,9 +54,13 @@ You can rescue and handle these errors to provide appropriate error handling in
54
54
  ## Configuration
55
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
56
 
57
- ## License
58
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
+ ## Submitting a Pull Request
59
58
 
60
- ## Contributing
59
+ [Fork](https://help.github.com/articles/fork-a-repo/) the [official repository](https://github.com/TheArtOfCoding/google_reviews).
60
+ [Create a topic branch.](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/)
61
+ Implement your feature or bug fix.
62
+ Add, commit, and push your changes.
63
+ [Submit a pull request.](https://help.github.com/articles/using-pull-requests/)
61
64
 
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).
65
+ ## License
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleReviews
4
+ # Response Object
5
+ class Response
6
+ attr_reader :status, :data, :error_message
7
+
8
+ def initialize(data: [], status: "OK", error: "")
9
+ @data = data
10
+ @status = status
11
+ @error = error
12
+ end
13
+
14
+ def success?
15
+ status == "OK"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleReviews
4
+ # Google Review Object
5
+ class Review
6
+ attr_accessor :text, :time, :rating, :language, :author_url, :translated, :author_name,
7
+ :original_language, :profile_photo_url, :relative_time_description
8
+
9
+ def initialize(data)
10
+ @text = data["text"]
11
+ @time = data["time"]
12
+ @rating = data["rating"]
13
+ @language = data["language"]
14
+ @author_url = data["author_url"]
15
+ @translated = data["translated"]
16
+ @author_name = data["author_name"]
17
+ @original_language = data["original_language"]
18
+ @profile_photo_url = data["profile_photo_url"]
19
+ @relative_time_description = data["relative_time_description"]
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "google_reviews/review"
4
+
3
5
  # GoogleReviews module
4
6
  module GoogleReviews
5
7
  # Various utility methods
@@ -13,21 +15,40 @@ module GoogleReviews
13
15
  end
14
16
 
15
17
  def formatted_reviews_data(reviews)
18
+ return [] if reviews.nil? || reviews.empty?
19
+
16
20
  reviews.map do |review|
17
- {
18
- author_name: review["author_name"],
19
- rating: review["rating"],
20
- text: review["text"]
21
- }
21
+ Review.new(review)
22
22
  end
23
23
  end
24
24
 
25
+ def execute_place_name_request(url)
26
+ data = ApiRequest.execute(url)
27
+
28
+ raise ApiError, I18n.t("messages.search_place_api_error", exception: data["status"]) unless data["status"] == "OK"
29
+
30
+ data["results"]
31
+ end
32
+
33
+ def execute_place_id_request(url)
34
+ data = ApiRequest.execute(url)
35
+
36
+ error = I18n.t("messages.search_id_api_error", exception: data["status"])
37
+ return GoogleReviews::Response.new(status: data["status"], error: error) unless data["status"] == "OK"
38
+
39
+ reviews = data["result"]["reviews"]
40
+ return GoogleReviews::Response.new if reviews.nil? || reviews.empty?
41
+
42
+ GoogleReviews::Response.new(data: formatted_reviews_data(reviews))
43
+ end
44
+
25
45
  private
26
46
 
27
47
  def encoded_place_name(place_name)
28
48
  URI.encode_www_form_component(place_name)
29
49
  end
30
50
 
31
- module_function :request_uri, :formatted_reviews_data, :encoded_place_name
51
+ module_function :request_uri, :formatted_reviews_data, :encoded_place_name, :execute_place_id_request,
52
+ :execute_place_name_request
32
53
  end
33
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleReviews
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
@@ -5,6 +5,7 @@ require "json"
5
5
  require "net/http"
6
6
  require "google_reviews/error"
7
7
  require "google_reviews/utils"
8
+ require "google_reviews/response"
8
9
  require "google_reviews/constants"
9
10
  require "google_reviews/api_request"
10
11
  require "google_reviews/translations"
@@ -16,25 +17,24 @@ module GoogleReviews
16
17
  def self.fetch_reviews_by_place_name(api_key, place_name)
17
18
  url = Utils.request_uri(api_key, place_name: place_name)
18
19
 
19
- data = ApiRequest.execute(url)
20
+ begin
21
+ data = Utils.execute_place_name_request(url)
22
+ return GoogleReviews::Response.new unless data
20
23
 
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)
24
+ fetch_reviews_by_place_id(api_key, data.first["place_id"])
25
+ rescue ApiError => e
26
+ GoogleReviews::Response.new(status: "409", error: e)
27
+ end
25
28
  end
26
29
 
27
30
  def self.fetch_reviews_by_place_id(api_key, place_id)
28
31
  url = Utils.request_uri(api_key, place_id: place_id)
29
32
 
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)
33
+ begin
34
+ Utils.execute_place_id_request(url)
35
+ rescue ApiError => e
36
+ GoogleReviews::Response.new(status: "409", error: e)
37
+ end
38
38
  end
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_reviews
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gullariz12
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -61,6 +61,8 @@ files:
61
61
  - lib/google_reviews/api_request.rb
62
62
  - lib/google_reviews/constants.rb
63
63
  - lib/google_reviews/error.rb
64
+ - lib/google_reviews/response.rb
65
+ - lib/google_reviews/review.rb
64
66
  - lib/google_reviews/translations.rb
65
67
  - lib/google_reviews/utils.rb
66
68
  - lib/google_reviews/version.rb