Module: X::Resources::Actions::Lists

Included in:
X::Resources::API
Defined in:
x-resources/lib/x/resources/actions/lists.rb

Overview

Create, update, delete, follow, and pin lists as the authenticated user

Internal to x-resources: X::Resources::API includes it, and its methods are public API of the client that includes API, but the module is only how they are grouped, and some of them need the methods of another, so include API rather than this module alone.

Instance Method Summary collapse

Instance Method Details

#add_list_member(list, user) ⇒ Boolean

Add a member to a list as the authenticated user

Examples:

Add a member to a list

client.add_list_member("1234567890", user)

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

  • user (User, String, Integer) —

    the user or their identifier

Returns:

  • (Boolean) —

    true if the user is now a member



64
65
66
# File 'x-resources/lib/x/resources/actions/lists.rb', line 64

def add_list_member(list, user)
  List.from_id(list, client: self).add_member(user)
end

#create_list(name, **params) ⇒ List

Create a list owned by the authenticated user

Examples:

Create a private list

client.create_list("Rubyists", private: true)

Parameters:

  • name (String) —

    the name of the list

  • params (Hash) —

    additional request body fields: description and private

Returns:

  • (List) —

    the created list, holding only its identifier and name

Raises:



28
29
30
# File 'x-resources/lib/x/resources/actions/lists.rb', line 28

def create_list(name, **params)
  List.create(name, client: self, **params)
end

#delete_list(list) ⇒ Boolean

Delete a list as the authenticated user

Examples:

Delete a list

client.delete_list("1234567890")

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

Returns:

  • (Boolean) —

    true if the list was deleted



52
53
54
# File 'x-resources/lib/x/resources/actions/lists.rb', line 52

def delete_list(list)
  List.delete(list, client: self)
end

#follow_list(list) ⇒ Boolean

Follow a list as the authenticated user

Examples:

Follow a list

client.follow_list("1234567890")

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user now follows the list



87
88
89
# File 'x-resources/lib/x/resources/actions/lists.rb', line 87

def follow_list(list)
  RelationWrites.relate(self, current_user_id, "followed_lists", {"list_id" => Utils.id_of(list, List)}, "following")
end

#pin_list(list) ⇒ Boolean

Pin a list as the authenticated user

Examples:

Pin a list

client.pin_list("1234567890")

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user has pinned the list



109
110
111
# File 'x-resources/lib/x/resources/actions/lists.rb', line 109

def pin_list(list)
  RelationWrites.relate(self, current_user_id, "pinned_lists", {"list_id" => Utils.id_of(list, List)}, "pinned")
end

#remove_list_member(list, user) ⇒ Boolean

Remove a member from a list as the authenticated user

Examples:

Remove a member from a list

client.remove_list_member("1234567890", user)

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

  • user (User, String, Integer) —

    the user or their identifier

Returns:

  • (Boolean) —

    true if the user is no longer a member



76
77
78
# File 'x-resources/lib/x/resources/actions/lists.rb', line 76

def remove_list_member(list, user)
  List.from_id(list, client: self).remove_member(user)
end

#unfollow_list(list) ⇒ Boolean

Unfollow a list as the authenticated user

Examples:

Unfollow a list

client.unfollow_list("1234567890")

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user no longer follows the list



98
99
100
# File 'x-resources/lib/x/resources/actions/lists.rb', line 98

def unfollow_list(list)
  RelationWrites.unrelate(self, current_user_id, "followed_lists", Utils.id_of(list, List), "following")
end

#unpin_list(list) ⇒ Boolean

Unpin a list as the authenticated user

Examples:

Unpin a list

client.unpin_list("1234567890")

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user no longer has the list pinned



120
121
122
# File 'x-resources/lib/x/resources/actions/lists.rb', line 120

def unpin_list(list)
  RelationWrites.unrelate(self, current_user_id, "pinned_lists", Utils.id_of(list, List), "pinned")
end

#update_list(list, **params) ⇒ Boolean

Update the name, description, or privacy of a list as the authenticated user

Examples:

Make a list private

client.update_list("1234567890", private: true)

Parameters:

  • list (List, String, Integer) —

    the list or its identifier

  • params (Hash) —

    the request body fields to change: name, description, and private

Returns:

  • (Boolean) —

    true if the list was updated

Raises:

  • (ArgumentError) —

    if no field is given to change, before any request



41
42
43
# File 'x-resources/lib/x/resources/actions/lists.rb', line 41

def update_list(list, **params)
  List.update(list, client: self, **params)
end