module Pinterest::Endpoints::Pins
Pins
related endpoints.
Public Instance Methods
Returns the list of pins of a board of the authenticated user.
@param board [Fixnum|String] The board path (username/id) or id. @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 pin objects.
# File lib/pinterest/endpoints/pins.rb, line 118 def board_pins(board, fields: nil, cursor: nil, limit: nil) validate_board(board) get_pins_collection("/boards/#{board}/pins/", nil, fields, cursor, limit) end
Creates a new pin.
@param board [String] The board path (username/id) or id. @param image [String] The image to pin. @param note [String] The note to attach to the pin. @param link [String] The link to attach to the pin. @param fields [Array] A list of fields to return. @return [Pinterest::User] The new created pin object.
# File lib/pinterest/endpoints/pins.rb, line 35 def create_pin(board, image, note: nil, link: nil, fields: nil) board = validate_board(board) # Ensure only valid fields are used fields = ensure_pin_fields(fields) # Create the payload payload = {note: note, board: board, link: link} # Add the image - Try to detect whether is a URL or a path payload.merge!(add_image(image)) # Perform the request and create the pin data = perform_network_request(method: "POST", url: versioned_url("/pins/"), query: cleanup_params({fields: fields.join(",")}), body: payload) ::Pinterest::Pin.create(data.body["data"]) end
Deletes a pin.
@param pin [String] The pin id. @return [Boolean] `true` if operation succeeded, `false` otherwise.
# File lib/pinterest/endpoints/pins.rb, line 80 def delete_pin(pin) # Validate the board id pin = validate_pin(pin) # Perform the request perform_network_request(method: "DELETE", url: versioned_url("/pins/#{pin}/")) true end
Edits a pin.
@param pin [String] The pin id. @param board [String] The new board path (username/id) or id. @param note [String] The new note to attach to the pin. @param link [String] The new link to attach to the pin. @param fields [Array] A list of fields to return. @return [Pinterest::User] The updated pin object.
# File lib/pinterest/endpoints/pins.rb, line 61 def edit_pin(pin, board: nil, note: nil, link: nil, fields: nil) pin = validate_pin(pin) board = validate_board(board) if board # Ensure only valid fields are used fields = ensure_pin_fields(fields) # Create the payload payload = cleanup_params({note: note, board: board, link: link}) # Perform the request and create the pin data = perform_network_request(method: "PATCH", url: versioned_url("/pins/#{pin}/"), query: cleanup_params({fields: fields.join(",")}), body: payload) ::Pinterest::Pin.create(data.body["data"]) end
Returns the list of liked pins of 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 pin objects.
# File lib/pinterest/endpoints/pins.rb, line 129 def likes(fields: nil, cursor: nil, limit: nil) get_pins_collection("/me/likes/", nil, fields, cursor, limit) end
Returns information about a pin.
@param pin [Fixnum|String] The pin id. @param fields [Array] A list of fields to return. @return [Pinterest::User] A pin object.
# File lib/pinterest/endpoints/pins.rb, line 15 def pin(pin, fields: nil) # Validate the pin id pin = validate_pin(pin) # Ensure only valid fields are used fields = ensure_pin_fields(fields) # Perform the request and create the pin data = perform_network_request(url: versioned_url("/pins/#{pin}/"), query: cleanup_params({fields: fields.join(",")})).body["data"] ::Pinterest::Pin.create(data) end
Returns the list of pins of 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 pin objects.
# File lib/pinterest/endpoints/pins.rb, line 95 def pins(fields: nil, cursor: nil, limit: nil) get_pins_collection("/me/pins/", nil, fields, cursor, limit) end
Search between of pins of the authenticated user.
@param query [String] The query to perform. @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 pin objects.
# File lib/pinterest/endpoints/pins.rb, line 106 def search_my_pins(query = "", fields: nil, cursor: nil, limit: nil) ensure_param(query, "You have to specify a query.") get_pins_collection("/me/search/pins/", {query: query}, fields, cursor, limit) end