Module: Pinterest::Endpoints::Boards
- Included in:
- Client
- Defined in:
- lib/pinterest/endpoints/boards.rb
Overview
Boards related endpoints.
Instance Method Summary collapse
-
#board(board, fields: nil) ⇒ Pinterest::Board
Returns information about a board.
-
#boards(fields: nil) ⇒ Pinterest::Collection
Returns the list of the boards of the authenticated user.
-
#create_board(name, description = "", fields: nil) ⇒ Pinterest::Board
Creates a new board.
-
#delete_board(board) ⇒ Boolean
Deletes a board.
-
#edit_board(board, name: nil, description: nil, fields: nil) ⇒ Pinterest::Board
Edits a board.
-
#follow_board(board) ⇒ Boolean
Follows a board.
-
#following_boards(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of boards followed by the authenticated user.
-
#search_my_boards(query, fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Search between of boards of the authenticated user.
-
#suggested_boards(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of boards of suggested boards for the authenticated user.
-
#unfollow_board(board) ⇒ Boolean
Stop following a board.
Instance Method Details
#board(board, fields: nil) ⇒ Pinterest::Board
Returns information about a board.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pinterest/endpoints/boards.rb', line 15 def board(board, fields: nil) # Validate the board id board = validate_board(board) # Ensure only valid fields are used fields = ensure_board_fields(fields) # Perform the request and create the board data = perform_network_request(url: versioned_url("/boards/#{board}/"), query: cleanup_params({fields: fields.join(",")})).body["data"] ::Pinterest::Board.create(data) end |
#boards(fields: nil) ⇒ Pinterest::Collection
Returns the list of the boards of the authenticated user. Pagination is not supported by Pinterest API.
31 32 33 |
# File 'lib/pinterest/endpoints/boards.rb', line 31 def boards(fields: nil) get_boards_collection("/me/boards/", nil, fields) end |
#create_board(name, description = "", fields: nil) ⇒ Pinterest::Board
Creates a new board.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pinterest/endpoints/boards.rb', line 41 def create_board(name, description = "", fields: nil) # Validate name ensure_param(name, "You have to specify the board name.") # Ensure only valid fields are used fields = ensure_board_fields(fields) # Create the board data = perform_network_request( method: "POST", url: versioned_url("/boards/"), query: cleanup_params({fields: fields.join(",")}), body: cleanup_params({name: name, description: description}) ) # Wrap in a object ::Pinterest::Board.create(data.body["data"]) end |
#delete_board(board) ⇒ Boolean
Deletes a board.
89 90 91 92 93 94 95 96 |
# File 'lib/pinterest/endpoints/boards.rb', line 89 def delete_board(board) # Validate the board id board = validate_board(board) # Perform the request perform_network_request(method: "DELETE", url: versioned_url("/boards/#{board}/")) true end |
#edit_board(board, name: nil, description: nil, fields: nil) ⇒ Pinterest::Board
Edits a board.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pinterest/endpoints/boards.rb', line 66 def edit_board(board, name: nil, description: nil, fields: nil) # Validate the board id raise(ArgumentError, "You have to specify a board or its id.") unless board board = board.id if board.is_a?(::Pinterest::Board) # Ensure only valid fields are used fields = ensure_board_fields(fields) # Create the board data = perform_network_request( method: "PATCH", url: versioned_url("/boards/#{board}/"), query: cleanup_params(fields: fields.join(",")), body: cleanup_params({name: name, description: description}) ) # Wrap in a object ::Pinterest::Board.create(data.body["data"]) end |
#follow_board(board) ⇒ Boolean
Follows a board.
134 135 136 137 138 139 140 141 |
# File 'lib/pinterest/endpoints/boards.rb', line 134 def follow_board(board) # Validate the board id board = validate_board(board) # Perform the request perform_network_request(method: "POST", query: {board: board}, url: versioned_url("/me/following/boards/")) true end |
#following_boards(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of boards followed by the authenticated user.
126 127 128 |
# File 'lib/pinterest/endpoints/boards.rb', line 126 def following_boards(fields: nil, cursor: nil, limit: nil) get_boards_collection("/me/following/boards/", nil, fields, cursor, limit) end |
#search_my_boards(query, fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Search between of boards of the authenticated user.
105 106 107 108 |
# File 'lib/pinterest/endpoints/boards.rb', line 105 def search_my_boards(query, fields: nil, cursor: nil, limit: nil) ensure_param(query, "You have to specify a query.") get_boards_collection("/me/search/boards/", {query: query}, fields, cursor, limit) end |
#suggested_boards(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of boards of suggested boards for the authenticated user.
116 117 118 |
# File 'lib/pinterest/endpoints/boards.rb', line 116 def suggested_boards(fields: nil, cursor: nil, limit: nil) get_boards_collection("/me/boards/suggested/", nil, fields, cursor, limit) end |
#unfollow_board(board) ⇒ Boolean
Stop following a board.
147 148 149 150 151 152 153 154 |
# File 'lib/pinterest/endpoints/boards.rb', line 147 def unfollow_board(board) # Validate the board id board = validate_board(board) # Perform the request perform_network_request(method: "DELETE", url: versioned_url("/me/following/boards/#{board}/")) true end |