Class: Attio::Resources::Deals Private
- Defined in:
- lib/attio/resources/deals.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Deals resource for managing sales opportunities
Instance Method Summary collapse
-
#create(data:) ⇒ Hash
private
Create a new deal.
-
#delete(id:) ⇒ Hash
private
Delete a deal.
-
#get(id:) ⇒ Hash
private
Get a specific deal.
-
#list(params = {}) ⇒ Hash
private
List all deals.
-
#list_by_company(company_id:, params: {}) ⇒ Hash
private
List deals by company.
-
#list_by_owner(owner_id:, params: {}) ⇒ Hash
private
List deals by owner.
-
#list_by_stage(stage_id:, params: {}) ⇒ Hash
private
List deals by stage.
-
#mark_lost(id:, lost_reason: nil, lost_date: nil) ⇒ Hash
private
Mark a deal as lost.
-
#mark_won(id:, won_date: nil, actual_value: nil) ⇒ Hash
private
Mark a deal as won.
-
#pipeline_value(stage_id: nil, owner_id: nil) ⇒ Hash
private
Calculate pipeline value.
-
#update(id:, data:) ⇒ Hash
private
Update a deal.
-
#update_stage(id:, stage_id:) ⇒ Hash
private
Update a deal's stage.
Constructor Details
This class inherits a constructor from Attio::Resources::Base
Instance Method Details
#create(data:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new deal
56 57 58 59 60 61 |
# File 'lib/attio/resources/deals.rb', line 56 def create(data:) validate_required_hash!(data, "Data") validate_required_string!(data[:name], "Deal name") request(:post, "objects/deals/records", { data: data }) end |
#delete(id:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delete a deal
79 80 81 82 |
# File 'lib/attio/resources/deals.rb', line 79 def delete(id:) validate_id!(id, "Deal") request(:delete, "objects/deals/records/#{id}") end |
#get(id:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a specific deal
39 40 41 42 |
# File 'lib/attio/resources/deals.rb', line 39 def get(id:) validate_id!(id, "Deal") request(:get, "objects/deals/records/#{id}") end |
#list(params = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List all deals
31 32 33 |
# File 'lib/attio/resources/deals.rb', line 31 def list(params = {}) request(:get, "objects/deals/records", params) end |
#list_by_company(company_id:, params: {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List deals by company
146 147 148 149 150 151 152 |
# File 'lib/attio/resources/deals.rb', line 146 def list_by_company(company_id:, params: {}) validate_required_string!(company_id, "Company") filter = { company_id: { "$eq" => company_id } } merged_params = params.merge(filter: filter) list(merged_params) end |
#list_by_owner(owner_id:, params: {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List deals by owner
159 160 161 162 163 164 165 |
# File 'lib/attio/resources/deals.rb', line 159 def list_by_owner(owner_id:, params: {}) validate_required_string!(owner_id, "Owner") filter = { owner_id: { "$eq" => owner_id } } merged_params = params.merge(filter: filter) list(merged_params) end |
#list_by_stage(stage_id:, params: {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List deals by stage
133 134 135 136 137 138 139 |
# File 'lib/attio/resources/deals.rb', line 133 def list_by_stage(stage_id:, params: {}) validate_required_string!(stage_id, "Stage") filter = { stage_id: { "$eq" => stage_id } } merged_params = params.merge(filter: filter) list(merged_params) end |
#mark_lost(id:, lost_reason: nil, lost_date: nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Mark a deal as lost
118 119 120 121 122 123 124 125 126 |
# File 'lib/attio/resources/deals.rb', line 118 def mark_lost(id:, lost_reason: nil, lost_date: nil) validate_id!(id, "Deal") data = { status: "lost" } data[:lost_reason] = lost_reason if lost_reason data[:lost_date] = lost_date if lost_date update(id: id, data: data) end |
#mark_won(id:, won_date: nil, actual_value: nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Mark a deal as won
102 103 104 105 106 107 108 109 110 |
# File 'lib/attio/resources/deals.rb', line 102 def mark_won(id:, won_date: nil, actual_value: nil) validate_id!(id, "Deal") data = { status: "won" } data[:won_date] = won_date if won_date data[:actual_value] = actual_value if actual_value update(id: id, data: data) end |
#pipeline_value(stage_id: nil, owner_id: nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Calculate pipeline value
172 173 174 175 176 177 178 179 180 |
# File 'lib/attio/resources/deals.rb', line 172 def pipeline_value(stage_id: nil, owner_id: nil) params = { filter: {} } params[:filter][:stage_id] = { "$eq" => stage_id } if stage_id params[:filter][:owner_id] = { "$eq" => owner_id } if owner_id # This would typically be a specialized endpoint, but we'll use list # and let the client calculate the statistics list(params) end |
#update(id:, data:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Update a deal
68 69 70 71 72 73 |
# File 'lib/attio/resources/deals.rb', line 68 def update(id:, data:) validate_id!(id, "Deal") validate_required_hash!(data, "Data") request(:patch, "objects/deals/records/#{id}", { data: data }) end |
#update_stage(id:, stage_id:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Update a deal's stage
89 90 91 92 93 94 |
# File 'lib/attio/resources/deals.rb', line 89 def update_stage(id:, stage_id:) validate_id!(id, "Deal") validate_required_string!(stage_id, "Stage") update(id: id, data: { stage_id: stage_id }) end |