Class: GooglePlaces::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/google_places/photo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, photo_reference, html_attributions, api_key, sensor) ⇒ Photo

Returns a new instance of Photo.



5
6
7
8
9
10
11
12
# File 'lib/google_places/photo.rb', line 5

def initialize(width, height, photo_reference, html_attributions, api_key, sensor)
  @width             = width
  @height            = height
  @photo_reference   = photo_reference
  @html_attributions = html_attributions
  @api_key           = api_key
  @sensor            = sensor
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/google_places/photo.rb', line 3

def height
  @height
end

#html_attributionsObject

Returns the value of attribute html_attributions.



3
4
5
# File 'lib/google_places/photo.rb', line 3

def html_attributions
  @html_attributions
end

#photo_referenceObject

Returns the value of attribute photo_reference.



3
4
5
# File 'lib/google_places/photo.rb', line 3

def photo_reference
  @photo_reference
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/google_places/photo.rb', line 3

def width
  @width
end

Instance Method Details

#fetch_url(maxwidth, options = {}) ⇒ URL

Search for a Photo’s url with its reference key

Parameters:

  • api_key (String)

    the provided api key

  • sensor (Boolean)

    Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. Note that this is a mandatory parameter

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

Returns:

  • (URL)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/google_places/photo.rb', line 28

def fetch_url(maxwidth, options = {})
  language  = options.delete(:language)
  retry_options = options.delete(:retry_options) || {}

  unless @fetched_url
    @fetched_url = Request.photo_url(
      :maxwidth => maxwidth,
      :photoreference => @photo_reference,
      :sensor => @sensor,
      :key => @api_key,
      :retry_options => retry_options
    )
  end
  @fetched_url
end