Class: BaseCRM::LeadsService
- Inherits:
-
Object
- Object
- BaseCRM::LeadsService
- Defined in:
- lib/basecrm/services/leads_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:address, :custom_fields, :description, :email, :facebook, :fax, :first_name, :industry, :last_name, :linkedin, :mobile, :organization_name, :owner_id, :phone, :skype, :source_id, :status, :tags, :title, :twitter, :website]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all leads.
-
#create(lead) ⇒ Lead
Create a lead.
-
#destroy(id) ⇒ Boolean
Delete a lead.
-
#find(id) ⇒ Lead
Retrieve a single lead.
-
#initialize(client) ⇒ LeadsService
constructor
A new instance of LeadsService.
-
#update(lead) ⇒ Lead
Update a lead.
-
#where(options = {}) ⇒ Array<Lead>
Retrieve all leads.
Constructor Details
#initialize(client) ⇒ LeadsService
Returns a new instance of LeadsService.
7 8 9 |
# File 'lib/basecrm/services/leads_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all leads
get ‘/leads’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/leads_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(lead) ⇒ Lead
Create a lead
post ‘/leads’
Creates a new lead A lead may represent a single individual or an organization
59 60 61 62 63 64 65 66 |
# File 'lib/basecrm/services/leads_service.rb', line 59 def create(lead) validate_type!(lead) attributes = sanitize(lead) _, _, root = @client.post("/leads", attributes) Lead.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a lead
delete ‘/leads/BaseCRM#id’
Delete an existing lead If the specified lead does not exist, this query returns an error This operation cannot be undone
120 121 122 123 |
# File 'lib/basecrm/services/leads_service.rb', line 120 def destroy(id) status, _, _ = @client.delete("/leads/#{id}") status == 204 end |
#find(id) ⇒ Lead
Retrieve a single lead
get ‘/leads/BaseCRM#id’
Returns a single lead available to the user, according to the unique lead ID provided If the specified lead does not exist, this query returns an error
78 79 80 81 82 |
# File 'lib/basecrm/services/leads_service.rb', line 78 def find(id) _, _, root = @client.get("/leads/#{id}") Lead.new(root[:data]) end |
#update(lead) ⇒ Lead
Update a lead
put ‘/leads/BaseCRM#id’
Updates lead information If the specified lead does not exist, this query returns an error <figure class=“notice”> In order to modify tags, you need to supply the entire set of tags ‘tags` are replaced every time they are used in a request </figure>
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/basecrm/services/leads_service.rb', line 98 def update(lead) validate_type!(lead) params = extract_params!(lead, :id) id = params[:id] attributes = sanitize(lead) _, _, root = @client.put("/leads/#{id}", attributes) Lead.new(root[:data]) end |
#where(options = {}) ⇒ Array<Lead>
Retrieve all leads
get ‘/leads’
Returns all leads available to the user, according to the parameters provided
43 44 45 46 47 |
# File 'lib/basecrm/services/leads_service.rb', line 43 def where( = {}) _, _, root = @client.get("/leads", ) root[:items].map{ |item| Lead.new(item[:data]) } end |