Class: Talis::Hierarchy::Node
Overview
Represents hierarchy node API operations provided by the Blueprint gem: https://github.com/talis/blueprint_rb
In order to perform remote operations, the client must be configured with a valid OAuth client that is allowed to query nodes:
Talis::Authentication.client_id = 'client_id'
Talis::Authentication.client_secret = 'client_secret'
Instance Attribute Summary
Attributes included from OAuthService
#client_id, #client_secret, #oauth_host
Attributes included from Resource::Helpers
#attributes, #id, #namespace, #type
Class Method Summary collapse
-
.ancestors(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all ancestors belonging to the specified node from the hierarchy for the given namespace.
-
.api_client(request_id = new_req_id) ⇒ Object
Exposes the underlying Blueprint nodes API client.
-
.children(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all children belonging to the specified node from the hierarchy for the given namespace.
-
.create(request_id: new_req_id, namespace:, type:, id:, attributes: {}) ⇒ Talis::Hierarchy::Node
Create a new node.
-
.descendants(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all descendants belonging to the specified node from the hierarchy for the given namespace.
-
.find(request_id: new_req_id, namespace:, opts: {}) ⇒ Hash
Search for nodes in the hierarchy for the given namespace.
-
.get(request_id: new_req_id, namespace:, type:, id:) ⇒ Object
Fetch a single node from the hierarchy for the given namespace.
-
.parents(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all parents belonging to the specified node from the hierarchy for the given namespace.
Instance Method Summary collapse
-
#initialize(id:, type:, namespace:, attributes: {}) ⇒ Node
constructor
A new instance of Node.
Methods included from Resource
Methods included from Resource::Helpers
#persisted?, #stored_id, #stored_type
Methods inherited from Resource
Constructor Details
#initialize(id:, type:, namespace:, attributes: {}) ⇒ Node
Returns a new instance of Node.
20 21 22 23 24 25 |
# File 'lib/talis/hierarchy/node.rb', line 20 def initialize(id:, type:, namespace:, attributes: {}) @id = id @type = type @namespace = namespace @attributes = attributes end |
Class Method Details
.ancestors(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all ancestors belonging to the specified node from the hierarchy for the given namespace.
126 127 128 129 130 |
# File 'lib/talis/hierarchy/node.rb', line 126 def ancestors(request_id: new_req_id, namespace:, type:, id:, opts: {}) api_client(request_id).get_ancestors(id, namespace, type, opts).data rescue BlueprintClient::ApiError => error handle_response(error) end |
.api_client(request_id = new_req_id) ⇒ Object
Exposes the underlying Blueprint nodes API client.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/talis/hierarchy/node.rb', line 178 def api_client(request_id = new_req_id) configure_blueprint api_client = BlueprintClient::ApiClient.new api_client.default_headers = { 'X-Request-Id' => request_id, 'User-Agent' => "talis-ruby-client/#{Talis::VERSION} "\ "ruby/#{RUBY_VERSION}" } BlueprintClient::HierarchyApi.new(api_client) end |
.children(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all children belonging to the specified node from the hierarchy for the given namespace.
105 106 107 108 109 |
# File 'lib/talis/hierarchy/node.rb', line 105 def children(request_id: new_req_id, namespace:, type:, id:, opts: {}) api_client(request_id).get_children(id, namespace, type, opts).data rescue BlueprintClient::ApiError => error handle_response(error) end |
.create(request_id: new_req_id, namespace:, type:, id:, attributes: {}) ⇒ Talis::Hierarchy::Node
Create a new node
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/talis/hierarchy/node.rb', line 161 def create(request_id: new_req_id, namespace:, type:, id:, attributes: {}) new_node = { data: { id: id, type: type, attributes: attributes } } build(api_client(request_id).add_node(namespace, new_node, {}).data, namespace) rescue BlueprintClient::ApiError => error handle_response(error) end |
.descendants(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all descendants belonging to the specified node from the hierarchy for the given namespace.
147 148 149 150 151 |
# File 'lib/talis/hierarchy/node.rb', line 147 def descendants(request_id: new_req_id, namespace:, type:, id:, opts: {}) api_client(request_id).get_descendants(id, namespace, type, opts).data rescue BlueprintClient::ApiError => error handle_response(error) end |
.find(request_id: new_req_id, namespace:, opts: {}) ⇒ Hash
Search for nodes in the hierarchy for the given namespace.
where nodes are of type BlueprintClient::Node
45 46 47 48 49 |
# File 'lib/talis/hierarchy/node.rb', line 45 def find(request_id: new_req_id, namespace:, opts: {}) api_client(request_id).search_nodes(namespace, opts) rescue BlueprintClient::ApiError => error handle_response(error) end |
.get(request_id: new_req_id, namespace:, type:, id:) ⇒ Object
Fetch a single node from the hierarchy for the given namespace.
61 62 63 64 65 66 67 68 69 |
# File 'lib/talis/hierarchy/node.rb', line 61 def get(request_id: new_req_id, namespace:, type:, id:) api_client(request_id).get_node(namespace, id, type).data rescue BlueprintClient::ApiError => error begin handle_response(error) rescue Talis::NotFoundError nil end end |
.parents(request_id: new_req_id, namespace:, type:, id:, opts: {}) ⇒ Object
Fetch all parents belonging to the specified node from the hierarchy for the given namespace.
84 85 86 87 88 |
# File 'lib/talis/hierarchy/node.rb', line 84 def parents(request_id: new_req_id, namespace:, type:, id:, opts: {}) api_client(request_id).get_parents(id, namespace, type, opts).data rescue BlueprintClient::ApiError => error handle_response(error) end |