Class: Node::Red::Client
- Inherits:
-
Object
- Object
- Node::Red::Client
- Defined in:
- lib/node/red/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
-
#add_flow(flow) ⇒ Hash
Add a flow to the active configuration.
-
#auth_login ⇒ Hash
Get the active authentication scheme.
-
#auth_revoke(token) ⇒ Hash
Revoke an access token.
-
#auth_token(client_id:, grant_type:, scope:, username:, password:) ⇒ Hash
Exchange credentials for access token.
-
#delete_flow(id) ⇒ Hash
Delete an individual flow configuration.
-
#delete_node_module(module_name) ⇒ Hash
Remove a node module.
-
#deploy_flows(flows, rev: nil) ⇒ Hash
Set the active flow configuration.
-
#diagnostics ⇒ Hash
Get the runtime diagnostics.
-
#flow(id) ⇒ Hash
Get an individual flow configuration.
-
#flows ⇒ Array<Hash>
Get the active flow configuration.
-
#flows_state ⇒ Hash
Get the active flow’s runtime state.
-
#initialize(base_url, access_token: nil) ⇒ Client
constructor
Initialize a new Node-RED Admin API client.
-
#install_node(module_name) ⇒ Hash
Install a new node module.
-
#node_module(module_name) ⇒ Hash
Get a node module’s information.
-
#node_set(module_name, set_name) ⇒ Hash
Get a node module set information.
-
#nodes ⇒ Array<Hash>
Get a list of the installed nodes.
-
#set_flows_state(state) ⇒ Hash
Set the active flow’s runtime state.
-
#settings ⇒ Hash
Get the runtime settings.
-
#update_flow(id, flow) ⇒ Hash
Update an individual flow configuration.
-
#update_node_module(module_name, enabled:) ⇒ Hash
Enable or disable a node module.
-
#update_node_set(module_name, set_name, enabled:) ⇒ Hash
Enable or disable a node set.
Constructor Details
#initialize(base_url, access_token: nil) ⇒ Client
Initialize a new Node-RED Admin API client
16 17 18 19 |
# File 'lib/node/red/client.rb', line 16 def initialize(base_url, access_token: nil) @base_url = base_url.chomp("/") @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/node/red/client.rb', line 10 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/node/red/client.rb', line 10 def base_url @base_url end |
Instance Method Details
#add_flow(flow) ⇒ Hash
Add a flow to the active configuration
116 117 118 |
# File 'lib/node/red/client.rb', line 116 def add_flow(flow) post("/flow", flow) end |
#auth_login ⇒ Hash
Get the active authentication scheme
26 27 28 |
# File 'lib/node/red/client.rb', line 26 def auth_login get("/auth/login") end |
#auth_revoke(token) ⇒ Hash
Revoke an access token
55 56 57 58 |
# File 'lib/node/red/client.rb', line 55 def auth_revoke(token) body = { token: token } post("/auth/revoke", body) end |
#auth_token(client_id:, grant_type:, scope:, username:, password:) ⇒ Hash
Exchange credentials for access token
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/node/red/client.rb', line 38 def auth_token(client_id:, grant_type:, scope:, username:, password:) body = { client_id: client_id, grant_type: grant_type, scope: scope, username: username, password: password } response = post("/auth/token", body, use_auth: false) @access_token = response["access_token"] if response["access_token"] response end |
#delete_flow(id) ⇒ Hash
Delete an individual flow configuration
141 142 143 |
# File 'lib/node/red/client.rb', line 141 def delete_flow(id) delete("/flow/#{id}") end |
#delete_node_module(module_name) ⇒ Hash
Remove a node module
185 186 187 |
# File 'lib/node/red/client.rb', line 185 def delete_node_module(module_name) delete("/nodes/#{module_name}") end |
#deploy_flows(flows, rev: nil) ⇒ Hash
Set the active flow configuration
97 98 99 100 101 |
# File 'lib/node/red/client.rb', line 97 def deploy_flows(flows, rev: nil) body = { flows: flows } body[:rev] = rev if rev post("/flows", body) end |
#diagnostics ⇒ Hash
Get the runtime diagnostics
72 73 74 |
# File 'lib/node/red/client.rb', line 72 def diagnostics get("/diagnostics") end |
#flow(id) ⇒ Hash
Get an individual flow configuration
124 125 126 |
# File 'lib/node/red/client.rb', line 124 def flow(id) get("/flow/#{id}") end |
#flows ⇒ Array<Hash>
Get the active flow configuration
81 82 83 |
# File 'lib/node/red/client.rb', line 81 def flows get("/flows") end |
#flows_state ⇒ Hash
Get the active flow’s runtime state
88 89 90 |
# File 'lib/node/red/client.rb', line 88 def flows_state get("/flows/state") end |
#install_node(module_name) ⇒ Hash
Install a new node module
158 159 160 161 |
# File 'lib/node/red/client.rb', line 158 def install_node(module_name) body = { module: module_name } post("/nodes", body) end |
#node_module(module_name) ⇒ Hash
Get a node module’s information
167 168 169 |
# File 'lib/node/red/client.rb', line 167 def node_module(module_name) get("/nodes/#{module_name}") end |
#node_set(module_name, set_name) ⇒ Hash
Get a node module set information
194 195 196 |
# File 'lib/node/red/client.rb', line 194 def node_set(module_name, set_name) get("/nodes/#{module_name}/#{set_name}") end |
#nodes ⇒ Array<Hash>
Get a list of the installed nodes
150 151 152 |
# File 'lib/node/red/client.rb', line 150 def nodes get("/nodes") end |
#set_flows_state(state) ⇒ Hash
Set the active flow’s runtime state
107 108 109 110 |
# File 'lib/node/red/client.rb', line 107 def set_flows_state(state) body = { state: state } post("/flows/state", body) end |
#settings ⇒ Hash
Get the runtime settings
65 66 67 |
# File 'lib/node/red/client.rb', line 65 def settings get("/settings") end |
#update_flow(id, flow) ⇒ Hash
Update an individual flow configuration
133 134 135 |
# File 'lib/node/red/client.rb', line 133 def update_flow(id, flow) put("/flow/#{id}", flow) end |
#update_node_module(module_name, enabled:) ⇒ Hash
Enable or disable a node module
176 177 178 179 |
# File 'lib/node/red/client.rb', line 176 def update_node_module(module_name, enabled:) body = { enabled: enabled } put("/nodes/#{module_name}", body) end |
#update_node_set(module_name, set_name, enabled:) ⇒ Hash
Enable or disable a node set
204 205 206 207 |
# File 'lib/node/red/client.rb', line 204 def update_node_set(module_name, set_name, enabled:) body = { enabled: enabled } put("/nodes/#{module_name}/#{set_name}", body) end |