Class: BaseCRM::DealsService
- Inherits:
-
Object
- Object
- BaseCRM::DealsService
- Defined in:
- lib/basecrm/services/deals_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:contact_id, :currency, :custom_fields, :hot, :loss_reason_id, :unqualified_reason_id, :name, :owner_id, :source_id, :stage_id, :tags, :value, :last_stage_change_at, :estimated_close_date, :customized_win_likelihood, :added_on]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all deals.
-
#create(deal) ⇒ Deal
Create a deal.
-
#destroy(id) ⇒ Boolean
Delete a deal.
-
#find(id) ⇒ Deal
Retrieve a single deal.
-
#initialize(client) ⇒ DealsService
constructor
A new instance of DealsService.
-
#update(deal) ⇒ Deal
Update a deal.
-
#where(options = {}) ⇒ Array<Deal>
Retrieve all deals.
Constructor Details
#initialize(client) ⇒ DealsService
Returns a new instance of DealsService.
9 10 11 |
# File 'lib/basecrm/services/deals_service.rb', line 9 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all deals
get ‘/deals’
If you want to use filtering or sorting (see #where).
19 20 21 |
# File 'lib/basecrm/services/deals_service.rb', line 19 def all PaginatedResource.new(self) end |
#create(deal) ⇒ Deal
Create a deal
post ‘/deals’
Create a new deal
58 59 60 61 62 63 64 65 |
# File 'lib/basecrm/services/deals_service.rb', line 58 def create(deal) validate_type!(deal) attributes = sanitize(deal) _, _, root = @client.post("/deals", attributes) Deal.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a deal
delete ‘/deals/BaseCRM#id’
Delete an existing deal and remove all of the associated contacts from the deal in a single call If the specified deal does not exist, the request will return an error This operation cannot be undone
119 120 121 122 |
# File 'lib/basecrm/services/deals_service.rb', line 119 def destroy(id) status, _, _ = @client.delete("/deals/#{id}") status == 204 end |
#find(id) ⇒ Deal
Retrieve a single deal
get ‘/deals/BaseCRM#id’
Returns a single deal available to the user, according to the unique deal ID provided If the specified deal does not exist, the request will return an error
77 78 79 80 81 |
# File 'lib/basecrm/services/deals_service.rb', line 77 def find(id) _, _, root = @client.get("/deals/#{id}") Deal.new(root[:data]) end |
#update(deal) ⇒ Deal
Update a deal
put ‘/deals/BaseCRM#id’
Updates deal information If the specified deal does not exist, the request will return an error <figure class=“notice”> In order to modify tags used on a record, you need to supply the entire set ‘tags` are replaced every time they are used in a request </figure>
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/basecrm/services/deals_service.rb', line 97 def update(deal) validate_type!(deal) params = extract_params!(deal, :id) id = params[:id] attributes = sanitize(deal) _, _, root = @client.put("/deals/#{id}", attributes) Deal.new(root[:data]) end |
#where(options = {}) ⇒ Array<Deal>
Retrieve all deals
get ‘/deals’
Returns all deals available to the user according to the parameters provided
43 44 45 46 47 |
# File 'lib/basecrm/services/deals_service.rb', line 43 def where( = {}) _, _, root = @client.get("/deals", ) root[:items].map{ |item| Deal.new(item[:data]) } end |