Module: Cts::Mpx::Services::Data
- Defined in:
- lib/cts/mpx/services/data.rb
Overview
Collection of procedural methods to interact with the Data services All of these methods mimic the DSS clients as close as possible If your operation does not work in the DSS client, it will not work here
Class Method Summary collapse
-
.[](key = nil) ⇒ Service[], Service
Addressable method, indexed by data service title.
-
.delete(user: nil, account_id: nil, service: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil) ⇒ Response
Procedural method to DELETE data from the data services.
-
.get(user: nil, account_id: nil, service: nil, fields: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil, method: :get) ⇒ Response
Procedural method to GET data from the data services.
-
.post(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}, method: :post) ⇒ Response
Procedural method to POST data to the data services.
-
.prep_call(args = {}) ⇒ Response
Helper method to assure that everything is is ok to call the methods above.
-
.put(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}) ⇒ Response
Procedural method to PUT data to the data services.
Class Method Details
.[](key = nil) ⇒ Service[], Service
Addressable method, indexed by data service title
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cts/mpx/services/data.rb', line 16 def [](key = nil) services = Services[].select { |s| s.type == 'data' } return services unless key raise ArgumentError, 'key must be a string' unless key.is_a? String service = services.find { |e| e.name == key } raise ArgumentError, "#{key} must be a service name." unless service service end |
.delete(user: nil, account_id: nil, service: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil) ⇒ Response
Procedural method to DELETE data from the data services
31 32 33 |
# File 'lib/cts/mpx/services/data.rb', line 31 def delete(user: nil, account_id: nil, service: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil) get(user: user, account_id: account_id, service: service, endpoint: endpoint, sort: sort, extra_path: extra_path, range: range, ids: ids, query: query, headers: headers, count: count, entries: entries, method: :delete) end |
.get(user: nil, account_id: nil, service: nil, fields: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil, method: :get) ⇒ Response
Procedural method to GET data from the data services
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cts/mpx/services/data.rb', line 51 def get(user: nil, account_id: nil, service: nil, fields: nil, endpoint: nil, sort: nil, extra_path: nil, range: nil, ids: nil, query: {}, headers: {}, count: nil, entries: nil, method: :get) prep_call(user: user, account_id: account_id, service: service, query: query, headers: headers, required_arguments: ['user', 'service', 'endpoint'], binding: binding) host = Driver::Assemblers.host user: user, service: service, account_id: account_id path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path, ids: ids query = Driver::Assemblers.query user: user, account_id: account_id, service: service, endpoint: endpoint, query: query, range: range query[:fields] = fields if Services[service].type == 'data' && fields request = Driver::Request.create(method: method, url: [host, path].join, query: query, headers: headers) request.call end |
.post(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}, method: :post) ⇒ Response
Procedural method to POST data to the data services
75 76 77 78 79 80 81 82 83 |
# File 'lib/cts/mpx/services/data.rb', line 75 def post(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}, method: :post) prep_call(user: user, account_id: account_id, service: service, query: query, headers: headers, required_arguments: ['user', 'service', 'endpoint', 'page'], page: page, binding: binding) host = Driver::Assemblers.host user: user, service: service, account_id: account_id path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path query = Driver::Assemblers.query user: user, account_id: account_id, service: service, endpoint: endpoint, query: query request = Driver::Request.create(method: method, url: [host, path].join, query: query, headers: headers, payload: page.to_s) request.call end |
.prep_call(args = {}) ⇒ Response
Helper method to assure that everything is is ok to call the methods above
111 112 113 114 115 116 117 118 |
# File 'lib/cts/mpx/services/data.rb', line 111 def prep_call(args = {}) Driver::Helpers.required_arguments args[:required_arguments], args[:binding] Driver::Helpers.raise_if_not_a([args[:user]], User) if args[:user] Driver::Helpers.raise_if_not_a_hash [args[:query], args[:headers]] Driver::Helpers.raise_if_not_a([args[:page]], Driver::Page) if args[:page] args[:user].token! Registry.fetch_and_store_domain(args[:user], args[:account_id]) end |
.put(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}) ⇒ Response
Procedural method to PUT data to the data services
89 90 91 |
# File 'lib/cts/mpx/services/data.rb', line 89 def put(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}) post(user: user, account_id: account_id, service: service, endpoint: endpoint, extra_path: extra_path, query: query, page: page, headers: headers, method: :put) end |