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, :name, :owner_id, :source_id, :stage_id, :tags, :value, :last_stage_change_at]
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.
7 8 9 |
# File 'lib/basecrm/services/deals_service.rb', line 7 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).
17 18 19 |
# File 'lib/basecrm/services/deals_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(deal) ⇒ Deal
Create a deal
post ‘/deals’
Create a new deal
55 56 57 58 59 60 61 62 |
# File 'lib/basecrm/services/deals_service.rb', line 55 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
116 117 118 119 |
# File 'lib/basecrm/services/deals_service.rb', line 116 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
74 75 76 77 78 |
# File 'lib/basecrm/services/deals_service.rb', line 74 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>
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/basecrm/services/deals_service.rb', line 94 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
40 41 42 43 44 |
# File 'lib/basecrm/services/deals_service.rb', line 40 def where( = {}) _, _, root = @client.get("/deals", ) root[:items].map{ |item| Deal.new(item[:data]) } end |