1 /** 2 * Copyright © DiamondMVC 2019 3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module diamond.web.soap.client.envelopebody; 7 8 import diamond.web.soap.client.envelopeparameter; 9 10 /// Wrapper around a soap envelope body. 11 final class SoapEnvelopeBody 12 { 13 private: 14 /// The method. 15 string _method; 16 /// The parameters. 17 SoapEnvelopeParameter[] _parameters; 18 19 public: 20 final: 21 /** 22 * Creates a new soap envelope body. 23 * Params: 24 * method = The method of the body. 25 */ 26 this(string method) 27 { 28 _method = method; 29 } 30 31 @property 32 { 33 /// Gets the method of the body. 34 string method() { return _method; } 35 36 /// Gets the parameters of the body. 37 SoapEnvelopeParameter[] parameters() { return _parameters; } 38 } 39 40 /** 41 * Adds a parameter to the body. 42 * Params: 43 * name = The name. 44 * value = The value. 45 */ 46 void addParameter(string name, string value) 47 { 48 _parameters ~= new SoapEnvelopeParameter(name, value); 49 } 50 51 /** 52 * Gets a parameter from the body. 53 * Params: 54 * name = The name of the parameter. 55 * Returns: 56 * The parameter if found, null otherwise. 57 */ 58 SoapEnvelopeParameter getParameter(string name) 59 { 60 import std.algorithm : filter; 61 import std.array : array; 62 import std..string : toLower, strip; 63 64 if (!name || !name.length) 65 { 66 return null; 67 } 68 69 if (!_parameters || !_parameters.length) 70 { 71 return null; 72 } 73 74 auto parameter = _parameters.filter!(p => p.name.toLower().strip() == name.toLower().strip()).array; 75 76 if (!parameter || !parameter.length) 77 { 78 return null; 79 } 80 81 return parameter[0]; 82 } 83 }