Module: Cts::Mpx::Driver::Assemblers
- Defined in:
- lib/cts/mpx/driver/assemblers.rb
Overview
collection of methods used to assemble various parts of a request.
Class Method Summary collapse
-
.host(user: nil, service: nil, account_id: 'urn:theplatform:auth:root') ⇒ String
assembles user service and account_id into a host string.
-
.path(service: nil, endpoint: nil, extra_path: nil, ids: nil, account_id: 'urn:theplatform:auth:root') ⇒ String
Assembles service, endpoint, extra_path, ids, and account_id into a host path.
-
.query(user: nil, account_id: nil, service: nil, endpoint: nil, query: {}, range: nil, count: nil, entries: nil, sort: nil) ⇒ Hash
Assembles service, endpoint, query, range, count, entries, sort and account_id into a query.
Class Method Details
.host(user: nil, service: nil, account_id: 'urn:theplatform:auth:root') ⇒ String
assembles user service and account_id into a host string
17 18 19 20 21 22 23 24 25 |
# File 'lib/cts/mpx/driver/assemblers.rb', line 17 def host(user: nil, service: nil, account_id: 'urn:theplatform:auth:root') Helpers.required_arguments %i[user service], binding user.token! service = Services[service] u = URI.parse service.url(account_id) [u.scheme, u.host].join('://') end |
.path(service: nil, endpoint: nil, extra_path: nil, ids: nil, account_id: 'urn:theplatform:auth:root') ⇒ String
Assembles service, endpoint, extra_path, ids, and account_id into a host path
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cts/mpx/driver/assemblers.rb', line 35 def path(service: nil, endpoint: nil, extra_path: nil, ids: nil, account_id: 'urn:theplatform:auth:root') Helpers.required_arguments %i[service endpoint], binding service = Services[].find { |s| s.name == service && s.endpoints.include?(endpoint) } path = "#{URI.parse(service.url(account_id)).path}/#{service.path}/#{endpoint}" path += "/#{extra_path}" if extra_path path += "/feed" if service.type == 'data' path += "/#{ids}" if ids path end |
.query(user: nil, account_id: nil, service: nil, endpoint: nil, query: {}, range: nil, count: nil, entries: nil, sort: nil) ⇒ Hash
Assembles service, endpoint, query, range, count, entries, sort and account_id into a query
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cts/mpx/driver/assemblers.rb', line 59 def query(user: nil, account_id: nil, service: nil, endpoint: nil, query: {}, range: nil, count: nil, entries: nil, sort: nil) Helpers.required_arguments %i[user service endpoint], binding user.token! service = Services[].find { |s| s.name == service && s.endpoints.include?(endpoint) } h = { schema: service.type == 'data' ? service.schema : service.endpoints[endpoint]['schema'], form: service.form, token: user.token } h[:account] = account_id if account_id h[:count] = count if count h[:entries] = entries if entries h[:range] = range if range h[:sort] = sort if sort h.merge! Oj.load(Oj.dump(query), symbol_keys: true) if query.any? h end |