Skip to content

Commit

Permalink
Add V3 endpoints for custom field values.
Browse files Browse the repository at this point in the history
  • Loading branch information
timchaston committed Jun 2, 2020
1 parent e11aa5b commit 9c36083
Show file tree
Hide file tree
Showing 14 changed files with 4,427 additions and 0 deletions.
77 changes: 77 additions & 0 deletions lib/active_campaign/api/field_values.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

module ActiveCampaign
module API
#
# Interface to custom field value endpoints
#
# @author Tim Chaston <timchaston@gmail.com>
#
module FieldValues
#
# Create a custom field value
#
# @param [Hash] params create a new custom field value with this data
# @param params [String] :contact ID of the contact whose field value you're updating
# @param params [String] :field ID of the custom field whose value you're updating for the contact
# @param params [String] :value Value for the field that you're updating. For multi-select options this needs to be in
# the format of ||option1||option2||
#
# @return [Hash] a hash with the information of the newly created field value and the contact it was created on
#
def create_field_value(params)
post('fieldValues', fieldValue: params)
end

#
# Retrieve a custom field value
#
# @param [Integer] id the id of the custom field value to show
#
# @return [Hash] a hash with the information of the custom field value
#
def show_field_value(id)
get("fieldValues/#{id}")
end

#
# Update a custom field value for contact
#
# @param [Integer] id the id of the custom field value to update
# @param [Hash] params update the custom field value with this data
# @param params [String] :contact the id of the contact whose field value you're updating
# @param params [String] :field the id of the custom field whose value you're updating for the contact
# @param params [String] :value the value for the field that you're updating
#
# @return [Hash] a hash with the information of the contact and the custom field value
#
def update_field_value(id, params)
put("fieldValues/#{id}", field_value: params)
end

#
# Delete a custom field value
#
# @param [Integer] id the id of the custom field value to delete
#
# @return [Hash] an empty hash
#
def delete_field_value(id)
delete("fieldValues/#{id}")
end

#
# List all custom field values
#
# @option [Hash] filters filter the list of custom field values with this data
# @option filter [String] :fieldid the id of the field the value belongs to
# @option filter [String] :val the value of the custom field for a specify contact
#
# @return [Hash] a hash with the information of field values that match the filters
def show_field_values(filters: {}, **params)
params[:filters] = filters if filters.any?
get('fieldValues', params)
end
end
end
end
1 change: 1 addition & 0 deletions lib/active_campaign/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Client
endpoint :pipelines
endpoint :users
endpoint :fields
endpoint :field_values

attr_reader :config

Expand Down
Loading

0 comments on commit 9c36083

Please sign in to comment.