|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Resend |
| 4 | + # Module for managing contact properties |
| 5 | + # |
| 6 | + # Contact properties allow you to store custom data about your contacts |
| 7 | + module ContactProperties |
| 8 | + class << self |
| 9 | + # Create a custom property for your contacts |
| 10 | + # |
| 11 | + # @param params [Hash] Parameters for creating a contact property |
| 12 | + # @option params [String] :key The property key (max 50 characters, alphanumeric and underscores only) (required) |
| 13 | + # @option params [String] :type The property type ('string' or 'number') (required) |
| 14 | + # @option params [String, Integer] :fallback_value The default value when property is not set (must match type) |
| 15 | + # |
| 16 | + # @return [Hash] Response containing the created contact property |
| 17 | + # |
| 18 | + # @example Create a string property |
| 19 | + # Resend::ContactProperties.create({ |
| 20 | + # key: 'company_name', |
| 21 | + # type: 'string', |
| 22 | + # fallback_value: 'Acme Corp' |
| 23 | + # }) |
| 24 | + # |
| 25 | + # @example Create a number property |
| 26 | + # Resend::ContactProperties.create({ |
| 27 | + # key: 'age', |
| 28 | + # type: 'number', |
| 29 | + # fallback_value: 0 |
| 30 | + # }) |
| 31 | + def create(params) |
| 32 | + path = "contact-properties" |
| 33 | + Resend::Request.new(path, params, "post").perform |
| 34 | + end |
| 35 | + |
| 36 | + # Retrieve a contact property by its ID |
| 37 | + # |
| 38 | + # @param contact_property_id [String] The Contact Property ID |
| 39 | + # |
| 40 | + # @return [Hash] Response containing the contact property details |
| 41 | + # |
| 42 | + # @example Get a contact property |
| 43 | + # Resend::ContactProperties.get('b6d24b8e-af0b-4c3c-be0c-359bbd97381e') |
| 44 | + def get(contact_property_id = "") |
| 45 | + path = "contact-properties/#{contact_property_id}" |
| 46 | + Resend::Request.new(path, {}, "get").perform |
| 47 | + end |
| 48 | + |
| 49 | + # Retrieve a list of contact properties |
| 50 | + # |
| 51 | + # @param params [Hash] Optional query parameters |
| 52 | + # @option params [Integer] :limit Number of contact properties to retrieve (1-100, default: 20) |
| 53 | + # @option params [String] :after The ID after which to retrieve more contact properties |
| 54 | + # @option params [String] :before The ID before which to retrieve more contact properties |
| 55 | + # |
| 56 | + # @return [Hash] Response containing list of contact properties |
| 57 | + # |
| 58 | + # @example List all contact properties |
| 59 | + # Resend::ContactProperties.list |
| 60 | + # |
| 61 | + # @example List with pagination |
| 62 | + # Resend::ContactProperties.list({ limit: 10, after: 'cursor_123' }) |
| 63 | + def list(params = {}) |
| 64 | + path = Resend::PaginationHelper.build_paginated_path("contact-properties", params) |
| 65 | + Resend::Request.new(path, {}, "get").perform |
| 66 | + end |
| 67 | + |
| 68 | + # Update an existing contact property |
| 69 | + # |
| 70 | + # Note: The 'key' and 'type' fields cannot be changed after creation |
| 71 | + # |
| 72 | + # @param params [Hash] Parameters for updating a contact property |
| 73 | + # @option params [String] :id The Contact Property ID (required) |
| 74 | + # @option params [String, Integer] :fallback_value The default value when property is not set |
| 75 | + # (must match property type) |
| 76 | + # |
| 77 | + # @return [Hash] Response containing the updated contact property |
| 78 | + # |
| 79 | + # @example Update fallback value |
| 80 | + # Resend::ContactProperties.update({ |
| 81 | + # id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381e', |
| 82 | + # fallback_value: 'Example Company' |
| 83 | + # }) |
| 84 | + def update(params) |
| 85 | + contact_property_id = params[:id] |
| 86 | + path = "contact-properties/#{contact_property_id}" |
| 87 | + Resend::Request.new(path, params, "patch").perform |
| 88 | + end |
| 89 | + |
| 90 | + # Remove an existing contact property |
| 91 | + # |
| 92 | + # @param contact_property_id [String] The Contact Property ID |
| 93 | + # |
| 94 | + # @return [Hash] Response containing the deleted property ID and confirmation |
| 95 | + # |
| 96 | + # @example Delete a contact property |
| 97 | + # Resend::ContactProperties.remove('b6d24b8e-af0b-4c3c-be0c-359bbd97381e') |
| 98 | + def remove(contact_property_id = "") |
| 99 | + path = "contact-properties/#{contact_property_id}" |
| 100 | + Resend::Request.new(path, {}, "delete").perform |
| 101 | + end |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments