Class: Foursquare::User

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

Instance Method Summary collapse

Constructor Details

#initialize(foursquare, json) ⇒ User

Returns a new instance of User.



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

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

Instance Method Details

#badge_countObject



66
67
68
69
# File 'lib/foursquare/user.rb', line 66

def badge_count
  fetch unless @json.has_key?("badges")
  @json["badges"]["count"]
end

#checkin_countObject



76
77
78
79
# File 'lib/foursquare/user.rb', line 76

def checkin_count
  fetch unless @json.has_key?("checkins")
  @json["checkins"]["count"]
end

#checkins_hereObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/foursquare/user.rb', line 88

def checkins_here
  checkin_json = @foursquare.get("venues/#{last_checkin.venue.id}/herenow")
  checkin_json["hereNow"]["items"].map do |item|
    begin
      next unless json = @foursquare.get("checkins/#{item["id"]}")
      checkin = json["checkin"]
      Foursquare::Checkin.new(@foursquare, checkin)
    rescue Foursquare::Error
      # We can't get checkin information for people who aren't our friends.
    end
  end.compact
end

#contactObject



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

def contact
  fetch unless @json.has_key?("contact")
  @json["contact"]
end

#emailObject



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

def email
  contact["email"]
end

#fetchObject



7
8
9
10
# File 'lib/foursquare/user.rb', line 7

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

#first_nameObject



20
21
22
# File 'lib/foursquare/user.rb', line 20

def first_name
  @json["firstName"]
end

#friends(options = {}) ⇒ Object



101
102
103
104
105
# File 'lib/foursquare/user.rb', line 101

def friends(options={})
  @foursquare.get("users/#{id}/friends", options)["friends"]["items"].map do |item|
    Foursquare::User.new(@foursquare, item)
  end
end

#genderObject



32
33
34
# File 'lib/foursquare/user.rb', line 32

def gender
  @json["gender"]
end

#home_cityObject



36
37
38
# File 'lib/foursquare/user.rb', line 36

def home_city
  @json["homeCity"]
end

#idObject



12
13
14
# File 'lib/foursquare/user.rb', line 12

def id
  @json["id"]
end

#last_checkinObject



81
82
83
84
85
86
# File 'lib/foursquare/user.rb', line 81

def last_checkin
  fetch unless @json.has_key?("checkins")
  return unless @json["checkins"]["items"]
  item = @json["checkins"]["items"].last
  Foursquare::Checkin.new(@foursquare, item)
end

#last_nameObject



24
25
26
# File 'lib/foursquare/user.rb', line 24

def last_name
  @json["lastName"]
end

#mayorshipsObject



71
72
73
74
# File 'lib/foursquare/user.rb', line 71

def mayorships
  fetch unless @json.has_key?("mayorships")
  @json["mayorships"]["items"]
end

#nameObject



16
17
18
# File 'lib/foursquare/user.rb', line 16

def name
  [first_name, last_name].join(' ').strip
end

#phone_numberObject



62
63
64
# File 'lib/foursquare/user.rb', line 62

def phone_number
  contact["phone"]
end

#photoObject



28
29
30
# File 'lib/foursquare/user.rb', line 28

def photo
  @json["photo"]
end

#pingsObject



44
45
46
47
# File 'lib/foursquare/user.rb', line 44

def pings
  fetch unless @json.has_key?("pings")
  @json["pings"]
end

#relationshipObject



40
41
42
# File 'lib/foursquare/user.rb', line 40

def relationship
  @json["relationship"]
end

#tips(options = {}) ⇒ Object



107
108
109
110
111
# File 'lib/foursquare/user.rb', line 107

def tips(options={})
  @foursquare.get("users/#{id}/tips", options)["tips"]["items"].map do |item|
    Foursquare::Tip.new(@foursquare, item)
  end
end

#twitterObject



58
59
60
# File 'lib/foursquare/user.rb', line 58

def twitter
  contact["twitter"]
end