Module: Pinterest::Endpoints::Pins

Included in:
Client
Defined in:
lib/pinterest/endpoints/pins.rb

Overview

Pins related endpoints.

Instance Method Summary collapse

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.

Parameters:

  • board (Fixnum|String)

    The board path (username/id) or id.

  • fields (Array)

    A list of fields to return.

  • cursor (String)

    A cursor to paginate results, obtained by a previous call.

  • limit (Fixnum)

    The maximum number of objects to return.

Returns:



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.

Parameters:

  • board (String)

    The board path (username/id) or id.

  • image (String)

    The image to pin.

  • note (String)

    The note to attach to the pin.

  • link (String)

    The link to attach to the pin.

  • fields (Array)

    A list of fields to return.

Returns:



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.

Parameters:

  • pin (String)

    The pin id.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



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.

Parameters:

  • pin (String)

    The pin id.

  • board (String)

    The new board path (username/id) or id.

  • note (String)

    The new note to attach to the pin.

  • link (String)

    The new link to attach to the pin.

  • fields (Array)

    A list of fields to return.

Returns:



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.

Parameters:

  • fields (Array)

    A list of fields to return.

  • cursor (String)

    A cursor to paginate results, obtained by a previous call.

  • limit (Fixnum)

    The maximum number of objects to return.

Returns:



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.

Parameters:

  • pin (Fixnum|String)

    The pin id.

  • fields (Array)

    A list of fields to return.

Returns:



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.

Parameters:

  • fields (Array)

    A list of fields to return.

  • cursor (String)

    A cursor to paginate results, obtained by a previous call.

  • limit (Fixnum)

    The maximum number of objects to return.

Returns:



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.

Parameters:

  • query (String) (defaults to: "")

    The query to perform.

  • fields (Array)

    A list of fields to return.

  • cursor (String)

    A cursor to paginate results, obtained by a previous call.

  • limit (Fixnum)

    The maximum number of objects to return.

Returns:



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