lib/cts/mpx/driver/assemblers.rb in cts-mpx-1.0.1 vs lib/cts/mpx/driver/assemblers.rb in cts-mpx-1.0.2
- old
+ new
@@ -17,11 +17,11 @@
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
+ u = URI.parse service.url(account_id)
[u.scheme, u.host].join('://')
end
# Assembles service, endpoint, extra_path, ids, and account_id into a host path
@@ -32,11 +32,11 @@
# @param [String] account_id long form account_id id (ownerId)
# @raise [ArgumentError] if service or endpoint is not supplied
# @return [String] assembled path for a data call
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[service]
+ 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
@@ -54,24 +54,24 @@
# @param [TrueFalse] entries return an array of entries.
# @param [String] sort set the sort field
# @raise [ArgumentError] if user, service or endpoint is not supplied
# @raise [RuntimeError] if the user token is not set
# @return [Hash] assembled query for a data call
- def query(user: nil, account: nil, service: nil, endpoint: nil, query: {}, range: nil, count: nil, entries: nil, sort: nil)
+ 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[service]
+ service = Services[].find { |s| s.name == service && s.endpoints.include?(endpoint) }
h = {}
if service.type == 'data'
h.merge!(token: user.token, schema: service.schema, form: service.form)
h.merge!(query_data(range: range, count: count, entries: entries, sort: sort))
else
h.merge!(token: user.token, schema: service.endpoints[endpoint]['schema'], form: service.form)
end
- h[:account] = account if account
+ h[:account] = account_id if account_id
h.delete :token if user.token == 'sign_in_token'
h.merge! query
h
end