Class: Dodopayments::Resources::Entitlements::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/dodopayments/resources/entitlements/files.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Files

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Files.

Parameters:



64
65
66
# File 'lib/dodopayments/resources/entitlements/files.rb', line 64

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(file_id, id:, request_options: {}) ⇒ nil

Companion to ‘post_entitlement_file`. Deletes the file from the Entitlements Engine (force=true) and atomically removes the `file_id` from the entitlement’s ‘integration_config.digital_file_ids` JSONB array. EE delete happens first; if it fails we surface the error and leave local state untouched.

Parameters:

  • file_id (String)

    Digital file Id from EE

  • id (String)

    Entitlement Id

  • request_options (Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dodopayments/resources/entitlements/files.rb', line 23

def delete(file_id, params)
  parsed, options = Dodopayments::Entitlements::FileDeleteParams.dump_request(params)
  id =
    parsed.delete(:id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["entitlements/%1$s/files/%2$s", id, file_id],
    model: NilClass,
    options: options
  )
end

#upload(id, request_options: {}) ⇒ Dodopayments::Models::Entitlements::FileUploadResponse

Streams a multipart/form-data body to the Entitlements Engine (‘POST /api/digital-files/dodo/files/upload`) and appends the returned `file_id` to the entitlement’s ‘integration_config.digital_file_ids` using a JSONB array append. Compensates EE-side on local DB write failure (best-effort delete of the just-uploaded file).

Parameters:

Returns:

See Also:



52
53
54
55
56
57
58
59
# File 'lib/dodopayments/resources/entitlements/files.rb', line 52

def upload(id, params = {})
  @client.request(
    method: :post,
    path: ["entitlements/%1$s/files", id],
    model: Dodopayments::Models::Entitlements::FileUploadResponse,
    options: params[:request_options]
  )
end