Class: RsrGroup::ResponseFile
- Defined in:
- lib/rsr_group/response_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
(also: #get_content)
readonly
Returns the value of attribute content.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ResponseFile
constructor
A new instance of ResponseFile.
- #response_type ⇒ Object
- #to_json ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ ResponseFile
Returns a new instance of ResponseFile.
8 9 10 11 12 13 14 |
# File 'lib/rsr_group/response_file.rb', line 8 def initialize( = {}) requires!(, :username, :password, :filename) @credentials = .select { |k, v| [:username, :password].include?(k) } @filename = File.basename([:filename]) @account_number = @filename.split('-')[2] end |
Instance Attribute Details
#content ⇒ Object (readonly) Also known as: get_content
Returns the value of attribute content.
4 5 6 |
# File 'lib/rsr_group/response_file.rb', line 4 def content @content end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/rsr_group/response_file.rb', line 5 def filename @filename end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/rsr_group/response_file.rb', line 6 def end |
Class Method Details
.all(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rsr_group/response_file.rb', line 22 def self.all( = {}) requires!(, :username, :password) Base.connect() do |ftp| ftp.chdir(RsrGroup.config.response_dir) @resp = ftp.nlst("*.txt") ftp.close end @resp end |
Instance Method Details
#response_type ⇒ Object
45 46 47 |
# File 'lib/rsr_group/response_file.rb', line 45 def response_type FILE_TYPES[@filename.split("-").first] end |
#to_json ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rsr_group/response_file.rb', line 49 def to_json get_content if @content.length == 0 raise ZeroByteFile.new("File is empty (filename: #{@filename})") end @json = { response_type: response_type, identifier: @content.lines[1].split(";")[0], filename: @filename, account_number: @account_number, } return parse_eerr if error? return parse_econf if confirmation? return parse_eship if shipping? end |