Class: Sharepoint::List

Inherits:
Object show all
Includes:
Type
Defined in:
lib/sharepoint-lists.rb

Instance Attribute Summary

Attributes inherited from Object

#parent

Attributes inherited from ObjectProperties

#data, #site, #updated_data

Instance Method Summary collapse

Methods included from Type

#initialize

Methods inherited from Object

#copy, #destroy, #guid, #initialize, #reload, #save

Methods inherited from ObjectProperties

#add_properties, #add_property, #available_properties, #initialize

Instance Method Details

#add_folder(path, attributes) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/sharepoint-lists.rb', line 98

def add_folder path, attributes
  path      = path.gsub(/\/*$/, '') # remove slashes at the end of the path
  site_url  = "#{@site.protocol}://#{@site.server_url}/"
  action    = "#{site_url}_vti_bin/listdata.svc/#{self.title}"
  path      = root_folder.server_relative_url + '/' + path
  attributes['ContentTypeID'] ||= '0x01200059042D1A09191046851FA83D5B89816A'
  attributes['Path']          ||= path
  payload                       = VtiBin.translate_field_names(attributes).to_json
  # Create the item using _vti_bin api
  response = @site.query :post, action, payload, true do |curl|
    curl.headers['Slug'] = "#{path}/#{attributes['Title']}|0x0120"
  end
  response = JSON.parse response
  unless response['d'].nil?
    # Fetch the item we just created using the REST api
    item_id = response['d']['ID']
    @site.query :get, "#{site_url}_api/#{['id']}/items(#{item_id})"
  else
    raise Sharepoint::SPException.new response, action, payload
  end
end

#add_item(attributes) ⇒ Object



92
93
94
95
96
# File 'lib/sharepoint-lists.rb', line 92

def add_item attributes
  attributes['__metadata']         ||= Hash.new
  attributes['__metadata']['type'] ||= list_item_entity_type_full_name
  @site.query :post, item_uri, attributes.to_json
end

#find_items(options = {}) ⇒ Object



84
85
86
# File 'lib/sharepoint-lists.rb', line 84

def find_items options = {}
  @site.query :get, (make_item_filter options)
end

#item_countObject



88
89
90
# File 'lib/sharepoint-lists.rb', line 88

def item_count
  @site.query :get, "#{['id']}/ItemCount"
end