Module: Pinterest::Endpoints::Pins
- Included in:
- Client
- Defined in:
- lib/pinterest/endpoints/pins.rb
Overview
Pins related endpoints.
Instance Method Summary collapse
-
#board_pins(board, fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of pins of a board of the authenticated user.
-
#create_pin(board, image, note: nil, link: nil, fields: nil) ⇒ Pinterest::User
Creates a new pin.
-
#delete_pin(pin) ⇒ Boolean
Deletes a pin.
-
#edit_pin(pin, board: nil, note: nil, link: nil, fields: nil) ⇒ Pinterest::User
Edits a pin.
-
#likes(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of liked pins of the authenticated user.
-
#pin(pin, fields: nil) ⇒ Pinterest::User
Returns information about a pin.
-
#pins(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of pins of the authenticated user.
-
#search_my_pins(query = "", fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Search between of pins of the authenticated user.
Instance Method Details
#board_pins(board, fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of pins of a board of the authenticated user.
118 119 120 121 |
# 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 |
#create_pin(board, image, note: nil, link: nil, fields: nil) ⇒ Pinterest::User
Creates a new pin.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |
#delete_pin(pin) ⇒ Boolean
Deletes a pin.
80 81 82 83 84 85 86 87 |
# 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 |
#edit_pin(pin, board: nil, note: nil, link: nil, fields: nil) ⇒ Pinterest::User
Edits a pin.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |
#likes(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of liked pins of the authenticated user.
129 130 131 |
# 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 |
#pin(pin, fields: nil) ⇒ Pinterest::User
Returns information about a pin.
15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
#pins(fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Returns the list of pins of the authenticated user.
95 96 97 |
# 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_my_pins(query = "", fields: nil, cursor: nil, limit: nil) ⇒ Pinterest::Collection
Search between of pins of the authenticated user.
106 107 108 109 |
# 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 |