Sha256: e0894dc9890e698b7616c3208b5ff445d84d27ccf62158d72dea6e90b92118a9

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require "geocoder/lookups/google"
require "geocoder/results/google_places_details"

module Geocoder
  module Lookup
    class GooglePlacesDetails < Google
      def name
        "Google Places Details"
      end

      def required_api_key_parts
        ["key"]
      end

      def supported_protocols
        [:https]
      end

      private

      def base_query_url(query)
        "#{protocol}://maps.googleapis.com/maps/api/place/details/json?"
      end

      def result_root_attr
        'result'
      end

      def results(query)
        result = super(query)
        return [result] unless result.is_a? Array

        result
      end

      def fields(query)
        if query.options.has_key?(:fields)
          return format_fields(query.options[:fields])
        end

        if configuration.has_key?(:fields)
          return format_fields(configuration[:fields])
        end

        nil  # use Google Places defaults
      end

      def format_fields(*fields)
        flattened = fields.flatten.compact
        return if flattened.empty?

        flattened.join(',')
      end

      def query_url_google_params(query)
        {
          placeid: query.text,
          fields: fields(query),
          language: query.language || configuration.language
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/lookups/google_places_details.rb
geocoder-1.8.2 lib/geocoder/lookups/google_places_details.rb
geocoder-1.8.1 lib/geocoder/lookups/google_places_details.rb
geocoder-1.8.0 lib/geocoder/lookups/google_places_details.rb