class Gdsapi::Methods::GetLocations

Private Instance Methods

parse(body) click to toggle source

Parsing routine invoked on JSON response parsed to hash @param [Hash] body - given response hash from GDS @return [Hash[Symbol => Array]] - location objects grouped by editing mode:

:upsert - objects inserted or updated since given timestamp
:delete - objects deleted since given timestamp
# File lib/gdsapi/methods/get_locations.rb, line 14
def parse(body)
  return {} if body.empty?

  locations = body['locations']
  types = body['types']
  attributes = body['attributes']
  sub_types = body['subTypes']
  grouped_locations = locations.group_by { |location| modes[location['mod']] }
  grouped_locations.each_value do |hash_locations|
    hash_locations.map! do |location|
      location[:attributes] = match_attributes(location['attributes'], attributes)
      Gdsapi::Structs::Location.new location.symbolize_keys
    end
  end
  grouped_locations[:types] = types.map { |t| Gdsapi::Structs::Type.new(t.symbolize_keys) }
  grouped_locations[:sub_types] = sub_types.map { |st| Gdsapi::Structs::SubType.new(st.symbolize_keys) }
  grouped_locations
end
path() click to toggle source
# File lib/gdsapi/methods/get_locations.rb, line 33
def path
  'locations'
end
permitted_params() click to toggle source

Query params :country [Number|String] - GDS country id for which locations are fetched (optional) :offset [Number|String] - number of records to be skipped when fetching chunks (optional) :limit [Number|String] - number of records to be fetched when fetching chunks (optional) :timestamp [String] - temporal checkpoint(i.e. date, records from which are interested)

(optional, format: yyyy-MM-dd’T’HH:mm:ssZ, GMT +2)
# File lib/gdsapi/methods/get_locations.rb, line 55
def permitted_params
  %i(country offset limit timestamp)
end
transform_params(filtered_params) click to toggle source
# File lib/gdsapi/methods/get_locations.rb, line 37
def transform_params(filtered_params)
  filtered_params.tap do |params|
    if params[:timestamp]
      if params[:timestamp].respond_to?(:strftime)
        params[:timestamp] = params[:timestamp].strftime('%FT%T%z')
      else
        params[:timestamp] = params[:timestamp].to_s
      end
    end
  end
end