Class: BaseCRM::LossReasonsService

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

Constant Summary collapse

OPTS_KEYS_TO_PERSIST =
Set[:name]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ LossReasonsService

Returns a new instance of LossReasonsService.


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

def initialize(client)
  @client = client
end

Instance Method Details

#allEnumerable

Retrieve all reasons

get '/loss_reasons'

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/loss_reasons_service.rb', line 17

def all
  PaginatedResource.new(self)
end

#create(loss_reason) ⇒ LossReason

Create a loss reason

post '/loss_reasons'

Create a new loss reason <figure class=“notice”> Loss reason's name *must* be unique </figure>

Parameters:

  • loss_reason (LossReason, Hash)

    Either object of the LossReason type or Hash. This object's attributes describe the object to be created.

Returns:

  • (LossReason)

    The resulting object represting created resource.


52
53
54
55
56
57
58
59
# File 'lib/basecrm/services/loss_reasons_service.rb', line 52

def create(loss_reason)
  validate_type!(loss_reason)

  attributes = sanitize(loss_reason)
  _, _, root = @client.post("/loss_reasons", attributes)

  LossReason.new(root[:data])
end

#destroy(id) ⇒ Boolean

Delete a reason

delete '/loss_reasons/id'

Delete an existing loss reason If the reason with supplied unique identifier does not exist it returns an error This operation cannot be undone

Parameters:

  • id (Integer)

    Unique identifier of a LossReason

Returns:

  • (Boolean)

    Status of the operation.


112
113
114
115
# File 'lib/basecrm/services/loss_reasons_service.rb', line 112

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

#find(id) ⇒ LossReason

Retrieve a single reason

get '/loss_reasons/id'

Returns a single loss reason available to the user by the provided id If a loss reason with the supplied unique identifier does not exist, it returns an error

Parameters:

  • id (Integer)

    Unique identifier of a LossReason

Returns:


71
72
73
74
75
# File 'lib/basecrm/services/loss_reasons_service.rb', line 71

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

  LossReason.new(root[:data])
end

#update(loss_reason) ⇒ LossReason

Update a loss reason

put '/loss_reasons/id'

Updates a loss reason information If the specified loss reason does not exist, the request will return an error <figure class=“notice”> If you want to update loss reason you *must* make sure name of the reason is unique </figure>

Parameters:

  • loss_reason (LossReason, Hash)

    Either object of the LossReason type or Hash. This object's attributes describe the object to be updated.

Returns:

  • (LossReason)

    The resulting object represting updated resource.


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

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

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

  LossReason.new(root[:data])
end

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

Retrieve all reasons

get '/loss_reasons'

Returns all deal loss reasons available to the user according to the parameters provided

Parameters:

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

    Search options

Options Hash (options):

  • :ids (String)

    Comma separated list of deal loss reasons unique identifiers to be returned in a request.

  • :name (String)

    Name of the loss reason to search for. This parameter is used in a strict sense.

  • :page (Integer) — default: 1

    Page number to start from. Page numbering is 1-based and omitting `page` parameter will return the first page.

  • :per_page (Integer) — default: 25

    Number of records to return per page. Default limit is 25 and maximum number that can be returned is 100.

  • :sort_by (String) — default: id: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=name:desc`.

Returns:

  • (Array<LossReason>)

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


34
35
36
37
38
# File 'lib/basecrm/services/loss_reasons_service.rb', line 34

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

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