module Pinterest::Endpoints::Users

Users related endpoints.

Public Instance Methods

follow_interest(interest) click to toggle source

Starts following a interest.

@param interest [Fixnum|String] The interest id. @return [Boolean] `true` if operation succeeded, `false` otherwise. NOTE: This is currently returning 405 on the platform. Review ASAP.

# File lib/pinterest/endpoints/users.rb, line 103
def follow_interest(interest)
  # Validate the interest id
  raise(ArgumentError, "You have to specify a interest or its id.") unless interest
  interest = interest.id if interest.is_a?(::Pinterest::Interest)

  # Perform the request
  perform_network_request(method: "POST", query: {interest: interest}, url: versioned_url("/me/following/interests/"))
end
follow_user(user) click to toggle source

Follows a user.

@param user [Fixnum|String] The username or user id. @return [Boolean] `true` if operation succeeded, `false` otherwise.

# File lib/pinterest/endpoints/users.rb, line 60
def follow_user(user)
  # Validate the user id
  user = validate_user(user)

  # Perform the request
  perform_network_request(method: "POST", body: {user: user}, url: versioned_url("/me/following/users/"))
  true
end
followers(fields: nil, cursor: nil, limit: nil) click to toggle source

Returns the list of users who follow the authenticated user.

@param fields [Array] A list of fields to return. @param cursor [String] A cursor to paginate results, obtained by a previous call. @param limit [Fixnum] The maximum number of objects to return. @return [Pinterest::Collection] An collection of user objects.

# File lib/pinterest/endpoints/users.rb, line 42
def followers(fields: nil, cursor: nil, limit: nil)
  get_users_collection("/me/followers/", fields, cursor, limit)
end
following_users(fields: nil, cursor: nil, limit: nil) click to toggle source

Returns the list of users followed by the authenticated user.

@param fields [Array] A list of fields to return. @param cursor [String] A cursor to paginate results, obtained by a previous call. @param limit [Fixnum] The maximum number of objects to return. @return [Pinterest::Collection] An collection of user objects.

# File lib/pinterest/endpoints/users.rb, line 52
def following_users(fields: nil, cursor: nil, limit: nil)
  get_users_collection("/me/following/users/", fields, cursor, limit)
end
interests(cursor: nil, limit: nil) click to toggle source

Returns the list of interests (topics) followed by the authenticated user.

@param cursor [String] A cursor to paginate results, obtained by a previous call. @param limit [Fixnum] The maximum number of objects to return. @return [Pinterest::Collection] An collection of interest objects.

# File lib/pinterest/endpoints/users.rb, line 87
def interests(cursor: nil, limit: nil)
  # Perform request
  data = perform_network_request(
    url: versioned_url("/me/following/interests/"),
    pagination: true, cursor: cursor, limit: limit
  )

  # Create the collection
  ::Pinterest::Collection.new(data.body, cursor, limit) { |interest| ::Pinterest::Interest.create(interest) }
end
me(fields: nil) click to toggle source

Returns information about the authenticated user.

@param fields [Array] A list of fields to return. @return [Pinterest::User] A user object.

# File lib/pinterest/endpoints/users.rb, line 14
def me(fields: nil)
  fields = ensure_user_fields(fields)

  # Perform request and create the user
  data = perform_network_request(url: versioned_url("/me/"), query: cleanup_params({fields: fields.join(",")}))
  ::Pinterest::User.create(data.body["data"])
end
unfollow_interest(interest) click to toggle source

Stops following a interest.

@param interest [Fixnum|String] The interest id. @return [Boolean] `true` if operation succeeded, `false` otherwise. NOTE: This is currently returning 404 on the platform. Review ASAP.

# File lib/pinterest/endpoints/users.rb, line 117
def unfollow_interest(interest)
  # Validate the interest id
  raise(ArgumentError, "You have to specify a interest or its id.") unless interest
  interest = interest.id if interest.is_a?(::Pinterest::Interest)

  # Perform the request
  perform_network_request(method: "DELETE", url: versioned_url("/me/following/interests/#{interest}/"))
end
unfollow_user(user) click to toggle source

Stops following a user.

@param user [Fixnum|String] The username or user id. @return [Boolean] `true` if operation succeeded, `false` otherwise.

# File lib/pinterest/endpoints/users.rb, line 73
def unfollow_user(user)
  # Validate the user id
  user = validate_user(user)

  # Perform the request
  perform_network_request(method: "DELETE", url: versioned_url("/me/following/users/#{user}/"))
  true
end
user(user, fields: nil) click to toggle source

Returns information about a user.

@param user [Fixnum|String] The username or user id. @param fields [Array] A list of fields to return. @return [Pinterest::User] A user object.

# File lib/pinterest/endpoints/users.rb, line 27
def user(user, fields: nil)
  user = validate_user(user)
  fields = ensure_user_fields(fields)

  # Perform request and create the user
  data = perform_network_request(url: versioned_url("/users/#{user}/"), query: cleanup_params({fields: fields.join(",")}))
  ::Pinterest::User.create(data.body["data"])
end