Class: ATDIS::Feed
- Inherits:
-
Object
- Object
- ATDIS::Feed
- Defined in:
- lib/atdis/feed.rb
Constant Summary collapse
- VALID_OPTIONS =
[:page, :street, :suburb, :postcode, :lodgement_date_start, :lodgement_date_end, :last_modified_date_start, :last_modified_date_end]
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Class Method Summary collapse
Instance Method Summary collapse
- #application(id) ⇒ Object
- #application_url(id) ⇒ Object
- #applications(options = {}) ⇒ Object
- #applications_url(options = {}) ⇒ Object
-
#initialize(base_url) ⇒ Feed
constructor
base_url - the base url from which the urls for all atdis urls are made It should be of the form: www.council.nsw.gov.au/atdis/1.0.
Constructor Details
#initialize(base_url) ⇒ Feed
base_url - the base url from which the urls for all atdis urls are made It should be of the form: www.council.nsw.gov.au/atdis/1.0
12 13 14 |
# File 'lib/atdis/feed.rb', line 12 def initialize(base_url) @base_url = base_url end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/atdis/feed.rb', line 5 def base_url @base_url end |
Class Method Details
.base_url_from_url(url) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/atdis/feed.rb', line 33 def self.base_url_from_url(url) u = URI.parse(url) = (u.query) VALID_OPTIONS.each do |o| .delete(o) end u.query = () u.fragment = nil u.path = "/" + u.path.split("/")[1..-2].join("/") u.to_s end |
.options_from_url(url) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/atdis/feed.rb', line 45 def self.(url) u = URI.parse(url) = (u.query) [:lodgement_date_start, :lodgement_date_end, :last_modified_date_start, :last_modified_date_end].each do |k| [k] = Date.parse([k]) if [k] end [:page] = [:page].to_i if [:page] # Remove invalid options .keys.each do |key| if !VALID_OPTIONS.include?(key) .delete(key) end end end |
Instance Method Details
#application(id) ⇒ Object
65 66 67 |
# File 'lib/atdis/feed.rb', line 65 def application(id) Models::Application.read_url(application_url(id)) end |
#application_url(id) ⇒ Object
29 30 31 |
# File 'lib/atdis/feed.rb', line 29 def application_url(id) "#{base_url}/#{CGI::escape(id)}.json" end |
#applications(options = {}) ⇒ Object
61 62 63 |
# File 'lib/atdis/feed.rb', line 61 def applications( = {}) Models::Page.read_url(applications_url()) end |
#applications_url(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/atdis/feed.rb', line 16 def applications_url( = {}) = .keys - VALID_OPTIONS if !.empty? raise "Unexpected options used: #{.join(',')}" end [:street] = [:street].join(",") if [:street].respond_to?(:join) [:suburb] = [:suburb].join(",") if [:suburb].respond_to?(:join) [:postcode] = [:postcode].join(",") if [:postcode].respond_to?(:join) q = Feed.() "#{base_url}/applications.json" + (q ? "?#{q}" : "") end |