Class: Vonage::ProactiveConnect::Items
- Inherits:
-
Namespace
- Object
- Namespace
- Vonage::ProactiveConnect::Items
- Extended by:
- T::Sig
- Defined in:
- lib/vonage/proactive_connect/items.rb
Defined Under Namespace
Classes: FileResponse, ListResponse
Instance Method Summary collapse
-
#download_csv(list_id:, order: 'asc', **params) ⇒ Object
Download list items as a CSV file format.
-
#list(list_id:, **params) ⇒ Object
Find all list items.
-
#upload_csv(list_id:, filepath:) ⇒ Object
Import list items from a CSV file.
Instance Method Details
#download_csv(list_id:, order: 'asc', **params) ⇒ Object
Download list items as a CSV file format
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
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
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 |