Class: Usps::Imis::BaseData

Inherits:
Hash
  • Object
show all
Defined in:
lib/usps/imis/base_data.rb

Overview

Base class for API data response wrappers

Direct Known Subclasses

Data, PartyData

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json) ⇒ Object

Load raw API response JSON to access properties

Parameters:

  • json (String)

    Raw API response JSON



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

Raises:



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

Raises:



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_idObject Also known as: id

Access the iMIS ID property

Raises:



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

#inspectObject



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

#propertiesObject

Hash of all property names to values

Raises:



34
35
36
# File 'lib/usps/imis/base_data.rb', line 34

def properties(...)
  raise Errors::ApiError, "#{self.class} must implement #properties"
end