Class: Vonage::ProactiveConnect::Items::FileResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/vonage/proactive_connect/items/file_response.rb

Overview

typed: true

Constant Summary collapse

DEFAULT_FILENAME =
'vonage-proactive-connect-list-items.csv'

Instance Attribute Summary collapse

Attributes inherited from Response

#entity, #http_response

Instance Method Summary collapse

Methods inherited from Response

#method_missing, #respond_to_missing?

Constructor Details

#initialize(entity = nil, http_response = nil) ⇒ FileResponse

Returns a new instance of FileResponse.



8
9
10
11
# File 'lib/vonage/proactive_connect/items/file_response.rb', line 8

def initialize(entity=nil, http_response=nil)
  super
  self.filename = initial_filename
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vonage::Response

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/vonage/proactive_connect/items/file_response.rb', line 6

def filename
  @filename
end

Instance Method Details

#dataObject



22
23
24
# File 'lib/vonage/proactive_connect/items/file_response.rb', line 22

def data
  http_response ? http_response.body : nil
end

#save(filepath:) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
# File 'lib/vonage/proactive_connect/items/file_response.rb', line 13

def save(filepath:)
  pn = Pathname.new(filepath)
  raise ArgumentError, ':filepath not a directory' unless pn.directory?
  raise ArgumentError, ':filepath not absolute' unless pn.absolute?
  raise ArgumentError, ':filepath not writable' unless pn.writable?

  File.open("#{pn.cleanpath}/#{filename}", 'w') {|f| f.write(http_response.body) }
end