Class: CtdDocumentation::TasksController

Inherits:
BaseController show all
Defined in:
lib/ctd_documentation/controllers/tasks_controller.rb

Overview

TasksController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from CtdDocumentation::BaseController

Instance Method Details

#all_tasks_fieldsHash of Object

This is used to determine the payload needed to be sent for creating/updating a task by a certain task type enum value



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 116

def all_tasks_fields
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/ranger/scans/get_params',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize)))
    .execute
end

#create_a_new_task(body) ⇒ CreateANewQueryResponse

This route creates a task



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 41

def create_a_new_task(body)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/ranger/scans',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(CreateANewQueryResponse.method(:from_hash)))
    .execute
end

#delete_a_task(content_type) ⇒ DeleteAQueryResponse

Delete a task by a list of selected resource IDs



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 60

def delete_a_task(content_type)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/ranger/scans',
                                 Server::DEFAULT)
               .header_param(new_parameter(content_type, key: 'Content-Type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(DeleteAQueryResponse.method(:from_hash)))
    .execute
end

#get_active_detection_history(site_id__exact, sort: nil) ⇒ GetActiveDetectionHistoryResponse

Get active detection history



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 132

def get_active_detection_history(site_id__exact,
                                 sort: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/ranger/active_history',
                                 Server::DEFAULT)
               .query_param(new_parameter(site_id__exact, key: 'site_id__exact'))
               .query_param(new_parameter(sort, key: 'sort'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(GetActiveDetectionHistoryResponse.method(:from_hash)))
    .execute
end

#get_tasks(sort: nil, page: 1, per_page: 20, name__icontains: nil, site_id__exact: nil) ⇒ GetQueriesResponse

Get all tasks and their information



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 16

def get_tasks(sort: nil,
              page: 1,
              per_page: 20,
              name__icontains: nil,
              site_id__exact: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/ranger/scans',
                                 Server::DEFAULT)
               .query_param(new_parameter(sort, key: 'sort'))
               .query_param(new_parameter(page, key: 'page'))
               .query_param(new_parameter(per_page, key: 'per_page'))
               .query_param(new_parameter(name__icontains, key: 'name__icontains'))
               .query_param(new_parameter(site_id__exact, key: 'site_id__exact'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(GetQueriesResponse.method(:from_hash)))
    .execute
end

#information_of_all_tasksHash of Object

Get descriptions and enums for all tasks (can be used later to retrieve parameters per task type enum)



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 101

def information_of_all_tasks
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/ranger/scans/get_types',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize)))
    .execute
end

#update_a_single_task(resource_id, body) ⇒ CreateANewQueryResponse

This route updates a task update



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ctd_documentation/controllers/tasks_controller.rb', line 79

def update_a_single_task(resource_id,
                         body)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/ranger/scans/{resource_id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(resource_id, key: 'resource_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(CreateANewQueryResponse.method(:from_hash)))
    .execute
end