=begin
#Klaviyo API
#The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
The version of the OpenAPI document: 2025-01-15
Contact: developers@klaviyo.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.2.1
=end
require 'cgi'
module KlaviyoAPI
class ReviewsApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Get Review
# Get the review with the given ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `reviews:read`
# @param id [String] The ID of the review
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_event For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_review For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#relationships
# @return [Hash]
def get_review(id, opts = {})
data, _status_code, _headers = get_review_with_http_info(id, opts)
data
end
# Get Review
# Get the review with the given ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `reviews:read`
# @param id [String] The ID of the review
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_event For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_review For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#relationships
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_review_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ReviewsApi.get_review ...'
end
# verify the required parameter 'id' is set
if @api_client.config.client_side_validation && id.nil?
fail ArgumentError, "Missing the required parameter 'id' when calling ReviewsApi.get_review"
end
allowable_values = ["timestamp", "event_properties", "datetime", "uuid"]
if @api_client.config.client_side_validation && opts[:'fields_event'] && !opts[:'fields_event'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_event\", must include one of #{allowable_values}"
end
allowable_values = ["email", "status", "status.value", "status.rejection_reason", "status.rejection_reason.reason", "status.rejection_reason.status_explanation", "verified", "review_type", "created", "updated", "images", "product", "product.url", "product.name", "product.image_url", "product.external_id", "rating", "author", "content", "title", "smart_quote", "public_reply", "public_reply.content", "public_reply.author", "public_reply.updated"]
if @api_client.config.client_side_validation && opts[:'fields_review'] && !opts[:'fields_review'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_review\", must include one of #{allowable_values}"
end
allowable_values = ["events"]
if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/reviews/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[event]'] = @api_client.build_collection_param(opts[:'fields_event'], :csv) if !opts[:'fields_event'].nil?
query_params[:'fields[review]'] = @api_client.build_collection_param(opts[:'fields_review'], :csv) if !opts[:'fields_review'].nil?
query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-01-15"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']
new_options = opts.merge(
:operation => :"ReviewsApi.get_review",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: ReviewsApi#get_review\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Reviews
# Get all reviews.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `reviews:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_event For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_review For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`created`: `greater-or-equal`, `less-or-equal`<br>`rating`: `any`, `equals`, `greater-or-equal`, `less-or-equal`<br>`id`: `any`, `equals`<br>`item.id`: `any`, `equals`<br>`content`: `contains`<br>`status`: `equals`<br>`review_type`: `equals`<br>`verified`: `equals`
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#relationships
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#pagination
# @option opts [Integer] :page_size Default: 20. Min: 1. Max: 100. (default to 20)
# @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sorting
# @return [Hash]
def get_reviews(opts = {})
data, _status_code, _headers = get_reviews_with_http_info(opts)
data
end
# Get Reviews
# Get all reviews.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `reviews:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_event For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_review For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`created`: `greater-or-equal`, `less-or-equal`<br>`rating`: `any`, `equals`, `greater-or-equal`, `less-or-equal`<br>`id`: `any`, `equals`<br>`item.id`: `any`, `equals`<br>`content`: `contains`<br>`status`: `equals`<br>`review_type`: `equals`<br>`verified`: `equals`
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#relationships
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#pagination
# @option opts [Integer] :page_size Default: 20. Min: 1. Max: 100. (default to 20)
# @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sorting
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_reviews_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ReviewsApi.get_reviews ...'
end
allowable_values = ["timestamp", "event_properties", "datetime", "uuid"]
if @api_client.config.client_side_validation && opts[:'fields_event'] && !opts[:'fields_event'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_event\", must include one of #{allowable_values}"
end
allowable_values = ["email", "status", "status.value", "status.rejection_reason", "status.rejection_reason.reason", "status.rejection_reason.status_explanation", "verified", "review_type", "created", "updated", "images", "product", "product.url", "product.name", "product.image_url", "product.external_id", "rating", "author", "content", "title", "smart_quote", "public_reply", "public_reply.content", "public_reply.author", "public_reply.updated"]
if @api_client.config.client_side_validation && opts[:'fields_review'] && !opts[:'fields_review'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_review\", must include one of #{allowable_values}"
end
allowable_values = ["events"]
if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
end
if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 100
fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ReviewsApi.get_reviews, must be smaller than or equal to 100.'
end
if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1
fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ReviewsApi.get_reviews, must be greater than or equal to 1.'
end
allowable_values = ["created", "-created", "rating", "-rating", "updated", "-updated"]
if @api_client.config.client_side_validation && opts[:'sort'] && !allowable_values.include?(opts[:'sort'])
fail ArgumentError, "invalid value for \"sort\", must be one of #{allowable_values}"
end
# resource path
local_var_path = '/api/reviews'
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[event]'] = @api_client.build_collection_param(opts[:'fields_event'], :csv) if !opts[:'fields_event'].nil?
query_params[:'fields[review]'] = @api_client.build_collection_param(opts[:'fields_review'], :csv) if !opts[:'fields_review'].nil?
query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil?
query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?
query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?
query_params[:'page[size]'] = opts[:'page_size'] if !opts[:'page_size'].nil?
query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-01-15"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']
new_options = opts.merge(
:operation => :"ReviewsApi.get_reviews",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: ReviewsApi#get_reviews\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Update Review
# Update a review.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `reviews:write`
# @param id [String] The id of the review (review ID).
# @param review_patch_query [ReviewPatchQuery] DTO for updating reviews
# @param [Hash] opts the optional parameters
# @return [Hash]
def update_review(id, review_patch_query, opts = {})
data, _status_code, _headers = update_review_with_http_info(id, review_patch_query, opts)
data
end
# Update Review
# Update a review.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `reviews:write`
# @param id [String] The id of the review (review ID).
# @param review_patch_query [ReviewPatchQuery] DTO for updating reviews
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def update_review_with_http_info(id, review_patch_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ReviewsApi.update_review ...'
end
# verify the required parameter 'id' is set
if @api_client.config.client_side_validation && id.nil?
fail ArgumentError, "Missing the required parameter 'id' when calling ReviewsApi.update_review"
end
# verify the required parameter 'review_patch_query' is set
if @api_client.config.client_side_validation && review_patch_query.nil?
fail ArgumentError, "Missing the required parameter 'review_patch_query' when calling ReviewsApi.update_review"
end
# resource path
local_var_path = '/api/reviews/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-01-15"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/vnd.api+json'])
if !content_type.nil?
header_params['Content-Type'] = content_type
end
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body] || @api_client.object_to_http_body(review_patch_query)
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']
new_options = opts.merge(
:operation => :"ReviewsApi.update_review",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:PATCH, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: ReviewsApi#update_review\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end