Class: Foursquare::Venue

Inherits:
Object
  • Object
show all
Defined in:
lib/foursquare/venue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(foursquare, json) ⇒ Venue

Returns a new instance of Venue.



5
6
7
# File 'lib/foursquare/venue.rb', line 5

def initialize(foursquare, json)
  @foursquare, @json = foursquare, json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



3
4
5
# File 'lib/foursquare/venue.rb', line 3

def json
  @json
end

Instance Method Details

#all_photos(options = {:group => "venue"}) ⇒ Object



83
84
85
86
87
# File 'lib/foursquare/venue.rb', line 83

def all_photos(options={:group => "venue"})
  @foursquare.get("venues/#{id}/photos", options)["photos"]["items"].map do |item|
    Foursquare::Photo.new(@foursquare, item)
  end
end

#categoriesObject



30
31
32
# File 'lib/foursquare/venue.rb', line 30

def categories
  @categories ||= @json["categories"].map { |hash| Foursquare::Category.new(hash) }
end

#checkins_countObject



38
39
40
# File 'lib/foursquare/venue.rb', line 38

def checkins_count
  @json["stats"]["checkinsCount"]
end

#contactObject



22
23
24
# File 'lib/foursquare/venue.rb', line 22

def contact
  @json["contact"]
end

#fetchObject



9
10
11
12
# File 'lib/foursquare/venue.rb', line 9

def fetch
  @json = @foursquare.get("venues/#{id}")["venue"]
  self
end

#here_now_checkins(options = {:limit => "50"}) ⇒ Object

returns a list of checkins (only if a valid oauth token from a user is provided) developer.foursquare.com/docs/venues/herenow.html options: limit, offset, aftertimestamp



98
99
100
101
102
# File 'lib/foursquare/venue.rb', line 98

def here_now_checkins(options={:limit => "50"})
  @foursquare.get("venues/#{id}/herenow", options)["hereNow"]["items"].map do |item|
    Foursquare::Checkin.new(@foursquare, item)
  end
end

#here_now_countObject

count the people who have checked-in at the venue in the last two hours



90
91
92
93
# File 'lib/foursquare/venue.rb', line 90

def here_now_count
  fetch unless @json.has_key?("hereNow")
  @json["hereNow"]["count"]
end

#iconObject

return the url to the icon of the primary category if no primary is available, then return a default icon



61
62
63
# File 'lib/foursquare/venue.rb', line 61

def icon
  primary_category ? primary_category["icon"] : "https://foursquare.com/img/categories/none.png"
end

#idObject



14
15
16
# File 'lib/foursquare/venue.rb', line 14

def id
  @json["id"]
end

#locationObject



26
27
28
# File 'lib/foursquare/venue.rb', line 26

def location
  Foursquare::Location.new(@json["location"])
end

#nameObject



18
19
20
# File 'lib/foursquare/venue.rb', line 18

def name
  @json["name"]
end

#photosObject

not all photos may be present here (but we try to avoid one extra API call) if you want to get all the photos, try all_photos



75
76
77
78
79
80
# File 'lib/foursquare/venue.rb', line 75

def photos
  return all_photos if @json["photos"].blank?
  @json["photos"]["groups"].select { |g| g["type"] == "venue" }.first["items"].map do |item|
    Foursquare::Photo.new(@foursquare, item)
  end
end

#photos_countObject



69
70
71
# File 'lib/foursquare/venue.rb', line 69

def photos_count
  @json["photos"]["count"]
end

#primary_categoryObject



54
55
56
57
# File 'lib/foursquare/venue.rb', line 54

def primary_category
  return nil if categories.blank?
  @primary_category ||= categories.select { |category| category.primary? }.try(:first)
end

#short_urlObject



65
66
67
# File 'lib/foursquare/venue.rb', line 65

def short_url
  @json["shortUrl"]
end

#statsObject



50
51
52
# File 'lib/foursquare/venue.rb', line 50

def stats
  @json["stats"]
end

#todos_countObject



46
47
48
# File 'lib/foursquare/venue.rb', line 46

def todos_count
  @json["todos"]["count"]
end

#users_countObject



42
43
44
# File 'lib/foursquare/venue.rb', line 42

def users_count
  @json["stats"]["usersCount"]
end

#verified?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/foursquare/venue.rb', line 34

def verified?
  @json["verified"]
end