Class: ResoTransport::BaseMetadata
- Inherits:
-
Object
- Object
- ResoTransport::BaseMetadata
- Defined in:
- lib/reso_transport/base_metadata.rb
Direct Known Subclasses
Constant Summary collapse
- MIME_TYPES =
{ xml: 'application/xml', json: 'application/json' }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #cache ⇒ Object
- #cache_file ⇒ Object
- #classname ⇒ Object
- #data ⇒ Object
-
#initialize(client) ⇒ BaseMetadata
constructor
A new instance of BaseMetadata.
- #parser ⇒ Object
- #prefix ⇒ Object
- #raw ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(client) ⇒ BaseMetadata
Returns a new instance of BaseMetadata.
10 11 12 13 14 |
# File 'lib/reso_transport/base_metadata.rb', line 10 def initialize(client) @client = client @prefix = nil @classname = nil end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/reso_transport/base_metadata.rb', line 8 def client @client end |
Instance Method Details
#cache ⇒ Object
40 41 42 |
# File 'lib/reso_transport/base_metadata.rb', line 40 def cache @cache ||= client.send("#{prefix}_cache").new(cache_file) end |
#cache_file ⇒ Object
44 45 46 |
# File 'lib/reso_transport/base_metadata.rb', line 44 def cache_file @cache_file ||= client.send "#{prefix}_file" end |
#classname ⇒ Object
22 23 24 25 26 |
# File 'lib/reso_transport/base_metadata.rb', line 22 def classname raise 'classname not set' unless @classname @classname end |
#data ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/reso_transport/base_metadata.rb', line 32 def data if cache_file cache.read || cache.write(raw) else raw end end |
#parser ⇒ Object
28 29 30 |
# File 'lib/reso_transport/base_metadata.rb', line 28 def parser @parser ||= Object::const_get("#{classname}Parser").new.parse(data) end |
#prefix ⇒ Object
16 17 18 19 20 |
# File 'lib/reso_transport/base_metadata.rb', line 16 def prefix raise 'prefix not set' unless @prefix @prefix end |
#raw ⇒ Object
48 49 50 51 52 |
# File 'lib/reso_transport/base_metadata.rb', line 48 def raw return response.body if response.success? raise RequestError.new(request, response, classname) end |
#request ⇒ Object
58 59 60 61 62 |
# File 'lib/reso_transport/base_metadata.rb', line 58 def request return @request.to_h if @request.respond_to? :to_h {} end |
#response ⇒ Object
54 55 56 |
# File 'lib/reso_transport/base_metadata.rb', line 54 def response raise 'Must implement response method' end |