Class: Hubspot::Contact
- Defined in:
- lib/hubspot/contact.rb
Constant Summary
Constants inherited from Resource
Constants included from ResourceFilter::FilterGroupMethods
ResourceFilter::FilterGroupMethods::OPERATOR_MAP
Constants inherited from ApiClient
ApiClient::MAX_RETRIES, ApiClient::RETRY_WAIT_TIME
Instance Attribute Summary
Attributes inherited from Resource
#changes, #id, #metadata, #properties
Class Method Summary collapse
-
.find_by_token(token, properties: []) ⇒ Object
Finds a contact by the hubspotutk cookie.
Methods inherited from Resource
all, archive, batch_read, batch_read_all, #changes?, create, custom_properties, #delete, find, find!, find_by, find_by!, #initialize, #initialize_from_api, list, #method_missing, #persisted?, properties, property, read_only_properties, required_properties, #resource_name, resource_name, #respond_to_missing?, #save, #save!, search, select, updatable_properties, update, #update, #update_attributes, where
Methods included from ResourceFilter::FilterGroupMethods
#build_filter_groups, #extract_property_and_operator
Methods inherited from ApiClient
delete, get, #handle_response, handle_response, log_request, patch, post
Constructor Details
This class inherits a constructor from Hubspot::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hubspot::Resource
Class Method Details
.find_by_token(token, properties: []) ⇒ Object
Finds a contact by the hubspotutk cookie
token - the hubspot tracking token (stored from the hubspotutk cookie value) properties: - Optional list of properties to return.
Note: If properties are specified 2 calls to the api will be made because
at this time you can only search by the token using the v1 api
from which we
Example:
properties = %w[firstname lastname email last_contacted]
contact = Hubspot::Contact.find_by_token(, properties)
Returns An instance of the resource.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hubspot/contact.rb', line 29 def find_by_token(token, properties: []) all_properties = build_property_list(properties) query_props = all_properties.map { |prop| "property=#{prop}" } query_string = query_props.concat(['propertyMode=value_only']).join('&') # Make the original API request, manually appending the query string response = get("/contacts/v1/contact/utk/#{token}/profile?#{query_string}") # Only modify the response if it's successful (status 200 OK) if response.success? # Convert the v1 response body (parsed_response) to a v3 structure v3_response_hash = convert_v1_response(response.parsed_response, all_properties) # Modify the existing response object by updating its `parsed_response` response.instance_variable_set(:@parsed_response, v3_response_hash) end # Pass the (potentially modified) HTTParty response to the next step instantiate_from_response(response) end |