Class: Foursquare::User
- Inherits:
-
Object
- Object
- Foursquare::User
- Defined in:
- lib/foursquare/user.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #all_checkins ⇒ Object
- #badge_count ⇒ Object
- #checkin_count ⇒ Object
- #checkins(options = {}) ⇒ Object
- #checkins_here ⇒ Object
- #contact ⇒ Object
- #email ⇒ Object
- #facebook ⇒ Object
- #facebook? ⇒ Boolean
- #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
- #twitter? ⇒ Boolean
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
#json ⇒ Object (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_checkins ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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(={}) @foursquare.get("users/#{id}/checkins", )["checkins"]["items"].map do |item| Foursquare::Checkin.new(@foursquare, item) end end |
#checkins_here ⇒ Object
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 |
#contact ⇒ Object
51 52 53 54 |
# File 'lib/foursquare/user.rb', line 51 def contact fetch unless @json.has_key?("contact") @json["contact"] end |
#email ⇒ Object
56 57 58 |
# File 'lib/foursquare/user.rb', line 56 def email contact["email"] end |
#facebook ⇒ Object
64 65 66 |
# File 'lib/foursquare/user.rb', line 64 def facebook contact["facebook"] end |
#facebook? ⇒ Boolean
72 73 74 |
# File 'lib/foursquare/user.rb', line 72 def facebook? !facebook.blank? end |
#fetch ⇒ Object
9 10 11 12 |
# File 'lib/foursquare/user.rb', line 9 def fetch @json = @foursquare.get("users/#{id}")["user"] self end |
#first_name ⇒ Object
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(={}) @foursquare.get("users/#{id}/friends", )["friends"]["items"].map do |item| Foursquare::User.new(@foursquare, item) end end |
#gender ⇒ Object
34 35 36 |
# File 'lib/foursquare/user.rb', line 34 def gender @json["gender"] end |
#home_city ⇒ Object
38 39 40 |
# File 'lib/foursquare/user.rb', line 38 def home_city @json["homeCity"] end |
#id ⇒ Object
14 15 16 |
# File 'lib/foursquare/user.rb', line 14 def id @json["id"] end |
#last_checkin ⇒ Object
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_name ⇒ Object
26 27 28 |
# File 'lib/foursquare/user.rb', line 26 def last_name @json["lastName"] end |
#mayorships ⇒ Object
85 86 87 88 |
# File 'lib/foursquare/user.rb', line 85 def mayorships fetch unless @json.has_key?("mayorships") @json["mayorships"]["items"] end |
#name ⇒ Object
18 19 20 |
# File 'lib/foursquare/user.rb', line 18 def name [first_name, last_name].join(' ').strip end |
#phone_number ⇒ Object
76 77 78 |
# File 'lib/foursquare/user.rb', line 76 def phone_number contact["phone"] end |
#photo ⇒ Object
30 31 32 |
# File 'lib/foursquare/user.rb', line 30 def photo @json["photo"] end |
#pings ⇒ Object
46 47 48 49 |
# File 'lib/foursquare/user.rb', line 46 def pings fetch unless @json.has_key?("pings") @json["pings"] end |
#relationship ⇒ Object
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(={}) @foursquare.get("users/#{id}/tips", )["tips"]["items"].map do |item| Foursquare::Tip.new(@foursquare, item) end end |
#twitter ⇒ Object
60 61 62 |
# File 'lib/foursquare/user.rb', line 60 def twitter contact["twitter"] end |
#twitter? ⇒ Boolean
68 69 70 |
# File 'lib/foursquare/user.rb', line 68 def twitter? !twitter.blank? end |