Method: Orchestrate::Client#put

Defined in:
lib/orchestrate/client.rb

#put(collection, key, body, condition = nil) ⇒ Object Also known as: put_if_unmodified

Updates the value associated with a key. If the key does not currently have a value, will create the value.

Parameters:

  • collection (#to_s)

    The name of the collection.

  • key (#to_s)

    The name of the key.

  • body (#to_json)

    The value for the key.

  • condition (String, false, nil) (defaults to: nil)

    Conditions for setting the value. If String, value used as If-Match, value will only be updated if key's current value's ref matches. If false, uses If-None-Match the value will only be set if there is no existent value for the key. If nil (default), value is set regardless.

Returns:

  • Orchestrate::API::ItemResponse

Raises:

  • Orchestrate::API::BadRequest the body is not valid JSON.

  • Orchestrate::API::IndexingConflict One of the value's keys contains a value of a different type than the schema that exists for the collection.

  • Orchestrate::API::VersionMismatch A ref was provided, but it does not match the ref for the current value.

  • Orchestrate::API::AlreadyPresent the false condition was given, but a value already exists for this collection/key combo.

See Also:

[View source]

151
152
153
154
155
156
157
158
159
# File 'lib/orchestrate/client.rb', line 151

def put(collection, key, body, condition=nil)
  headers={}
  if condition.is_a?(String)
    headers['If-Match'] = API::Helpers.format_ref(condition)
  elsif condition == false
    headers['If-None-Match'] = '"*"'
  end
  send_request :put, [collection, key], { body: body, headers: headers, response: API::ItemResponse }
end