Class: TiktokBusinessApi::Resources::Identity
- Inherits:
-
BaseResource
- Object
- BaseResource
- TiktokBusinessApi::Resources::Identity
- Defined in:
- lib/tiktok_business_api/resources/identity.rb
Overview
Identity resource for the TikTok Business API
Constant Summary collapse
- RESOURCE_NAME =
'identity'
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#create(advertiser_id:, display_name:, image_uri: nil) ⇒ Hash
Create a new Custom User identity.
-
#get_info(advertiser_id:, identity_id:, identity_type:, identity_authorized_bc_id: nil) ⇒ Hash
Get information about a specific identity.
-
#list(advertiser_id:, **options) ⇒ Hash
Get a list of identities.
-
#list_all(advertiser_id:, **options) {|identity| ... } ⇒ Array?
List all identities with automatic pagination.
Methods inherited from BaseResource
#_http_get, #_http_post, #api_version, #base_path, #initialize, #paginate, #resource_name
Constructor Details
This class inherits a constructor from TiktokBusinessApi::Resources::BaseResource
Instance Method Details
#create(advertiser_id:, display_name:, image_uri: nil) ⇒ Hash
Create a new Custom User identity
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tiktok_business_api/resources/identity.rb', line 68 def create(advertiser_id:, display_name:, image_uri: nil) params = { advertiser_id: advertiser_id, display_name: display_name } # Add image URI if provided params[:image_uri] = image_uri if image_uri response = client.request(:post, "#{base_path}create/", params) response['data'] end |
#get_info(advertiser_id:, identity_id:, identity_type:, identity_authorized_bc_id: nil) ⇒ Hash
Get information about a specific identity
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tiktok_business_api/resources/identity.rb', line 48 def get_info(advertiser_id:, identity_id:, identity_type:, identity_authorized_bc_id: nil) params = { advertiser_id: advertiser_id, identity_id: identity_id, identity_type: identity_type } # Add Business Center ID if provided (required for BC_AUTH_TT) params[:identity_authorized_bc_id] = if response = client.request(:get, "#{base_path}info/", params) response['data']['identity_info'] end |
#list(advertiser_id:, **options) ⇒ Hash
Get a list of identities
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tiktok_business_api/resources/identity.rb', line 19 def list(advertiser_id:, **) params = { advertiser_id: advertiser_id } # Add optional parameters if provided params[:identity_type] = [:identity_type] if [:identity_type] params[:identity_authorized_bc_id] = [:identity_authorized_bc_id] if [:identity_authorized_bc_id] params[:filtering] = [:filtering].to_json if [:filtering] params[:page] = [:page] if [:page] params[:page_size] = [:page_size] if [:page_size] response = client.request(:get, "#{base_path}get/", params) if block_given? && response['data']['identity_list'] response['data']['identity_list'].each { |identity| yield(identity) } response['data'] else response['data'] end end |
#list_all(advertiser_id:, **options) {|identity| ... } ⇒ Array?
List all identities with automatic pagination
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/tiktok_business_api/resources/identity.rb', line 88 def list_all(advertiser_id:, **, &block) page = [:page] || 1 page_size = [:page_size] || 100 all_identities = [] has_more = true while has_more = .merge(page: page, page_size: page_size) response = list(advertiser_id: advertiser_id, **) identities = response['identity_list'] || [] if block_given? identities.each { |identity| yield(identity) } else all_identities.concat(identities) end # Check pagination info page_info = response['page_info'] || {} current_page = page_info['page'].to_i total_pages = page_info['total_page'].to_i has_more = current_page < total_pages page += 1 # Break if empty result or no more pages break if identities.empty? || !has_more end block_given? ? nil : all_identities end |