Class: Foursquare::User
- Inherits:
-
Object
- Object
- Foursquare::User
- Defined in:
- lib/foursquare/user.rb
Instance Method Summary collapse
- #badge_count ⇒ Object
- #checkin_count ⇒ Object
- #checkins_here ⇒ Object
- #contact ⇒ Object
- #email ⇒ Object
- #fetch ⇒ Object
- #first_name ⇒ Object
- #friends(options = {}) ⇒ Object
- #gender ⇒ Object
- #home_city ⇒ Object
- #id ⇒ Object
-
#initialize(foursquare, json) ⇒ User
constructor
A new instance of User.
- #last_checkin ⇒ Object
- #last_name ⇒ Object
- #mayorships ⇒ Object
- #name ⇒ Object
- #phone_number ⇒ Object
- #photo ⇒ Object
- #pings ⇒ Object
- #relationship ⇒ Object
- #tips(options = {}) ⇒ Object
- #twitter ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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_here ⇒ Object
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 |
#contact ⇒ Object
49 50 51 52 |
# File 'lib/foursquare/user.rb', line 49 def contact fetch unless @json.has_key?("contact") @json["contact"] end |
#email ⇒ Object
54 55 56 |
# File 'lib/foursquare/user.rb', line 54 def email contact["email"] end |
#fetch ⇒ Object
7 8 9 10 |
# File 'lib/foursquare/user.rb', line 7 def fetch @json = @foursquare.get("users/#{id}")["user"] self end |
#first_name ⇒ Object
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(={}) @foursquare.get("users/#{id}/friends", )["friends"]["items"].map do |item| Foursquare::User.new(@foursquare, item) end end |
#gender ⇒ Object
32 33 34 |
# File 'lib/foursquare/user.rb', line 32 def gender @json["gender"] end |
#home_city ⇒ Object
36 37 38 |
# File 'lib/foursquare/user.rb', line 36 def home_city @json["homeCity"] end |
#id ⇒ Object
12 13 14 |
# File 'lib/foursquare/user.rb', line 12 def id @json["id"] end |
#last_checkin ⇒ Object
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_name ⇒ Object
24 25 26 |
# File 'lib/foursquare/user.rb', line 24 def last_name @json["lastName"] end |
#mayorships ⇒ Object
71 72 73 74 |
# File 'lib/foursquare/user.rb', line 71 def mayorships fetch unless @json.has_key?("mayorships") @json["mayorships"]["items"] end |
#name ⇒ Object
16 17 18 |
# File 'lib/foursquare/user.rb', line 16 def name [first_name, last_name].join(' ').strip end |
#phone_number ⇒ Object
62 63 64 |
# File 'lib/foursquare/user.rb', line 62 def phone_number contact["phone"] end |
#photo ⇒ Object
28 29 30 |
# File 'lib/foursquare/user.rb', line 28 def photo @json["photo"] end |
#pings ⇒ Object
44 45 46 47 |
# File 'lib/foursquare/user.rb', line 44 def pings fetch unless @json.has_key?("pings") @json["pings"] end |
#relationship ⇒ Object
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(={}) @foursquare.get("users/#{id}/tips", )["tips"]["items"].map do |item| Foursquare::Tip.new(@foursquare, item) end end |
#twitter ⇒ Object
58 59 60 |
# File 'lib/foursquare/user.rb', line 58 def twitter contact["twitter"] end |