Module: Api::ReviewsIo::ReviewPayload
- Defined in:
- app/services/api/reviews_io/review_payload.rb
Overview
Interprets raw review hashes from the Reviews.io HTTP API so we can mirror
dashboard visibility (e.g. deleted / unpublished) without removing rows locally.
Constant Summary collapse
- UNPUBLISHED_STATUSES =
%w[ deleted removed unpublished rejected declined hidden moderated_rejected moderation_rejected ].freeze
Class Method Summary collapse
- .deleted_flags?(data) ⇒ Boolean
- .explicitly_unpublished?(data) ⇒ Boolean
- .falsy_flag?(value) ⇒ Boolean
- .hidden_after_sync?(review_data, existing_record) ⇒ Boolean
- .status_fields_unpublished?(data) ⇒ Boolean
- .truthy_flag?(value) ⇒ Boolean
- .unpublished_code?(raw) ⇒ Boolean
-
.unpublished_on_source?(review_data) ⇒ Boolean
True when Reviews.io indicates the review must not appear on the public storefront.
Class Method Details
.deleted_flags?(data) ⇒ Boolean
36 37 38 39 40 |
# File 'app/services/api/reviews_io/review_payload.rb', line 36 def self.deleted_flags?(data) truthy_flag?(data['deleted']) || truthy_flag?(data['review_deleted']) || truthy_flag?(data['is_deleted']) end |
.explicitly_unpublished?(data) ⇒ Boolean
42 43 44 45 |
# File 'app/services/api/reviews_io/review_payload.rb', line 42 def self.explicitly_unpublished?(data) (data.key?('published') && falsy_flag?(data['published'])) || (data.key?('is_published') && falsy_flag?(data['is_published'])) end |
.falsy_flag?(value) ⇒ Boolean
65 66 67 68 69 |
# File 'app/services/api/reviews_io/review_payload.rb', line 65 def self.falsy_flag?(value) value == false || (value.is_a?(Numeric) && value.zero?) || value.to_s.downcase.in?(%w[0 false no]) end |
.hidden_after_sync?(review_data, existing_record) ⇒ Boolean
19 20 21 |
# File 'app/services/api/reviews_io/review_payload.rb', line 19 def self.hidden_after_sync?(review_data, existing_record) unpublished_on_source?(review_data) || existing_record&.hidden == true end |
.status_fields_unpublished?(data) ⇒ Boolean
47 48 49 50 51 |
# File 'app/services/api/reviews_io/review_payload.rb', line 47 def self.status_fields_unpublished?(data) %w[status review_status moderation_status visibility].any? do |key| unpublished_code?(data[key]) end end |
.truthy_flag?(value) ⇒ Boolean
59 60 61 62 63 |
# File 'app/services/api/reviews_io/review_payload.rb', line 59 def self.truthy_flag?(value) value == true || value == 1 || value.to_s.downcase.in?(%w[1 true yes]) end |
.unpublished_code?(raw) ⇒ Boolean
53 54 55 56 57 |
# File 'app/services/api/reviews_io/review_payload.rb', line 53 def self.unpublished_code?(raw) return false if raw.blank? UNPUBLISHED_STATUSES.include?(raw.to_s.strip.downcase) end |
.unpublished_on_source?(review_data) ⇒ Boolean
True when Reviews.io indicates the review must not appear on the public storefront.
The API shape varies by endpoint; we treat several common keys as "unpublished".
27 28 29 30 31 32 33 34 |
# File 'app/services/api/reviews_io/review_payload.rb', line 27 def self.unpublished_on_source?(review_data) return false if review_data.blank? || !review_data.is_a?(Hash) return true if deleted_flags?(review_data) return true if explicitly_unpublished?(review_data) status_fields_unpublished?(review_data) end |