Class: LeaflyApiWrapper::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/leafly_api_wrapper/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Location

Returns a new instance of Location.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/leafly_api_wrapper/location.rb', line 14

def initialize(data)
  @id      = data['id']
  @name    = data['name']
  @slug    = data['slug']
  @address = "#{data['address1']} #{data['address2']}".strip
  @address = "#{data['address']} #{data['locationLabel']}".strip if @address.empty?
  @hours = data['hours']
  @phone = data['phone']
  @locationLabel = data['locationLabel']
  @delivery = data['delivery']
  @storefront = data['storefront']
  @lastMenuUpdate = data['lastMenuUpdate']
  @latitude = data['latitude']
  @longitude = data['longitude']
  @rating = data['rating']
  @numReviews = data['numReviews']
  @sponsor = data['sponsor']
  @ada = data['ada']
  @creditCards = data['creditCards']
  @atm = data['atm']
  @marquee = data['marquee']
  @coverPhoto = data['coverPhoto']
  @logoId = data['logoId']
   = data['logo']
  @medical = data['medical']
  @retail = data['retail']
  @price1 = data['price1']
  @price2 = data['price2']
  @price3 = data['price3']
  @mapMarkerLevel = data['mapMarkerLevel']
  @canadaLP = data['canadaLP']
  @tagLine = data['tagLine']
  @permalink = data['permalink']
  @starImage = data['starImage']
  @customMarker = data['customMarker']
  @customMarker2x = data['customMarker2x']
  @mapMarker = data['mapMarker']
  @specials = data['specials']
end

Instance Attribute Details

#adaObject (readonly)

Returns the value of attribute ada.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def ada
  @ada
end

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def address
  @address
end

#atmObject (readonly)

Returns the value of attribute atm.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def atm
  @atm
end

#canadaLPObject (readonly)

Returns the value of attribute canadaLP.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def canadaLP
  @canadaLP
end

#coverPhotoObject (readonly)

Returns the value of attribute coverPhoto.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def coverPhoto
  @coverPhoto
end

#creditCardsObject (readonly)

Returns the value of attribute creditCards.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def creditCards
  @creditCards
end

#customMarkerObject (readonly)

Returns the value of attribute customMarker.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def customMarker
  @customMarker
end

#customMarker2xObject (readonly)

Returns the value of attribute customMarker2x.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def customMarker2x
  @customMarker2x
end

#deliveryObject (readonly)

Returns the value of attribute delivery.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def delivery
  @delivery
end

#hoursObject (readonly)

Returns the value of attribute hours.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def hours
  @hours
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def id
  @id
end

#lastMenuUpdateObject (readonly)

Returns the value of attribute lastMenuUpdate.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def lastMenuUpdate
  @lastMenuUpdate
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def latitude
  @latitude
end

#locationLabelObject (readonly)

Returns the value of attribute locationLabel.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def locationLabel
  @locationLabel
end

#logoObject (readonly)

Returns the value of attribute logo.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def 
  
end

#logoIdObject (readonly)

Returns the value of attribute logoId.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def logoId
  @logoId
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def longitude
  @longitude
end

#mapMarkerObject (readonly)

Returns the value of attribute mapMarker.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def mapMarker
  @mapMarker
end

#mapMarkerLevelObject (readonly)

Returns the value of attribute mapMarkerLevel.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def mapMarkerLevel
  @mapMarkerLevel
end

#marqueeObject (readonly)

Returns the value of attribute marquee.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def marquee
  @marquee
end

#medicalObject (readonly)

Returns the value of attribute medical.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def medical
  @medical
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def name
  @name
end

#numReviewsObject (readonly)

Returns the value of attribute numReviews.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def numReviews
  @numReviews
end

Returns the value of attribute permalink.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def permalink
  @permalink
end

#phoneObject (readonly)

Returns the value of attribute phone.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def phone
  @phone
end

#price1Object (readonly)

Returns the value of attribute price1.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def price1
  @price1
end

#price2Object (readonly)

Returns the value of attribute price2.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def price2
  @price2
end

#price3Object (readonly)

Returns the value of attribute price3.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def price3
  @price3
end

#ratingObject (readonly)

Returns the value of attribute rating.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def rating
  @rating
end

#retailObject (readonly)

Returns the value of attribute retail.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def retail
  @retail
end

#slugObject (readonly)

Returns the value of attribute slug.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def slug
  @slug
end

#specialsObject (readonly)

Returns the value of attribute specials.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def specials
  @specials
end

Returns the value of attribute sponsor.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def sponsor
  @sponsor
end

#starImageObject (readonly)

Returns the value of attribute starImage.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def starImage
  @starImage
end

#storefrontObject (readonly)

Returns the value of attribute storefront.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def storefront
  @storefront
end

#tagLineObject (readonly)

Returns the value of attribute tagLine.



7
8
9
# File 'lib/leafly_api_wrapper/location.rb', line 7

def tagLine
  @tagLine
end

Class Method Details

.connectionObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/leafly_api_wrapper/location.rb', line 75

def self.connection
  api_id   = LeaflyApiWrapper.configuration.api_id
  api_key  = LeaflyApiWrapper.configuration.api_key
  base_url = LeaflyApiWrapper.configuration.base_url

  conn = Faraday.new(url: base_url) do |req|
    req.headers = { 'app_key' => api_key, 'app_id' => api_id }
    req.request  :url_encoded
    req.response :logger
    req.adapter  Faraday.default_adapter
  end
end

.get(slug) ⇒ Object



68
69
70
71
# File 'lib/leafly_api_wrapper/location.rb', line 68

def self.get(slug)
  res = connection.get "/locations/#{slug}"
  new(JSON.parse(res.body))
end

.near(lat, lon, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/leafly_api_wrapper/location.rb', line 55

def self.near(lat, lon, options = {})
  response = connection.post '/locations', {
    page:      0,
    take:      50,
    latitude:  lat,
    longitude: lon
  }.merge(options)

  JSON.parse(response.body)['stores'].collect do |data|
    new(data)
  end
end