# https://developers.podio.com/doc/items
class Podio::ItemField < ActivePodio::Base
  property :field_id, :integer
  property :type, :string
  property :external_id, :string
  property :label, :string
  property :values, :array
  property :config, :hash

  alias_method :id, :field_id

  class << self
    # https://developers.podio.com/doc/items/update-item-field-values-22367
    def update(item_id, field_id, values)
      response = Podio.connection.put do |req|
        req.url "/item/#{item_id}/value/#{field_id}"
        req.body = values
      end
      response.body
    end

    # https://developers.podio.com/doc/calendar/get-item-field-calendar-as-ical-10195681
    def ical_entry(item_id, field_id)
      Podio.connection.get("/calendar/item/#{item_id}/field/#{field_id}/ics/").body
    end
  end
end

# https://developers.podio.com/doc/items
class Podio::ItemField < ActivePodio::Base
  property :field_id, :integer
  property :type, :string
  property :external_id, :string
  property :label, :string
  property :values, :array
  property :config, :hash

  alias_method :id, :field_id

  class << self
    # https://developers.podio.com/doc/items/update-item-field-values-22367
    def update(item_id, field_id, values)
      silent = values[:silent] ? '?silent=1' : ''
      values.delete(:silent) if values && values[:silent]
      response = Podio.connection.put do |req|
        req.url "/item/#{item_id}/value/#{field_id}#{silent}"
        req.body = values
      end
      response.body
    end

    # https://developers.podio.com/doc/calendar/get-item-field-calendar-as-ical-10195681
    def ical_entry(item_id, field_id)
      Podio.connection.get("/calendar/item/#{item_id}/field/#{field_id}/ics/").body
    end
  end
end

Handle silent updates of item field values
Handle silent updates of item field values
