Class: BaseCRM::LossReasonsService
- Inherits:
-
Object
- Object
- BaseCRM::LossReasonsService
- Defined in:
- lib/basecrm/services/loss_reasons_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:name]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all reasons.
-
#create(loss_reason) ⇒ LossReason
Create a loss reason.
-
#destroy(id) ⇒ Boolean
Delete a reason.
-
#find(id) ⇒ LossReason
Retrieve a single reason.
-
#initialize(client) ⇒ LossReasonsService
constructor
A new instance of LossReasonsService.
-
#update(loss_reason) ⇒ LossReason
Update a loss reason.
-
#where(options = {}) ⇒ Array<LossReason>
Retrieve all reasons.
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
#all ⇒ Enumerable
Retrieve all reasons
get ‘/loss_reasons’
If you want to use filtering or sorting (see #where).
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>
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/BaseCRM#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
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/BaseCRM#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
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/BaseCRM#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>
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
34 35 36 37 38 |
# File 'lib/basecrm/services/loss_reasons_service.rb', line 34 def where( = {}) _, _, root = @client.get("/loss_reasons", ) root[:items].map{ |item| LossReason.new(item[:data]) } end |