Class: BaseCRM::TagsService
- Inherits:
-
Object
- Object
- BaseCRM::TagsService
- Defined in:
- lib/basecrm/services/tags_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:name, :resource_type]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all tags.
-
#create(tag) ⇒ Tag
Create a tag.
-
#destroy(id) ⇒ Boolean
Delete a tag.
-
#find(id) ⇒ Tag
Retrieve a single tag.
-
#initialize(client) ⇒ TagsService
constructor
A new instance of TagsService.
-
#update(tag) ⇒ Tag
Update a tag.
-
#where(options = {}) ⇒ Array<Tag>
Retrieve all tags.
Constructor Details
#initialize(client) ⇒ TagsService
Returns a new instance of TagsService.
7 8 9 |
# File 'lib/basecrm/services/tags_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all tags
get ‘/tags’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/tags_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(tag) ⇒ Tag
Create a tag
post ‘/tags’
Creates a new tag Notice the tag’s name must be unique within the scope of the resource_type
52 53 54 55 56 57 58 59 |
# File 'lib/basecrm/services/tags_service.rb', line 52 def create(tag) validate_type!(tag) attributes = sanitize(tag) _, _, root = @client.post("/tags", attributes) Tag.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a tag
delete ‘/tags/BaseCRM#id’
Deletes an existing tag If the specified tag is assigned to any resource, we will remove this tag from all such resources If the specified tag does not exist, this query will return an error This operation cannot be undone
111 112 113 114 |
# File 'lib/basecrm/services/tags_service.rb', line 111 def destroy(id) status, _, _ = @client.delete("/tags/#{id}") status == 204 end |
#find(id) ⇒ Tag
Retrieve a single tag
get ‘/tags/BaseCRM#id’
Returns a single tag available to the user according to the unique ID provided If the specified tag does not exist, this query will return an error
71 72 73 74 75 |
# File 'lib/basecrm/services/tags_service.rb', line 71 def find(id) _, _, root = @client.get("/tags/#{id}") Tag.new(root[:data]) end |
#update(tag) ⇒ Tag
Update a tag
put ‘/tags/BaseCRM#id’
Updates a tag’s information If the specified tag does not exist, this query will return an error Notice if you want to update a tag, you must make sure the tag’s name is unique within the scope of the specified resource
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/basecrm/services/tags_service.rb', line 88 def update(tag) validate_type!(tag) params = extract_params!(tag, :id) id = params[:id] attributes = sanitize(tag) _, _, root = @client.put("/tags/#{id}", attributes) Tag.new(root[:data]) end |
#where(options = {}) ⇒ Array<Tag>
Retrieve all tags
get ‘/tags’
Returns all tags available to the user, according to the parameters provided
36 37 38 39 40 |
# File 'lib/basecrm/services/tags_service.rb', line 36 def where( = {}) _, _, root = @client.get("/tags", ) root[:items].map{ |item| Tag.new(item[:data]) } end |