Class: Okonomi::Taskmanager::Resource
- Inherits:
-
Object
- Object
- Okonomi::Taskmanager::Resource
- Defined in:
- lib/okonomi/taskmanager/resource.rb
Direct Known Subclasses
Namespaces, TaskAssignments, TaskLabels, TaskTransitions, TaskTypes, Tasks, Users
Defined Under Namespace
Classes: TaskClientError
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#jwt_token ⇒ Object
readonly
Returns the value of attribute jwt_token.
-
#root_node_plural ⇒ Object
readonly
Returns the value of attribute root_node_plural.
-
#root_node_singular ⇒ Object
readonly
Returns the value of attribute root_node_singular.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #create(attributes) ⇒ Object
- #destroy(id) ⇒ Object
- #find(id) ⇒ Object
-
#initialize(root_node_singular: nil, root_node_plural: nil, api_url: nil, jwt_token: nil) ⇒ Resource
constructor
A new instance of Resource.
- #update(id, attributes) ⇒ Object
Constructor Details
#initialize(root_node_singular: nil, root_node_plural: nil, api_url: nil, jwt_token: nil) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 |
# File 'lib/okonomi/taskmanager/resource.rb', line 6 def initialize(root_node_singular: nil, root_node_plural: nil, api_url: nil, jwt_token: nil) @api_url = api_url @jwt_token = jwt_token @root_node_singular = root_node_singular @root_node_plural = root_node_plural end |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
4 5 6 |
# File 'lib/okonomi/taskmanager/resource.rb', line 4 def api_url @api_url end |
#jwt_token ⇒ Object (readonly)
Returns the value of attribute jwt_token.
4 5 6 |
# File 'lib/okonomi/taskmanager/resource.rb', line 4 def jwt_token @jwt_token end |
#root_node_plural ⇒ Object (readonly)
Returns the value of attribute root_node_plural.
4 5 6 |
# File 'lib/okonomi/taskmanager/resource.rb', line 4 def root_node_plural @root_node_plural end |
#root_node_singular ⇒ Object (readonly)
Returns the value of attribute root_node_singular.
4 5 6 |
# File 'lib/okonomi/taskmanager/resource.rb', line 4 def root_node_singular @root_node_singular end |
Instance Method Details
#all(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/okonomi/taskmanager/resource.rb', line 13 def all( = {}) uri = URI(build_uri_with_params(api_url, )) response = execute_request(Net::HTTP::Get, uri) if response.is_a?(Net::HTTPSuccess) parse_resources(response.body) else handle_error(response) end end |
#create(attributes) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/okonomi/taskmanager/resource.rb', line 35 def create(attributes) uri = URI(api_url) response = execute_request(Net::HTTP::Post, uri, { root_node_singular => attributes }.to_json) if response.is_a?(Net::HTTPSuccess) parse_resource(response.body) else handle_error(response) end end |
#destroy(id) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/okonomi/taskmanager/resource.rb', line 57 def destroy(id) uri = URI("#{api_url}/#{id}") response = execute_request(Net::HTTP::Delete, uri) if response.is_a?(Net::HTTPSuccess) true else handle_error(response) end end |
#find(id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/okonomi/taskmanager/resource.rb', line 24 def find(id) uri = URI("#{api_url}/#{id}") response = execute_request(Net::HTTP::Get, uri) if response.is_a?(Net::HTTPSuccess) parse_resource(response.body) else handle_error(response) end end |
#update(id, attributes) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/okonomi/taskmanager/resource.rb', line 46 def update(id, attributes) uri = URI("#{api_url}/#{id}") response = execute_request(Net::HTTP::Patch, uri, { root_node_singular => attributes }.to_json) if response.is_a?(Net::HTTPSuccess) parse_resource(response.body) else handle_error(response) end end |