Class: Merge::Accounting::AsyncLinkTokenClient

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/accounting/link_token/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Merge::Accounting::AsyncLinkTokenClient

Parameters:



104
105
106
# File 'lib/merge_ruby_client/accounting/link_token/client.rb', line 104

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientMerge::AsyncRequestClient (readonly)



100
101
102
# File 'lib/merge_ruby_client/accounting/link_token/client.rb', line 100

def request_client
  @request_client
end

Instance Method Details

#create(end_user_email_address:, end_user_organization_name:, end_user_origin_id:, categories:, integration: nil, link_expiry_mins: nil, should_create_magic_link_url: nil, common_models: nil, category_common_model_scopes: nil, language: nil, integration_specific_config: nil, request_options: nil) ⇒ Merge::Accounting::LinkToken

Creates a link token to be used when linking a new end user.

Examples:

api = Merge::Client.new(
  base_url: "https://api.example.com",
  environment: Merge::Environment::PRODUCTION,
  api_key: "YOUR_AUTH_TOKEN"
)
api.accounting.link_token.create(
  end_user_email_address: "[email protected]",
  end_user_organization_name: "Test Organization",
  end_user_origin_id: "12345",
  categories: [HRIS, ATS]
)

Parameters:

  • end_user_email_address (String)

    Your end user’s email address. This is purely for identification purposes - setting this value will not cause any emails to be sent.

  • end_user_organization_name (String)

    Your end user’s organization.

  • end_user_origin_id (String)

    This unique identifier typically represents the ID for your end user in your product’s database. This value must be distinct from other Linked Accounts’ unique identifiers.

  • categories (Array<Merge::Accounting::CategoriesEnum>)

    The integration categories to show in Merge Link.

  • integration (String) (defaults to: nil)

    The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see docs.merge.dev/guides/merge-link/single-integration/.

  • link_expiry_mins (Integer) (defaults to: nil)

    An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30.

  • should_create_magic_link_url (Boolean) (defaults to: nil)

    Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see merge.dev/blog/integrations-fast-say-hello-to-magic-link.

  • common_models (Array<Hash>) (defaults to: nil)

    An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account.Request of type Array<Merge::Accounting::CommonModelScopesBodyRequest>, as a Hash

    * :model_id (String)
    * :enabled_actions (Array<Merge::Accounting::EnabledActionsEnum>)
    * :disabled_fields (Array<String>)
    
  • category_common_model_scopes (Hash{String => Array}) (defaults to: nil)

    When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings.

  • language (String) (defaults to: nil)

    The language code for the language to localize Merge Link to.

  • integration_specific_config (Hash{String => Object}) (defaults to: nil)

    A JSON object containing integration-specific configuration options.

  • request_options (Merge::RequestOptions) (defaults to: nil)

Returns:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/merge_ruby_client/accounting/link_token/client.rb', line 151

def create(end_user_email_address:, end_user_organization_name:, end_user_origin_id:, categories:,
           integration: nil, link_expiry_mins: nil, should_create_magic_link_url: nil, common_models: nil, category_common_model_scopes: nil, language: nil, integration_specific_config: nil, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["X-Account-Token"] = request_options. unless request_options&..nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        end_user_email_address: end_user_email_address,
        end_user_organization_name: end_user_organization_name,
        end_user_origin_id: end_user_origin_id,
        categories: categories,
        integration: integration,
        link_expiry_mins: link_expiry_mins,
        should_create_magic_link_url: should_create_magic_link_url,
        common_models: common_models,
        category_common_model_scopes: category_common_model_scopes,
        language: language,
        integration_specific_config: integration_specific_config
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/accounting/v1/link-token"
    end
    Merge::Accounting::LinkToken.from_json(json_object: response.body)
  end
end