Class: Vonage::ProactiveConnect::Items

Inherits:
Namespace
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/vonage/proactive_connect/items.rb

Defined Under Namespace

Classes: FileResponse, ListResponse

Instance Method Summary collapse

Instance Method Details

#download_csv(list_id:, order: 'asc', **params) ⇒ Object

Download list items as a CSV file format

Examples:

response = proactive_connect.items.download_csv(list_id: 'e546eebe-8e23-4e4d-bb7c-29d4700c9865')

Parameters:

  • :list_id (required, String)

    ID for the list to download

  • order (optional, String) (defaults to: 'asc')

    Sort in either ascending (asc, the default) or descending (desc) order

  • :filename (optional, String)

    A name to set for the returned File object. If not set, the File object will use the actual filename (if available) or a default of download.csv if the actual filename is not available.

  • :filepath (optional, String)

    A filepath to a directory where the file should be written. If not set, the file is not written, though the the file can be written at any time by calling save on the returned object and passing in :filepath as an argument to the save method, for example: response = proactive_connect.items.download_csv(list_id: 'e546eebe-8e23-4e4d-bb7c-29d4700c9865') response.save('/files/downloads/') If set, the filepath must be:

    • An absolute path
    • For a valid directory
    • The directory must be writable

See Also:



66
67
68
69
70
71
72
73
# File 'lib/vonage/proactive_connect/items.rb', line 66

def download_csv(list_id:, order: 'asc', **params)
  response = request("/v0.1/bulk/lists/#{list_id}/items/download?order=#{order}", response_class: FileResponse)

  response.filename = params[:filename] if params[:filename]
  response.save(filepath: params[:filepath]) if params[:filepath]

  response
end

#list(list_id:, **params) ⇒ Object

Find all list items

Examples:

response = proactive_connect.items.list(list_id: 'e546eebe-8e23-4e4d-bb7c-29d4700c9865')

Parameters:

  • :list_id (required, String)

    Unique identifier for the list

  • :page (optional, String)

    Page of results to jump to

  • :page_size (optional, String)

    Number of results per page

  • order (optional, String)

    Sort in either ascending (asc, the default) or descending (desc) order

See Also:



31
32
33
34
35
36
# File 'lib/vonage/proactive_connect/items.rb', line 31

def list(list_id:, **params)
  path = "/v0.1/bulk/lists/#{list_id}/items"
  path += "?#{Params.encode(params)}" unless params.empty?

  request(path, response_class: ListResponse)
end

#upload_csv(list_id:, filepath:) ⇒ Object

Import list items from a CSV file

Examples:

response = proactive_connect.items.upload_csv(list_id: 'e546eebe-8e23-4e4d-bb7c-29d4700c9865', filepath: '/files/import.csv')

Parameters:

  • :list_id (required, String)

    ID for the list to download

  • order (optional, String)

    Sort in either ascending (asc, the default) or descending (desc) order

  • :filename (optional, String)

    A name to set for the returned File object. If not set, the File object will use the actual filename (if available) or a default of download.csv if the actual filename is not available.

  • :filepath (required, String)

    A filepath for the file to import. The file must be:

    • A valid file
    • Readable
    • Must have a .csv extension

Raises:

  • (ArgumentError)

See Also:



98
99
100
101
102
103
104
105
# File 'lib/vonage/proactive_connect/items.rb', line 98

def upload_csv(list_id:, filepath:)
  pn = Pathname.new(filepath)
  raise ArgumentError, ':filepath not for a file' unless pn.file?
  raise ArgumentError, 'file at :filepath not readable' unless pn.readable?
  raise ArgumentError, 'file at :filepath not csv' unless pn.extname == '.csv'

  multipart_post_request("/v0.1/bulk/lists/#{list_id}/items/import", filepath: filepath, file_name: pn.basename, mime_type: 'text/csv')
end