Module: Xcal::Parktronic::Routes::CustomQueries
- Included in:
- Xcal::Parktronic::Routes
- Defined in:
- lib/xcal/parktronic/routes/custom_queries.rb
Instance Method Summary collapse
-
#find_custom_query(referencable_id, referencable_type) ⇒ Object
Find last Custom Query by reference (by widget id and type).
-
#get_custom_queries ⇒ Object
(also: #custom_queries)
Fetches active custom queries.
-
#post_custom_query(params) ⇒ Object
Posts new Custom Query.
-
#update_custom_query(id, params) ⇒ Object
Update Custom Query with specific ID.
Instance Method Details
#find_custom_query(referencable_id, referencable_type) ⇒ Object
Find last Custom Query by reference (by widget id and type)
Parameters
-
referencable_id
referencable ID (widget id) -
referencable_type
referencable_type (widget type)
Examples
api.find_custom_query(3, 'ChartSeries')
67 68 69 70 71 72 |
# File 'lib/xcal/parktronic/routes/custom_queries.rb', line 67 def find_custom_query(referencable_id, referencable_type) response = get_response("/#{api_version}/custom_queries/find/#{referencable_id}/#{referencable_type}?#{URI.encode_www_form(:access_token => access_token)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body) response.code == '200' ? Xcal::Parktronic::GenericResponse.new(generic_response.custom_query, self) : generic_response end |
#get_custom_queries ⇒ Object Also known as: custom_queries
Fetches active custom queries
Examples
api.get_custom_queries
api.custom_queries
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/xcal/parktronic/routes/custom_queries.rb', line 12 def get_custom_queries response = get_response("/#{api_version}/custom_queries?#{URI.encode_www_form(:access_token => access_token)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body) if response.code == '200' generic_response.custom_queries.map { |cq| Xcal::Parktronic::GenericResponse.new(cq.custom_query, self) } else generic_response end end |
#post_custom_query(params) ⇒ Object
Posts new Custom Query
Parameters
-
params
hash of Custom Query data.
Examples
api.post_custom_query(body: 'test query', bucket_interval: 30, database_name: 'database')
32 33 34 35 36 37 38 |
# File 'lib/xcal/parktronic/routes/custom_queries.rb', line 32 def post_custom_query(params) request = Net::HTTP::Post.new("/#{api_version}/custom_queries", 'Content-Type' => 'application/json') request.body = { access_token: access_token, custom_query: params }.to_json response = http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |
#update_custom_query(id, params) ⇒ Object
Update Custom Query with specific ID
Parameters
-
id
alarm ID -
params
custom query params
Examples
api.update_custom_query(2, body: 'new body')
api.update_custom_query(5, active: false, bucket_interval: 5, source: 'xbo')
50 51 52 53 54 55 56 |
# File 'lib/xcal/parktronic/routes/custom_queries.rb', line 50 def update_custom_query(id, params) request = Net::HTTP::Patch.new("/#{api_version}/custom_queries/#{id}", 'Content-Type' => 'application/json') request.body = { access_token: access_token, custom_query: params }.to_json response = http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |