Class: OpenCongressApi::Base
- Inherits:
-
Object
- Object
- OpenCongressApi::Base
- Defined in:
- lib/opencongress_api/fetcher/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#fetch(options = {}) ⇒ Object
Fetch and parse a response based on a set of options Override this method to ensure necessary options are passed for the request.
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
19 20 21 |
# File 'lib/opencongress_api/fetcher/base.rb', line 19 def initialize @type = nil end |
Instance Method Details
#fetch(options = {}) ⇒ Object
Fetch and parse a response based on a set of options Override this method to ensure necessary options are passed for the request
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/opencongress_api/fetcher/base.rb', line 28 def fetch( = {}) url = build_url() puts "Getting #{url}" json = get_response(url) if self.is_json? data = JSON.parse(json) else data = XmlSimple.xml_in(json) end # TODO: Raise hell if there is a problem collection = OpenCongressApi::Collection.build(json_result(data)) collection.map!{|result| format_result(result)} end |