=begin
#Pinterest REST API
#Pinterest's REST API
The version of the OpenAPI document: 5.3.0
Contact: blah@cliffano.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 5.4.0
=end
require 'cgi'
module PinterestSdkClient
class PinsApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Get Pin analytics
# Get analytics for a Pin owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account. Optional: Business Access: Specify an ad_account_id
(obtained via List ad accounts) to use the owner of that ad_account as the \"operation user_account\". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: - For Pins on public or protected boards: Admin, Analyst. - For Pins on secret boards: Admin.
# @param pin_id [String] Unique identifier of a Pin.
# @param start_date [Date] Metric report start date (UTC). Format: YYYY-MM-DD
# @param end_date [Date] Metric report end date (UTC). Format: YYYY-MM-DD
# @param metric_types [Array] Pin metric types to get data for, default is all.
# @param [Hash] opts the optional parameters
# @option opts [String] :app_types Apps or devices to get data for, default is all. (default to 'ALL')
# @option opts [String] :split_field How to split the data into groups. Not including this param means data won't be split. (default to 'NO_SPLIT')
# @option opts [String] :ad_account_id Unique identifier of an ad account.
# @return [Hash]
def pins_analytics(pin_id, start_date, end_date, metric_types, opts = {})
data, _status_code, _headers = pins_analytics_with_http_info(pin_id, start_date, end_date, metric_types, opts)
data
end
# Get Pin analytics
# Get analytics for a Pin owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account. Optional: Business Access: Specify an <code>ad_account_id</code> (obtained via <a href=\"https://developers.pinterest.com/docs/api/v5/#operation/ad_accounts/list\">List ad accounts</a>) to use the owner of that ad_account as the \"operation user_account\". In order to do this, the token user_account must have one of the following <a href=\"https://help.pinterest.com/en/business/article/share-and-manage-access-to-your-ad-accounts\">Business Access</a> roles on the ad_account: - For Pins on public or protected boards: Admin, Analyst. - For Pins on secret boards: Admin.
# @param pin_id [String] Unique identifier of a Pin.
# @param start_date [Date] Metric report start date (UTC). Format: YYYY-MM-DD
# @param end_date [Date] Metric report end date (UTC). Format: YYYY-MM-DD
# @param metric_types [Array] Pin metric types to get data for, default is all.
# @param [Hash] opts the optional parameters
# @option opts [String] :app_types Apps or devices to get data for, default is all.
# @option opts [String] :split_field How to split the data into groups. Not including this param means data won't be split.
# @option opts [String] :ad_account_id Unique identifier of an ad account.
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def pins_analytics_with_http_info(pin_id, start_date, end_date, metric_types, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: PinsApi.pins_analytics ...'
end
# verify the required parameter 'pin_id' is set
if @api_client.config.client_side_validation && pin_id.nil?
fail ArgumentError, "Missing the required parameter 'pin_id' when calling PinsApi.pins_analytics"
end
# verify the required parameter 'start_date' is set
if @api_client.config.client_side_validation && start_date.nil?
fail ArgumentError, "Missing the required parameter 'start_date' when calling PinsApi.pins_analytics"
end
# verify the required parameter 'end_date' is set
if @api_client.config.client_side_validation && end_date.nil?
fail ArgumentError, "Missing the required parameter 'end_date' when calling PinsApi.pins_analytics"
end
# verify the required parameter 'metric_types' is set
if @api_client.config.client_side_validation && metric_types.nil?
fail ArgumentError, "Missing the required parameter 'metric_types' when calling PinsApi.pins_analytics"
end
allowable_values = ["ALL", "MOBILE", "TABLET", "WEB"]
if @api_client.config.client_side_validation && opts[:'app_types'] && !allowable_values.include?(opts[:'app_types'])
fail ArgumentError, "invalid value for \"app_types\", must be one of #{allowable_values}"
end
allowable_values = ["NO_SPLIT", "APP_TYPE"]
if @api_client.config.client_side_validation && opts[:'split_field'] && !allowable_values.include?(opts[:'split_field'])
fail ArgumentError, "invalid value for \"split_field\", must be one of #{allowable_values}"
end
pattern = Regexp.new(/^\d+$/)
if @api_client.config.client_side_validation && !opts[:'ad_account_id'].nil? && opts[:'ad_account_id'] !~ pattern
fail ArgumentError, "invalid value for 'opts[:\"ad_account_id\"]' when calling PinsApi.pins_analytics, must conform to the pattern #{pattern}."
end
# resource path
local_var_path = '/pins/{pin_id}/analytics'.sub('{' + 'pin_id' + '}', CGI.escape(pin_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'start_date'] = start_date
query_params[:'end_date'] = end_date
query_params[:'metric_types'] = @api_client.build_collection_param(metric_types, :csv)
query_params[:'app_types'] = opts[:'app_types'] if !opts[:'app_types'].nil?
query_params[:'split_field'] = opts[:'split_field'] if !opts[:'split_field'].nil?
query_params[:'ad_account_id'] = opts[:'ad_account_id'] if !opts[:'ad_account_id'].nil?
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/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] || ['pinterest_oauth2']
new_options = opts.merge(
:operation => :"PinsApi.pins_analytics",
: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: PinsApi#pins_analytics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Create Pin
# Create a Pin on a board or board section owned by the \"operation user_account\". Note: If the current \"operation user_account\" (defined by the access token) has access to another user's Ad Accounts via Pinterest Business Access, you can modify your request to make use of the current operation_user_account's permissions to those Ad Accounts by including the ad_account_id in the path parameters for the request (e.g. .../?ad_account_id=12345&...). - This function is intended solely for publishing new content created by the user. If you are interested in saving content created by others to your Pinterest boards, sometimes called 'curated content', please use our Save button instead. For more tips on creating fresh content for Pinterest, review our Content App Solutions Guide. Learn more about video Pin creation.
# @param pin [Pin] Create a new Pin.
# @param [Hash] opts the optional parameters
# @return [Pin]
def pins_create(pin, opts = {})
data, _status_code, _headers = pins_create_with_http_info(pin, opts)
data
end
# Create Pin
# Create a Pin on a board or board section owned by the \"operation user_account\". Note: If the current \"operation user_account\" (defined by the access token) has access to another user's Ad Accounts via Pinterest Business Access, you can modify your request to make use of the current operation_user_account's permissions to those Ad Accounts by including the ad_account_id in the path parameters for the request (e.g. .../?ad_account_id=12345&...). - This function is intended solely for publishing new content created by the user. If you are interested in saving content created by others to your Pinterest boards, sometimes called 'curated content', please use our <a href='/docs/add-ons/save-button'>Save button</a> instead. For more tips on creating fresh content for Pinterest, review our <a href='/docs/solutions/content-apps'>Content App Solutions Guide</a>. <strong><a href='/docs/solutions/content-apps/#creatingvideopins'>Learn more</a></strong> about video Pin creation.
# @param pin [Pin] Create a new Pin.
# @param [Hash] opts the optional parameters
# @return [Array<(Pin, Integer, Hash)>] Pin data, response status code and response headers
def pins_create_with_http_info(pin, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: PinsApi.pins_create ...'
end
# verify the required parameter 'pin' is set
if @api_client.config.client_side_validation && pin.nil?
fail ArgumentError, "Missing the required parameter 'pin' when calling PinsApi.pins_create"
end
# resource path
local_var_path = '/pins'
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/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(pin)
# return_type
return_type = opts[:debug_return_type] || 'Pin'
# auth_names
auth_names = opts[:debug_auth_names] || ['pinterest_oauth2']
new_options = opts.merge(
:operation => :"PinsApi.pins_create",
: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(:POST, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: PinsApi#pins_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Delete Pin
# Delete a Pins owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account.
# @param pin_id [String] Unique identifier of a Pin.
# @param [Hash] opts the optional parameters
# @return [nil]
def pins_delete(pin_id, opts = {})
pins_delete_with_http_info(pin_id, opts)
nil
end
# Delete Pin
# Delete a Pins owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account.
# @param pin_id [String] Unique identifier of a Pin.
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def pins_delete_with_http_info(pin_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: PinsApi.pins_delete ...'
end
# verify the required parameter 'pin_id' is set
if @api_client.config.client_side_validation && pin_id.nil?
fail ArgumentError, "Missing the required parameter 'pin_id' when calling PinsApi.pins_delete"
end
# resource path
local_var_path = '/pins/{pin_id}'.sub('{' + 'pin_id' + '}', CGI.escape(pin_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type]
# auth_names
auth_names = opts[:debug_auth_names] || ['pinterest_oauth2']
new_options = opts.merge(
:operation => :"PinsApi.pins_delete",
: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(:DELETE, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: PinsApi#pins_delete\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Pin
# Get a Pin owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account. Optional: Business Access: Specify an ad_account_id
(obtained via List ad accounts) to use the owner of that ad_account as the \"operation user_account\". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: - For Pins on public or protected boards: Owner, Admin, Analyst, Campaign Manager. - For Pins on secret boards: Owner, Admin.
# @param pin_id [String] Unique identifier of a Pin.
# @param [Hash] opts the optional parameters
# @option opts [String] :ad_account_id Unique identifier of an ad account.
# @return [Pin]
def pins_get(pin_id, opts = {})
data, _status_code, _headers = pins_get_with_http_info(pin_id, opts)
data
end
# Get Pin
# Get a Pin owned by the \"operation user_account\" - or on a group board that has been shared with this account. - By default, the \"operation user_account\" is the token user_account. Optional: Business Access: Specify an <code>ad_account_id</code> (obtained via <a href='/docs/api/v5/#operation/ad_accounts/list'>List ad accounts</a>) to use the owner of that ad_account as the \"operation user_account\". In order to do this, the token user_account must have one of the following <a href=\"https://help.pinterest.com/en/business/article/share-and-manage-access-to-your-ad-accounts\">Business Access</a> roles on the ad_account: - For Pins on public or protected boards: Owner, Admin, Analyst, Campaign Manager. - For Pins on secret boards: Owner, Admin.
# @param pin_id [String] Unique identifier of a Pin.
# @param [Hash] opts the optional parameters
# @option opts [String] :ad_account_id Unique identifier of an ad account.
# @return [Array<(Pin, Integer, Hash)>] Pin data, response status code and response headers
def pins_get_with_http_info(pin_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: PinsApi.pins_get ...'
end
# verify the required parameter 'pin_id' is set
if @api_client.config.client_side_validation && pin_id.nil?
fail ArgumentError, "Missing the required parameter 'pin_id' when calling PinsApi.pins_get"
end
pattern = Regexp.new(/^\d+$/)
if @api_client.config.client_side_validation && !opts[:'ad_account_id'].nil? && opts[:'ad_account_id'] !~ pattern
fail ArgumentError, "invalid value for 'opts[:\"ad_account_id\"]' when calling PinsApi.pins_get, must conform to the pattern #{pattern}."
end
# resource path
local_var_path = '/pins/{pin_id}'.sub('{' + 'pin_id' + '}', CGI.escape(pin_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'ad_account_id'] = opts[:'ad_account_id'] if !opts[:'ad_account_id'].nil?
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Pin'
# auth_names
auth_names = opts[:debug_auth_names] || ['pinterest_oauth2']
new_options = opts.merge(
:operation => :"PinsApi.pins_get",
: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: PinsApi#pins_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end