Class: BaseCRM::SourcesService
- Inherits:
-
Object
- Object
- BaseCRM::SourcesService
- Defined in:
- lib/basecrm/services/sources_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:name]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all sources.
-
#create(source) ⇒ Source
Create a source.
-
#destroy(id) ⇒ Boolean
Delete a source.
-
#find(id) ⇒ Source
Retrieve a single source.
-
#initialize(client) ⇒ SourcesService
constructor
A new instance of SourcesService.
-
#update(source) ⇒ Source
Update a source.
-
#where(options = {}) ⇒ Array<Source>
Retrieve all sources.
Constructor Details
#initialize(client) ⇒ SourcesService
Returns a new instance of SourcesService.
7 8 9 |
# File 'lib/basecrm/services/sources_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all sources
get ‘/sources’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/sources_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(source) ⇒ Source
Create a source
post ‘/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/sources_service.rb', line 52 def create(source) validate_type!(source) attributes = sanitize(source) _, _, root = @client.post("/sources", attributes) Source.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a source
delete ‘/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/sources_service.rb', line 112 def destroy(id) status, _, _ = @client.delete("/sources/#{id}") status == 204 end |
#find(id) ⇒ Source
Retrieve a single source
get ‘/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/sources_service.rb', line 71 def find(id) _, _, root = @client.get("/sources/#{id}") Source.new(root[:data]) end |
#update(source) ⇒ Source
Update a source
put ‘/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/sources_service.rb', line 90 def update(source) validate_type!(source) params = extract_params!(source, :id) id = params[:id] attributes = sanitize(source) _, _, root = @client.put("/sources/#{id}", attributes) Source.new(root[:data]) end |
#where(options = {}) ⇒ Array<Source>
Retrieve all sources
get ‘/sources’
Returns all deal sources available to the user according to the parameters provided
34 35 36 37 38 |
# File 'lib/basecrm/services/sources_service.rb', line 34 def where( = {}) _, _, root = @client.get("/sources", ) root[:items].map{ |item| Source.new(item[:data]) } end |