Class: Ecfr::VersionerService::Structure
- Defined in:
- lib/ecfr/versioner_service/structure.rb
Constant Summary collapse
- STRUCTURE_PATH =
"v1/structure"
Constants inherited from Base
Base::SUPPORTED_ARRAY_ACCESSORS
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Attributes inherited from Base
#metadata, #request_data, #response_status, #results
Class Method Summary collapse
-
.find(date, title_number, options = {}) ⇒ <Structure>
Retrieves the structure content for given date and hierarchy.
-
.url_for(date, title_number, options = {}) ⇒ <String>
Provides a url to the structure content for given date and hierarchy.
Instance Method Summary collapse
-
#initialize(data, options = {format: "json"}) ⇒ Structure
constructor
A new instance of Structure.
Methods inherited from Base
base_url, service_name, service_path
Methods inherited from Base
basic_auth_client_options, #each, metadata, metadata_key, result_key
Methods included from Extensible
Methods included from AttributeMethodDefinition
Methods inherited from Client
build, cache_key, client, client_pool, delete, execute, get, handle_response, perform, post, purge
Methods included from ParallelClient
Constructor Details
#initialize(data, options = {format: "json"}) ⇒ Structure
Returns a new instance of Structure.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ecfr/versioner_service/structure.rb', line 61 def initialize(data, = {format: "json"}) data = data.body if data.is_a?(Faraday::Response) format = [:format] skip_cache = false # we're going to load a response from sideloaded cache if data.is_a?(Hash) && format != "sideloaded" format = "sideloaded" skip_cache = true end if format == "json" @data = JSON.parse(data).with_indifferent_access elsif format == "xml" @data = Nokogiri::XML::Document.parse(data) elsif format == "sideloaded" @data = data.with_indifferent_access if Ecfr.config.cache_responses && !skip_cache # cache sideloaded response seperately so that a non sideloaded # call to structure can take advantage of cache cache_key = determine_cache_key([:referrer].request_data) # the client expects to be dealing with response objects, in a # sideload scenario we need to cache a response like object RequestStore[cache_key] = OpenStruct.new( body: data, status: [:referrer].response_status ) end end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
59 60 61 |
# File 'lib/ecfr/versioner_service/structure.rb', line 59 def data @data end |
Class Method Details
.find(date, title_number, options = {}) ⇒ <Structure>
Retrieves the structure content for given date and hierarchy
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ecfr/versioner_service/structure.rb', line 16 def self.find(date, title_number, = {}) = {format: "json"} = .merge(.symbolize_keys) format = .delete(:format) perform( :get, structure_path(date, title_number, format), params: .except(:section, :appendix).compact, perform_options: { init_data: {format: format}, parse_response: false } ) end |
.url_for(date, title_number, options = {}) ⇒ <String>
Provides a url to the structure content for given date and hierarchy
43 44 45 46 47 48 49 50 51 |
# File 'lib/ecfr/versioner_service/structure.rb', line 43 def self.url_for(date, title_number, = {}) = {format: "json"} = .merge(.symbolize_keys) format = .delete(:format) path = [service_path, structure_path(date, title_number, format)].join("/") client.build_url(path, ).to_s end |