lib/school_digger/api.rb in school_digger-1.2.0 vs lib/school_digger/api.rb in school_digger-2.1.0

- old
+ new

@@ -1,24 +1,25 @@ module SchoolDigger class Api include HTTParty - attr_reader :app_id, :app_key - + attr_reader :app_id, :app_key, :api_version + def initialize(options = {}) @app_id = options.fetch(:app_id, default_app_id) @app_key = options.fetch(:app_key, default_app_key) + @api_version = options.fetch(:api_version, default_api_version) end def get(path, query = {}) response = self.class.get(school_digger_url_base + path, query: modify_query(query), timeout: 30) end # # SchoolDigger::Api.new.autocomplete('San Die', st: "CA") def autocomplete(query, options = {} ) - available_options = %w(q st level boxLatitudeNW boxLongitudeNW boxLatitudeSE boxLongitudeSE returnCount) + available_options = %w(q st level eSE boxLongitudeSE returnCount) options = options.select {|k,v| available_options.include?(k.to_s)} options[:q] = query get "/autocomplete/schools", options end @@ -97,28 +98,28 @@ appKey: app_key } default_params.merge query end - def default_app_id + def default_app_id ENV.fetch("SCHOOL_DIGGER_APP_ID", 'not-implemented') end - def default_app_key + def default_app_key ENV.fetch("SCHOOL_DIGGER_APP_KEY", 'not-implemented') end + def default_api_version + ENV.fetch("SCHOOL_DIGGER_API_VERSION", "1.1") + end + def school_digger_url_endpoint @school_digger_url_endpoint ||= ENV.fetch("SCHOOL_DIGGER_BASE_URL", "https://api.schooldigger.com") end - def school_digger_api_version - @school_digger_api_version ||= ENV.fetch("SCHOOL_DIGGER_API_VERSION", "1.1") - end - + def school_digger_url_base - @school_digger_url_base ||= "#{school_digger_url_endpoint}/v#{school_digger_api_version}" + @school_digger_url_base ||= "#{school_digger_url_endpoint}/v#{api_version}" end - end end