Module: Cts::Mpx::Services::Web
- Defined in:
- lib/cts/mpx/services/web.rb
Overview
Collection of procedural methods to interact with the Web services All of these methods mimic the Business clients as close as possible If your operation does not work in the Business client, it will not work here
Class Method Summary collapse
-
.[](key = nil) ⇒ Service[], Service
Addressable method, indexed by web service title.
-
.assemble_payload(service: nil, endpoint: nil, method: nil, arguments: nil) ⇒ Hash
assembles service, endpoint, method, and arguments into a payload.
-
.post(user: nil, account: nil, service: nil, endpoint: nil, method: nil, query: {}, headers: {}, arguments: {}, extra_path: nil) ⇒ Response
Procedural method to interact with a web service via POST.
-
.services ⇒ Services[]
Web service list.
Class Method Details
.[](key = nil) ⇒ Service[], Service
Addressable method, indexed by web service title
16 17 18 19 20 21 22 23 24 |
# File 'lib/cts/mpx/services/web.rb', line 16 def [](key = nil) return services unless key Driver::Exceptions.raise_unless_argument_error?(key, String) service = services.find { |e| e.name == key } Driver::Exceptions.raise_unless_argument_error?(service, Driver::Service) service end |
.assemble_payload(service: nil, endpoint: nil, method: nil, arguments: nil) ⇒ Hash
assembles service, endpoint, method, and arguments into a payload
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cts/mpx/services/web.rb', line 38 def assemble_payload(service: nil, endpoint: nil, method: nil, arguments: nil) Driver::Helpers.required_arguments ['service', 'endpoint', 'method', 'arguments'], binding service = Services[service] method_list = service.endpoints[endpoint]['methods'] Driver::Exceptions.raise_unless_argument_error?(arguments, Hash) Driver::Exceptions.raise_unless_argument_error?(method, 'method') { !method_list.key?(method) } arguments.each_key { |k| Driver::Exceptions.raise_unless_argument_error?(arguments, 'argument') { !method_list[method].include? k.to_s } } h = {} h[method] = arguments h end |
.post(user: nil, account: nil, service: nil, endpoint: nil, method: nil, query: {}, headers: {}, arguments: {}, extra_path: nil) ⇒ Response
Procedural method to interact with a web service via POST
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cts/mpx/services/web.rb', line 68 def post(user: nil, account: nil, service: nil, endpoint: nil, method: nil, query: {}, headers: {}, arguments: {}, extra_path: nil) ### check arguments Driver::Helpers.required_arguments ['user', 'service', 'endpoint', 'method', 'arguments'], binding Driver::Helpers.raise_if_not_a_hash [query, headers, arguments] user.token! ### Registry Registry.fetch_and_store_domain(user, account) unless self[service].url? ### Assemblers/prep host = Driver::Assemblers.host user: user, service: service path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path payload = assemble_payload service: service, endpoint: endpoint, method: method, arguments: arguments query = Driver::Assemblers.query user: user, account_id: account, service: service, endpoint: endpoint, query: query ### Request request = Driver::Request.create(method: :post, url: [host, path].join, query: query, payload: Oj.dump(payload), headers: headers) request.call end |