Class: Usps::Imis::BaseData
- Inherits:
-
Hash
- Object
- Hash
- Usps::Imis::BaseData
- Defined in:
- lib/usps/imis/base_data.rb
Overview
Base class for API data response wrappers
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Load raw API response JSON to access properties.
Instance Method Summary collapse
-
#[](_property_name) ⇒ Object
Access an individual property value by name.
- #[]= ⇒ Object
-
#imis_id ⇒ Object
(also: #id)
Access the iMIS ID property.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
-
#properties ⇒ Object
Hash of all property names to values.
Class Method Details
.from_json(json) ⇒ Object
Load raw API response JSON to access properties
15 |
# File 'lib/usps/imis/base_data.rb', line 15 def self.from_json(json) = self[JSON.parse(json)] |
Instance Method Details
#[](_property_name) ⇒ Object
Access an individual property value by name
28 29 30 |
# File 'lib/usps/imis/base_data.rb', line 28 def [](_property_name) raise Errors::ApiError, "#{self.class} must implement #[](property_name)" end |
#[]= ⇒ Object
38 39 40 41 42 43 |
# File 'lib/usps/imis/base_data.rb', line 38 def []=(...) raise( Errors::ApiError, "#{self.class} does not support setting values. If you need to modify it, call `.raw` on it." ) end |
#imis_id ⇒ Object Also known as: id
Access the iMIS ID property
21 22 23 |
# File 'lib/usps/imis/base_data.rb', line 21 def imis_id raise Errors::ApiError, "#{self.class} must implement #imis_id" end |
#inspect ⇒ Object
45 46 47 48 49 |
# File 'lib/usps/imis/base_data.rb', line 45 def inspect stringio = StringIO.new PP.pp(self, stringio) stringio.string.delete("\n") end |
#pretty_print(pp) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/usps/imis/base_data.rb', line 51 def pretty_print(pp) pp.group(1, "#<#{self.class}", '>') do pretty_print_data.each do |key, value| pp.breakable pp.text "#{key}=" pp.pp value end end end |