class PlaceOS::Api::Metadata
- PlaceOS::Api::Metadata
- PlaceOS::Api::Application
- ActionController::Base
- Reference
- Object
Defined in:
placeos-rest-api/controllers/metadata.crConstant Summary
-
AFTER =
{} of Nil => Nil -
AROUND =
{} of Nil => Nil -
BEFORE =
{set_request_id => {nil, nil}, authorize! => {nil, [root, mqtt_user, mqtt_access]}, set_user_id => {nil, [root, mqtt_user, mqtt_access]}, can_read => {[index, history], nil}, can_read_guest => {[show, children_metadata], nil}, can_write => {[update, destroy, update_alt], nil}, check_delete_permissions => {[destroy], nil}, current_zone => {[children], nil}, body => {[update, update_alt], nil}} of Nil => Nil -
FORCE =
{} of Nil => Nil -
LOCAL_AFTER =
{} of Nil => Nil -
function => options
-
LOCAL_AROUND =
{} of Nil => Nil -
function => options
-
LOCAL_BEFORE =
{can_read => {[index, history], nil}, can_read_guest => {[show, children_metadata], nil}, can_write => {[update, destroy, update_alt], nil}, check_delete_permissions => {[destroy], nil}, current_zone => {[children], nil}, body => {[update, update_alt], nil}} of Nil => Nil -
function => options
-
LOCAL_FORCE =
{} of Nil => Nil -
function => options
-
LOCAL_RESCUE =
{} of Nil => Nil -
function => options
-
LOCAL_ROUTES =
{children_metadata => {"get", "/:id/children", nil, do if user_token.guest_scope? if name && (guest_ids.includes?(parent_id)) else head(:forbidden) end end render_json do |json| json.array do current_zone.children.all.each do |zone| if include_parent? || (zone.id != parent_id) (Children.new(zone, name)).to_json(json) end end end end end, false}, merge => {"patch", "/:id", nil, do mutate(merge: true) end, false}, update => {"put", "/:id", nil, do mutate(merge: false) end, false}, history => {"get", "/:id/history", nil, do history = Model::Metadata.build_history(parent_id, name, offset: offset, limit: limit) total = (Model::Metadata.for(parent_id, name)).max_of?(&.history_count) || 0 range_start = offset range_end = (history.max_of?() do |__arg5| __arg5.last.size end || 0) + range_start response.headers["X-Total-Count"] = total.to_s response.headers["Content-Range"] = "metadata #{range_start}-#{range_end}/#{total}" if range_end < total params["offset"] = (range_end + 1).to_s params["limit"] = limit.to_s path = File.join(base_route, "/#{parent_id}/history") response.headers["Link"] = "<#{path}?#{query_params}>; rel=\"next\"" end render(json: history) end, false}} of Nil => Nil -
function => options
-
LOCAL_SKIP =
{} of Nil => Nil -
function => options
-
Log =
::PlaceOS::Api::Log.for(self) -
NAMESPACE =
["/api/engine/v2/metadata"] -
default namespace based on class
-
RESCUE =
{Error::NoBody => {error_no_body, do |_error| message = "missing request body" Log.debug do message end return render_error(HTTP::Status::BAD_REQUEST, message) end}, JSON::SerializableError => {json_serializable_error, do |error| message = "Missing or extraneous properties in client JSON" Log.debug(exception: error) do message end if Api.production? return render_error(HTTP::Status::BAD_REQUEST, message) else return render_error(HTTP::Status::BAD_REQUEST, error.message, backtrace: error.backtrace?) end end}, JSON::ParseException => {json_parse_exception, do |error| message = "Failed to parse client JSON" Log.debug(exception: error) do message end if Api.production? return render_error(HTTP::Status::BAD_REQUEST, message) else return render_error(HTTP::Status::BAD_REQUEST, error.message, backtrace: error.backtrace?) end end}, Error::Unauthorized => {error_unauthorized, do |error| Log.debug do error.message end head(:unauthorized) end}, Error::Forbidden => {error_forbidden, do |error| Log.debug do error.message end head(:forbidden) end}, RethinkORM::Error::DocumentNotFound => {rethink_orm_error_document_not_found, do |error| Log.debug do error.message end head(:not_found) end}, RethinkORM::Error::DocumentInvalid => {rethink_orm_error_document_invalid, do |error| Log.debug do error.message end return render_error(HTTP::Status::UNPROCESSABLE_ENTITY, error.message) end}, Error::InvalidParams => {error_invalid_params, do |error| model_errors = error.params.errors.map(&.to_s) Log.debug(exception: error) do {message: "Invalid params", model_errors: model_errors} end return render_error(HTTP::Status::BAD_REQUEST, "Invalid params: #{model_errors.join(", ")}") end}} of Nil => Nil -
ROUTE_RESOURCE =
"metadata" -
ROUTES =
{children_metadata => {"get", "/:id/children", nil, do if user_token.guest_scope? if name && (guest_ids.includes?(parent_id)) else head(:forbidden) end end render_json do |json| json.array do current_zone.children.all.each do |zone| if include_parent? || (zone.id != parent_id) (Children.new(zone, name)).to_json(json) end end end end end, false}, merge => {"patch", "/:id", nil, do mutate(merge: true) end, false}, update => {"put", "/:id", nil, do mutate(merge: false) end, false}, history => {"get", "/:id/history", nil, do history = Model::Metadata.build_history(parent_id, name, offset: offset, limit: limit) total = (Model::Metadata.for(parent_id, name)).max_of?(&.history_count) || 0 range_start = offset range_end = (history.max_of?() do |__arg5| __arg5.last.size end || 0) + range_start response.headers["X-Total-Count"] = total.to_s response.headers["Content-Range"] = "metadata #{range_start}-#{range_end}/#{total}" if range_end < total params["offset"] = (range_end + 1).to_s params["limit"] = limit.to_s path = File.join(base_route, "/#{parent_id}/history") response.headers["Link"] = "<#{path}?#{query_params}>; rel=\"next\"" end render(json: history) end, false}, index => {"get", "/", nil, nil, false}, show => {"get", "/:id", nil, nil, false}, destroy => {"delete", "/:id", nil, nil, false}} of Nil => Nil -
SKIP =
{} of Nil => Nil
Class Method Summary
-
.__init_routes__(router)
Routes call the functions generated above
-
.__route_list__
Create draw_routes function
-
.base_route
Helper for obtaining base route
-
.children_metadata(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Helper methods for performing redirect_to calls
- .context(method : String, route : String, route_params : Hash(String, String) | Nil = nil, headers : Hash(String, String) | Nil = nil, body : String | Bytes | IO | Nil = nil, &)
-
.delete__api_engine_v2_metadata__id(context, head_request)
Create draw_routes function
-
.destroy(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
-
.get__api_engine_v2_metadata_(context, head_request)
Create draw_routes function
-
.get__api_engine_v2_metadata__id(context, head_request)
Create draw_routes function
-
.get__api_engine_v2_metadata__id_children(context, head_request)
Generate functions for each route
-
.get__api_engine_v2_metadata__id_history(context, head_request)
Create draw_routes function
-
.history(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
-
.index(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
-
.merge(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
-
.patch__api_engine_v2_metadata__id(context, head_request)
Create draw_routes function
-
.put__api_engine_v2_metadata__id(context, head_request)
Create draw_routes function
-
.show(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
-
.update(hash_parts : Hash(String | Symbol, Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Symbol) | Nil = nil, **tuple_parts)
Create draw_routes function
Instance Method Summary
-
#base_route(*args, **options)
Helper for obtaining base route
-
#base_route(*args, **options, &)
Helper for obtaining base route
-
#check_delete_permissions
Does the user making the request have permissions to modify the data
-
#children_metadata
Fetch metadata for Zone children
- #create_or_update(interface : Model::Metadata::Interface, merge : Bool) : Model::Metadata
- #current_zone : Model::Zone
- #destroy
- #error_forbidden(error)
- #error_invalid_params(error)
-
#error_no_body(_error)
Create functions as required for errors Skip the generating methods for existing handlers
- #error_unauthorized(error)
-
#guest_ids
Fetch zones for system the current user has a role for
-
#history
Returns the version history for a Settings model
- #include_parent? : Bool
- #index
- #json_parse_exception(error)
- #json_serializable_error(error)
- #limit : Int32
- #merge
- #name : String | Nil
- #offset : Int32
- #parent_id : String
- #rethink_orm_error_document_invalid(error)
- #rethink_orm_error_document_not_found(error)
-
#show
Fetch metadata for a model
- #update
Macro Summary
- __inherit_after_filters__
- __inherit_around_filters__
- __inherit_before_filters__
- __inherit_force_filters__
- __inherit_rescue_filters__
- __inherit_routes_filters__
- __inherit_skip_filters__
- generate_scope_check(*scopes)
Instance methods inherited from class PlaceOS::Api::Application
body : IO
body,
boolean_param(key : String, default : Bool = false, allow_empty : Bool = false) : Bool
boolean_param,
paginate_results(elastic, query, route = base_route)
paginate_results,
request_id : String
request_id,
set_collection_headers(size : Int32, content_type : String)
set_collection_headers,
set_request_id
set_request_id,
set_user_id
set_user_id
Class methods inherited from class PlaceOS::Api::Application
context(method : String, route : String, route_params : Hash(String, String) | Nil = nil, headers : Hash(String, String) | Nil = nil, body : String | Bytes | IO | Nil = nil, &)
context,
core_discovery : Discovery::Core
core_discovery
Class methods inherited from module PlaceOS::Api::Utils::Scopes
can_scope_access?(user_token : UserJWT, scope : String, access : Access)
can_scope_access?,
can_scopes_access!(user_token : UserJWT, scopes : Enumerable(String), access : Access)
can_scopes_access!
Instance methods inherited from module PlaceOS::Api::Utils::CurrentUser
authorize! : Model::UserJWT
authorize!,
check_admin
check_admin,
check_oauth_scope
check_oauth_scope,
check_support
check_support,
current_authority : Model::Authority | Nil
current_authority,
current_user : Model::User
current_user,
is_admin?
is_admin?,
is_support?
is_support?,
user_token : Model::UserJWT
user_token
Instance methods inherited from module PlaceOS::Api::Utils::Responders
handle_execute_error(error : Driver::Proxy::RemoteDriver::Error, respond : Bool = true)
handle_execute_error,
render_error(status : HTTP::Status, message : String | Nil, **additional)
render_error,
restrict_attributes(model, only : Array(String) | Nil = nil, except : Array(String) | Nil = nil, fields : Hash | Nil = nil) : Hash
restrict_attributes,
save_and_respond(resource, &)save_and_respond(resource) save_and_respond, save_and_status(resource) save_and_status, with_fields(model, fields) : Hash with_fields
Class Method Detail
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Helper methods for performing redirect_to calls
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Generate functions for each route
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Create draw_routes function
Create instance of controller class init with context, params and logger protocol checks (https etc) controller instance created begin exception helpers inline the around filters inline the before filters inline the action inline the after filters rescue exception handlers
Instance Method Detail
Fetch metadata for Zone children
Filter for a specific metadata by name via #name param.
Includes the parent metadata by default via include_parent param.
Create functions as required for errors Skip the generating methods for existing handlers