Method: WscSdk::Endpoint#create
- Defined in:
- lib/wsc_sdk/endpoint.rb
#create(model_object) ⇒ WscSdk::Model, Nil
Create a new model using the endpoint.
If successful this method will directly modify the model_object that is provided, and also return a reference to that object.
If the data in the model_object is not valid, then the validation messages will be updated in the errors property, and the method will return a Nil object.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/wsc_sdk/endpoint.rb', line 130 def create(model_object) return WscSdk::Errors.model_exists(self) unless model_object.new_model? payload = model_object.build_payload return WscSdk::Errors.invalid_attributes(self) unless model_object.valid? response = client.post(create_path, body: payload) if (200..299).include?(response.code) return transform_model(response.body, origin_model: model_object) else return transform_model(response.body, model_class: WscSdk::Models::Error) end end |