Class: Foursquared::Response::User

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

Overview

User response class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, response) ⇒ User

Returns a new instance of User.



8
9
10
11
# File 'lib/foursquared/response/user.rb', line 8

def initialize client, response
  @client = client
  @response = response
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/foursquared/response/user.rb', line 7

def client
  @client
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/foursquared/response/user.rb', line 7

def response
  @response
end

Instance Method Details

#approve_friend_request(user_id) ⇒ Foursquared::Response::User

Approves a pending friend request from this user.

Returns:



208
209
210
211
# File 'lib/foursquared/response/user.rb', line 208

def approve_friend_request user_id
  response = post("/users/#{id}/approve")["response"]
  @user = Foursquared::Response::User.new(client, response["user"])
end

#badgesHash

List user’s badges

Returns:

  • (Hash)

    count and items of badges



195
196
197
198
# File 'lib/foursquared/response/user.rb', line 195

def badges
  @badges = response["badges"]
  @badges["items"].map!{|item| Foursquared::Response::Badge.new(client, item)}
end

#bioString

A short bio for the user

Returns:

  • (String)


82
83
84
# File 'lib/foursquared/response/user.rb', line 82

def bio
  response["bio"]
end

#checkin_pingsString

Whether to ping if user checkins

Returns:

  • (String)


88
89
90
# File 'lib/foursquared/response/user.rb', line 88

def checkin_pings
  response["checkinPings"]
end

#contactHash

User’s contact details

Returns:

  • (Hash)

    An object containing none, some, or all of twitter, facebook, email, and phone.



118
119
120
# File 'lib/foursquared/response/user.rb', line 118

def contact
  response["contact"]
end

#deny_friend_requestFoursquared::Response::User

Denies a pending friend request from this user.

Returns:



215
216
217
218
# File 'lib/foursquared/response/user.rb', line 215

def deny_friend_request
  request_response = post("/users/#{id}/deny")["response"]
  @user = Foursquared::Response::User.new(client, request_response["user"])
end

#first_nameString

User’s first name

Returns:

  • (String)


21
22
23
# File 'lib/foursquared/response/user.rb', line 21

def first_name
  response["firstName"]
end

#followersHash

User’s followers

Returns:

  • (Hash)

    Optional, Contains count of followers and groups of users who follow or like this user



136
137
138
139
140
141
142
143
144
# File 'lib/foursquared/response/user.rb', line 136

def followers
  if response["followers"] and response["followers"]["groups"]
    @followers = response["followers"]
    @followers["groups"].each do |group|
       group["items"].map!{|item| Foursquared::Response::User.new(client, item)}
    end
    return @followers
  end
end

#followingHash

Groups of pages this user user has liked or followed.

Returns:

  • (Hash)


148
149
150
151
152
153
154
155
156
# File 'lib/foursquared/response/user.rb', line 148

def following
  if response["following"] and response["following"]["groups"]
    @following = response["following"]
    @following["groups"].each do |group|
       group["items"].map!{|item| Foursquared::Response::User.new(client, item)}
    end
    return @following
  end
end

#friendsHash

User’s friends list retrieved from the initial response

Returns:

  • (Hash)

    count and groups of users



51
52
53
54
55
56
57
# File 'lib/foursquared/response/user.rb', line 51

def friends
  @friends = response["friends"]
  @friends["groups"].each do |group|
    group["items"].map!{|item| Foursquared::Response::User.new(client, item)}
  end
  @friends
end

#full_badgesHash

List user’s full badges

Returns:

  • (Hash)


202
203
204
# File 'lib/foursquared/response/user.rb', line 202

def full_badges
  client.user_badges(id)
end

#full_friends(options = {}) ⇒ Hash

User’s full friends list

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

    Number of results to return, up to 500.

  • :offset (Integer)

    Used to page through results.

Returns:

  • (Hash)

    A count and items of friends.



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

def full_friends options={}
  client.user_friends(id, options)
end

#full_lists(options = {}) ⇒ Hash

Return the user’s full lists

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :group (String)

    “edited”, “created”, “followed”, “friends” or “suggested”

  • :ll (String)

    Location of the user eg: 40.7,-74

Returns:

  • (Hash)


175
176
177
# File 'lib/foursquared/response/user.rb', line 175

def full_lists options={}
  client.user_lists(id, options)
end

#full_mayorshipsHash

List user’s full mayorships

Returns:

  • (Hash)


189
190
191
# File 'lib/foursquared/response/user.rb', line 189

def full_mayorships
  client.user_mayorships(id)
end

#genderString

User’s gender

Returns:

  • (String)


70
71
72
# File 'lib/foursquared/response/user.rb', line 70

def gender
  response["gender"]
end

#home_cityString

User’s home city

Returns:

  • (String)


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

def home_city
  response["homeCity"]
end

#idString

The user’s id

Returns:

  • (String)

    The user’s id



15
16
17
# File 'lib/foursquared/response/user.rb', line 15

def id
  response["id"]
end

#last_nameString

User’s last name

Returns:

  • (String)


27
28
29
# File 'lib/foursquared/response/user.rb', line 27

def last_name
  response["lastName"]
end

#listsHash

Return the user’s lists

Returns:

  • (Hash)


160
161
162
163
164
165
166
167
168
# File 'lib/foursquared/response/user.rb', line 160

def lists
  @lists = response["lists"]
  if @lists and @lists["groups"]
    @lists["groups"].each do |group|
      group["items"].map!{|item| Foursquared::Response::List.new(client, item)}
    end
  end
  @lists
end

#mayorshipsHash

List user’s mayorships

Returns:

  • (Hash)


181
182
183
184
185
# File 'lib/foursquared/response/user.rb', line 181

def mayorships
  @mayorships = response["mayorships"]
  @mayorships["items"].each{|item| item["venue"] = Foursquared::Response::Venue.new(client, item["venue"])}
  @mayorships
end

#nameString

User’s full name

Returns:

  • (String)


33
34
35
# File 'lib/foursquared/response/user.rb', line 33

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

#page_infoHash

Page details

Returns:

  • (Hash)

    Optional, Contains a detailed page, if the type is a page.



124
125
126
# File 'lib/foursquared/response/user.rb', line 124

def page_info
  response["pageInfo"]
end

#photoFoursquared::Response::Photo

User’s profile photo



39
40
41
# File 'lib/foursquared/response/user.rb', line 39

def photo
  Foursquared::Response::Photo.new(client, response["photo"])
end

#pingsBoolean

Whether we receive pings from this user, if we have a relationship.

Returns:

  • (Boolean)


94
95
96
# File 'lib/foursquared/response/user.rb', line 94

def pings
  response["pings"]
end

#refferal_idString

User’s refferal ID

Returns:

  • (String)


130
131
132
# File 'lib/foursquared/response/user.rb', line 130

def refferal_id
  response["refferalId"]
end

#relationshipString

User’s relationship with the acting user

Returns:

  • (String)


45
46
47
# File 'lib/foursquared/response/user.rb', line 45

def relationship
  response["relationship"]
end

#scoresHash

User’s current game status.

Returns:

  • (Hash)

    Contains recent, max, checkinsCount, and goal for showing user’s current game status.



100
101
102
# File 'lib/foursquared/response/user.rb', line 100

def scores
  response["scores"]
end

#send_friend_requestFoursquared::Response::User

Send a Friend/Follow Request to this user

Parameters:

  • user_id (String, Integer)

    The request user’s/page’s id

Returns:



223
224
225
226
# File 'lib/foursquared/response/user.rb', line 223

def send_friend_request
  request_response = post("/users/#{id}/request")["response"]
  @user = Foursquared::Response::User.new(client, request_response["userrequest_"])
end

#set_pings(options = {}) ⇒ Foursquared::Response::User

Set whether to receive pings about this user

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :value (Boolean)

    required, true or false.

Returns:



239
240
241
242
# File 'lib/foursquared/response/user.rb', line 239

def set_pings options={}
  request_response = post("/users/#{id}/setpings", options)["response"]
  @user = Foursquared::Response::User.new(client,request_response["user"])
end

#typeString

Type of user. Optional, Present for non-standard user types

Returns:

  • (String)

    One of page, chain, celebrity, or venuePage



106
107
108
# File 'lib/foursquared/response/user.rb', line 106

def type
  response["type"]
end

#unfriendFoursquared::Response::User

Removes a friend, unfollows a celebrity, or cancels a pending friend request.

Returns:



230
231
232
233
# File 'lib/foursquared/response/user.rb', line 230

def unfriend
  request_response = post("/users/#{id}/unfriend")["response"]
  @user = Foursquared::Response::User.new(client, request_response["user"])
end

#venueFoursquared::Response::Venue

Venue details

Returns:



112
113
114
# File 'lib/foursquared/response/user.rb', line 112

def venue
  Foursquared::Response::Venue.new(client, response["venue"]) if response["venue"]
end