Class: BaseCRM::NotesService

Inherits:
Object
  • Object
show all
Defined in:
lib/basecrm/services/notes_service.rb

Constant Summary collapse

OPTS_KEYS_TO_PERSIST =
Set[:content, :resource_id, :resource_type]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ NotesService

Returns a new instance of NotesService.



7
8
9
# File 'lib/basecrm/services/notes_service.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#allEnumerable

Retrieve all notes

get ‘/notes’

If you want to use filtering or sorting (see #where).

Returns:

  • (Enumerable)

    Paginated resource you can use to iterate over all the resources.



17
18
19
# File 'lib/basecrm/services/notes_service.rb', line 17

def all
  PaginatedResource.new(self)
end

#create(note) ⇒ Note

Create a note

post ‘/notes’

Create a new note and associate it with one of the resources listed below:

  • [Leads](/docs/rest/reference/leads)

  • [Contacts](/docs/rest/reference/contacts)

  • [Deals](/docs/rest/reference/deals)

Parameters:

  • note (Note, Hash)

    Either object of the Note type or Hash. This object’s attributes describe the object to be created.

Returns:

  • (Note)

    The resulting object represting created resource.



56
57
58
59
60
61
62
63
# File 'lib/basecrm/services/notes_service.rb', line 56

def create(note)
  validate_type!(note)

  attributes = sanitize(note)
  _, _, root = @client.post("/notes", attributes)

  Note.new(root[:data])
end

#destroy(id) ⇒ Boolean

Delete a note

delete ‘/notes/BaseCRM#id

Delete an existing note If the note ID does not exist, this request will return an error This operation cannot be undone

Parameters:

  • id (Integer)

    Unique identifier of a Note

Returns:

  • (Boolean)

    Status of the operation.



113
114
115
116
# File 'lib/basecrm/services/notes_service.rb', line 113

def destroy(id)
  status, _, _ = @client.delete("/notes/#{id}")
  status == 204
end

#find(id) ⇒ Note

Retrieve a single note

get ‘/notes/BaseCRM#id

Returns a single note available to the user, according to the unique note ID provided If the note ID does not exist, this request will return an error

Parameters:

  • id (Integer)

    Unique identifier of a Note

Returns:

  • (Note)

    Searched resource object.



75
76
77
78
79
# File 'lib/basecrm/services/notes_service.rb', line 75

def find(id)
  _, _, root = @client.get("/notes/#{id}")

  Note.new(root[:data])
end

#update(note) ⇒ Note

Update a note

put ‘/notes/BaseCRM#id

Updates note information If the note ID does not exist, this request will return an error

Parameters:

  • note (Note, Hash)

    Either object of the Note type or Hash. This object’s attributes describe the object to be updated.

Returns:

  • (Note)

    The resulting object represting updated resource.



91
92
93
94
95
96
97
98
99
100
# File 'lib/basecrm/services/notes_service.rb', line 91

def update(note)
  validate_type!(note)
  params = extract_params!(note, :id)
  id = params[:id]

  attributes = sanitize(note)
  _, _, root = @client.put("/notes/#{id}", attributes)

  Note.new(root[:data])
end

#where(options = {}) ⇒ Array<Note>

Retrieve all notes

get ‘/notes’

Returns all notes available to the user, according to the parameters provided

Parameters:

  • options (Hash) (defaults to: {})

    Search options

Options Hash (options):

  • :creator_id (Integer)

    Unique identifier of the user. Returns all notes created by the user.

  • :ids (String)

    Comma-separated list of note IDs to be returned in a request.

  • :includes (String)

    Comma-separated list of one or more resources related to the note. **Not supported at the moment**.

  • :page (Integer) — default: 1

    Page number to start from. Page numbering starts at 1, and omitting the ‘page` parameter will return the first page.

  • :per_page (Integer) — default: 25

    Number of records to return per page. The default limit is 25 and the maximum number that can be returned at one time is 100.

  • :q (String)

    A query string to search for. Performs a full text search on the ‘content` field.

  • :resource_id (Integer)

    Unique identifier of the resource to search for.

  • :resource_type (String)

    Name of the type of resource to search for.

  • :sort_by (String) — default: updated_at:asc

    A field to sort by. Default ordering is ascending. If you want to change the sort ordering to descending, append ‘:desc` to the field e.g. `sort_by=resource_type:desc`.

Returns:

  • (Array<Note>)

    The list of Notes for the first page, unless otherwise specified.



38
39
40
41
42
# File 'lib/basecrm/services/notes_service.rb', line 38

def where(options = {})
  _, _, root = @client.get("/notes", options)

  root[:items].map{ |item| Note.new(item[:data]) }
end