Method: SBF::Client::PhotoEndpoint#create

Defined in:
lib/stbaldricks/endpoints/photo.rb

#create(entity_or_hash, with = {}) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stbaldricks/endpoints/photo.rb', line 6

def create(entity_or_hash, with = {})
  entity = entity_or_hash.is_a?(Hash) ? target_class.new(entity_or_hash) : entity_or_hash
  raise SBF::Client::Error, 'Invalid Entity' unless entity.is_a?(SBF::Client::BaseEntity)

  with = normalize_with(with)

  create_data = entity.dirty_data
  filename = create_data.delete(:filename)
  file = create_data.delete(:file)
  create_data.store(:with, with)

  response = SBF::Client::Api::Request.file_post_request(path: "#{base_uri}/create", params: create_data, file: file, filename: filename)

  hydrated_entity(response, create_data, entity)
end