Class: Papapi::FormResponse

Inherits:
Response show all
Defined in:
lib/papapi/form_response.rb

Constant Summary

Constants inherited from Response

Response::REMOVE_VARS

Instance Attribute Summary

Attributes inherited from Response

#request, #responses

Instance Method Summary collapse

Methods inherited from Response

#initialize, #parsed

Constructor Details

This class inherits a constructor from Papapi::Response

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/papapi/form_response.rb', line 21

def [] (key)
  fields[key.to_sym]
end

#fieldsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/papapi/form_response.rb', line 5

def fields
  unless @fields
    @fields = {}
    self.parsed['fields'].each do |field|
      next if REMOVE_VARS.include? field[0]
      raise "Error: #{field[3]}" if field[3] && ! field[3].empty?
      if field[2]
        @fields[field[0].to_sym] = field[2]
      else
        @fields[field[0].to_sym] = field[1]
      end
    end
  end
  @fields
end

#to_hObject



25
26
27
# File 'lib/papapi/form_response.rb', line 25

def to_h
  fields
end