Module: Resources
Instance Method Summary collapse
-
#add_tag_to_resource(id, tag) ⇒ Array
Add a tag to a resource.
-
#create_resource(name = nil, content = nil, is_public = false) ⇒ Resource
Create a resource.
-
#remove_tag_from_resource(id, tag) ⇒ Array
Remove a tag from a resource.
-
#tags_for_resource(id) ⇒ Array
Return tags for a resource.
-
#update_resource(id, options = {}) ⇒ Resource
Update a resource.
Methods included from BaseClient
#auth_header, #convert_keys, #convert_response, #handle_timeouts, #success?, #whitelist_params
Instance Method Details
#add_tag_to_resource(id, tag) ⇒ Array
Add a tag to a resource
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/client/resources.rb', line 72 def add_tag_to_resource(id, tag) tag.gsub!(" ", "_") url = "#{@api_base_path}/resources/#{id}/tags" handle_timeouts do response = self.class.post(url, headers: auth_header, body: { add: tag }) JSON.parse(response.body)['new_list'] end end |
#create_resource(name = nil, content = nil, is_public = false) ⇒ Resource
Create a resource
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/client/resources.rb', line 15 def create_resource(name=nil, content=nil, is_public=false) url = "#{@api_base_path}/resources/" handle_timeouts do response = self.class.post(url, headers: auth_header, body: { resource: { name: name, content: content, is_public: is_public } }) convert_response(response, "resource") end end |
#remove_tag_from_resource(id, tag) ⇒ Array
Remove a tag from a resource
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/client/resources.rb', line 90 def remove_tag_from_resource(id, tag) tag.gsub!(" ", "_") url = "#{@api_base_path}/resources/#{id}/tags" handle_timeouts do response = self.class.post(url, headers: auth_header, body: { remove: tag }) JSON.parse(response.body)['new_list'] end end |
#tags_for_resource(id) ⇒ Array
Return tags for a resource
56 57 58 59 60 61 62 63 |
# File 'lib/client/resources.rb', line 56 def (id) url = "#{@api_base_path}/resources/#{id}/tags" handle_timeouts do response = self.class.post(url, headers: auth_header) JSON.parse(response.body)['new_list'] end end |
#update_resource(id, options = {}) ⇒ Resource
Update a resource
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/client/resources.rb', line 36 def update_resource(id, ={}) whitelist = ['name', 'content', 'is_public'] = convert_keys() resource_params = whitelist_params(, whitelist) url = "#{@api_base_path}/resources/#{id}" handle_timeouts do response = self.class.put(url, headers: auth_header, body: { resource: resource_params }) convert_response(response, "resource") end end |