Class: BaseCRM::LeadSourcesService
- Inherits:
-
Object
- Object
- BaseCRM::LeadSourcesService
- Defined in:
- lib/basecrm/services/lead_sources_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:name, :resource_type]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all sources.
-
#create(lead_source) ⇒ LeadSource
Create a new source.
-
#destroy(id) ⇒ Boolean
Delete a source.
-
#find(id) ⇒ LeadSource
Retrieve a single source.
-
#initialize(client) ⇒ LeadSourcesService
constructor
A new instance of LeadSourcesService.
-
#update(lead_source) ⇒ LeadSource
Update a source.
-
#where(options = {}) ⇒ Array<LeadSource>
Retrieve all sources.
Constructor Details
#initialize(client) ⇒ LeadSourcesService
Returns a new instance of LeadSourcesService.
7 8 9 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all sources
get ‘/lead_sources’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(lead_source) ⇒ LeadSource
Create a new source
post ‘/lead_sources’
Creates a new source <figure class=“notice”> Source’s name must be unique </figure>
52 53 54 55 56 57 58 59 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 52 def create(lead_source) validate_type!(lead_source) attributes = sanitize(lead_source) _, _, root = @client.post("/lead_sources", attributes) LeadSource.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a source
delete ‘/lead_sources/BaseCRM#id’
Delete an existing source If the specified source does not exist, the request will return an error This operation cannot be undone
112 113 114 115 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 112 def destroy(id) status, _, _ = @client.delete("/lead_sources/#{id}") status == 204 end |
#find(id) ⇒ LeadSource
Retrieve a single source
get ‘/lead_sources/BaseCRM#id’
Returns a single source available to the user by the provided id If a source with the supplied unique identifier does not exist it returns an error
71 72 73 74 75 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 71 def find(id) _, _, root = @client.get("/lead_sources/#{id}") LeadSource.new(root[:data]) end |
#update(lead_source) ⇒ LeadSource
Update a source
put ‘/lead_sources/BaseCRM#id’
Updates source information If the specified source does not exist, the request will return an error <figure class=“notice”> If you want to update a source, you must make sure source’s name is unique </figure>
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 90 def update(lead_source) validate_type!(lead_source) params = extract_params!(lead_source, :id) id = params[:id] attributes = sanitize(lead_source) _, _, root = @client.put("/lead_sources/#{id}", attributes) LeadSource.new(root[:data]) end |
#where(options = {}) ⇒ Array<LeadSource>
Retrieve all sources
get ‘/lead_sources’
Returns all lead sources available to the user according to the parameters provided
34 35 36 37 38 |
# File 'lib/basecrm/services/lead_sources_service.rb', line 34 def where( = {}) _, _, root = @client.get("/lead_sources", ) root[:items].map{ |item| LeadSource.new(item[:data]) } end |