Class: Foursquare::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(foursquare, json) ⇒ User

Returns a new instance of User.



5
6
7
# File 'lib/foursquare/user.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/user.rb', line 3

def json
  @json
end

Instance Method Details

#all_checkinsObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/foursquare/user.rb', line 98

def all_checkins
  count = 250
  offset = 0
  array = []
  while count == 250
    checkins = checkins(:limit => count, :offset => offset)
    array += checkins
    count = checkins.count
    offset = offset + count
  end
  array
end

#badge_countObject



80
81
82
83
# File 'lib/foursquare/user.rb', line 80

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

#checkin_countObject



111
112
113
114
# File 'lib/foursquare/user.rb', line 111

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

#checkins(options = {}) ⇒ Object



92
93
94
95
96
# File 'lib/foursquare/user.rb', line 92

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

#checkins_hereObject



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/foursquare/user.rb', line 123

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



51
52
53
54
# File 'lib/foursquare/user.rb', line 51

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

#emailObject



56
57
58
# File 'lib/foursquare/user.rb', line 56

def email
  contact["email"]
end

#facebookObject



64
65
66
# File 'lib/foursquare/user.rb', line 64

def facebook
  contact["facebook"]
end

#facebook?Boolean

Returns:

  • (Boolean)


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

def facebook?
  !facebook.blank?
end

#fetchObject



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

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

#first_nameObject



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

def first_name
  @json["firstName"]
end

#friends(options = {}) ⇒ Object



136
137
138
139
140
# File 'lib/foursquare/user.rb', line 136

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

#genderObject



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

def gender
  @json["gender"]
end

#home_cityObject



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

def home_city
  @json["homeCity"]
end

#idObject



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

def id
  @json["id"]
end

#last_checkinObject



116
117
118
119
120
121
# File 'lib/foursquare/user.rb', line 116

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



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

def last_name
  @json["lastName"]
end

#mayorshipsObject



85
86
87
88
# File 'lib/foursquare/user.rb', line 85

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

#nameObject



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

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

#phone_numberObject



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

def phone_number
  contact["phone"]
end

#photoObject



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

def photo
  @json["photo"]
end

#pingsObject



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

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

#relationshipObject



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

def relationship
  @json["relationship"]
end

#tips(options = {}) ⇒ Object



142
143
144
145
146
# File 'lib/foursquare/user.rb', line 142

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

#twitterObject



60
61
62
# File 'lib/foursquare/user.rb', line 60

def twitter
  contact["twitter"]
end

#twitter?Boolean

Returns:

  • (Boolean)


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

def twitter?
  !twitter.blank?
end