Class: Vonage::ProactiveConnect::Items::FileResponse
- 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
-
#filename ⇒ Object
Returns the value of attribute filename.
Attributes inherited from Response
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(entity = nil, http_response = nil) ⇒ FileResponse
constructor
A new instance of FileResponse.
- #save(filepath:) ⇒ Object
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
#filename ⇒ Object
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
#data ⇒ Object
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
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 |