Class: Ketchup::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/ketchup/item.rb

Overview

Represents a list/agenda item in a meeting. Only the content is editable.

If you want to change the order of items, you can do that using Ketchup::ItemArray (the meeting’s item array).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, meeting, params = {}) ⇒ Item

Create a new item for a given meeting, using an existing api connection. You generally won’t want to call this yourself - the better interface to create new items is via a meeting’s item array.

However, if you are doing some internal hacking, it’s worth noting that all keys for parameters in the hash should be strings, not symbols.

Examples:

Ketchup::Item.new api, meeting, 'content' => "Treasurer's Report"

Parameters:

  • api (Ketchup::API)

    The API connection

  • meeting (Ketchup::Meeting)

    The meeting the item will belong to

  • params (Hash) (defaults to: {})

    Any other details for the item.

See Also:



27
28
29
30
31
32
33
34
# File 'lib/ketchup/item.rb', line 27

def initialize(api, meeting, params = {})
  @api     = api
  @meeting = meeting
  
  overwrite params
  
  @notes = Ketchup::NoteArray.new @api, self, (params['notes'] || [])
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def api
  @api
end

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/ketchup/item.rb', line 9

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def created_at
  @created_at
end

#meetingObject (readonly)

Returns the value of attribute meeting.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def meeting
  @meeting
end

#meeting_idObject (readonly)

Returns the value of attribute meeting_id.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def meeting_id
  @meeting_id
end

#notesObject (readonly)

Returns the value of attribute notes.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def notes
  @notes
end

#positionObject (readonly)

Returns the value of attribute position.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def position
  @position
end

#shortcode_urlObject (readonly)

Returns the value of attribute shortcode_url.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def shortcode_url
  @shortcode_url
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



7
8
9
# File 'lib/ketchup/item.rb', line 7

def updated_at
  @updated_at
end

Instance Method Details

#destroyObject

Deletes the item from the server. If the item has never been saved, this method will do nothing at all.



59
60
61
62
63
# File 'lib/ketchup/item.rb', line 59

def destroy
  return if new_record?
  
  @api.delete "/items/#{shortcode_url}.json"
end

#new_record?Boolean

Indicates whether the item exists on the server yet.

Returns:

  • (Boolean)

    True if the item does not exist on the server.



40
41
42
# File 'lib/ketchup/item.rb', line 40

def new_record?
  shortcode_url.nil?
end

#saveObject

Saves the item to the server, whether it’s a new item or an existing one. This does not save underlying notes.



47
48
49
50
51
52
53
54
# File 'lib/ketchup/item.rb', line 47

def save
  if new_record?
    overwrite @api.post("/meetings/#{meeting.shortcode_url}/items.json",
      'content' => content)
  else
    overwrite @api.put("/items/#{shortcode_url}.json", 'content' => content)
  end
end