Class: SBF::Client::EventApplicationEndpoint
- Inherits:
-
EntityEndpoint
- Object
- EntityEndpoint
- SBF::Client::EventApplicationEndpoint
- Defined in:
- lib/stbaldricks/endpoints/event_application.rb
Instance Attribute Summary
Attributes inherited from EntityEndpoint
Instance Method Summary collapse
Methods inherited from EntityEndpoint
#aggregate, #delete, #find, #find_first, #get, #initialize, #save, #update
Constructor Details
This class inherits a constructor from SBF::Client::EntityEndpoint
Instance Method Details
#create(entity, with = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/stbaldricks/endpoints/event_application.rb', line 6 def create(entity, with = {}) raise SBF::Client::Error, 'Invalid Entity' unless entity.is_a?(SBF::Client::BaseEntity) with = normalize_with(with) create_data = entity.to_hash create_data.store(:with, with) entity.errors.clear response = SBF::Client::Api::Request.post_request("#{base_uri}/create", create_data) parsed_response_body = JSON.parse(response.body).symbolize! if ok?(response) # Re-initialize the entity using the existing data as a base and overwriting with all data returned from the response # This will populate fields that have been auto-populated (e.g. id) into the original object entity.attributes = create_data.merge(parsed_response_body) else error = SBF::Client::ErrorEntity.new(parsed_response_body) entity.add_errors(error) end SBF::Client::Api::Response.new(http_code: response.code, data: entity, error: error) end |