Class: Collections
Instance Method Summary
collapse
#delete_resource, #get_resource, #initialize, #parse_response, #patch_resource, #post_resource, #post_resource_with_string_result, #put_resource, #return_uri
Methods inherited from CheckValues
#check_boolean, #check_int, #check_json, #check_string
Constructor Details
This class inherits a constructor from ChinoBaseAPI
Instance Method Details
#add_document(document_id, collection_id) ⇒ Object
1167
1168
1169
1170
1171
|
# File 'lib/chino_ruby.rb', line 1167
def add_document(document_id, collection_id)
check_string(document_id)
check_string(collection_id)
post_resource("/collections/#{collection_id}/documents/#{document_id}")
end
|
#create_collection(name) ⇒ Object
1144
1145
1146
1147
1148
1149
1150
|
# File 'lib/chino_ruby.rb', line 1144
def create_collection(name)
check_string(name)
data = {"name": name}.to_json
col = Collection.new
col.from_json(post_resource("/collections", data).to_json, true)
col
end
|
#delete_collection(collection_id, force) ⇒ Object
1161
1162
1163
1164
1165
|
# File 'lib/chino_ruby.rb', line 1161
def delete_collection(collection_id, force)
check_string(collection_id)
check_boolean(force)
delete_resource("/collections/#{collection_id}", force)
end
|
#get_collection(collection_id) ⇒ Object
1120
1121
1122
1123
1124
1125
|
# File 'lib/chino_ruby.rb', line 1120
def get_collection(collection_id)
check_string(collection_id)
col = Collection.new
col.from_json(get_resource("/collections/#{collection_id}").to_json, true)
col
end
|
#list_collections(limit = nil, offset = nil) ⇒ Object
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
|
# File 'lib/chino_ruby.rb', line 1127
def list_collections(limit=nil, offset=nil)
cols = GetCollectionsResponse.new
if limit==nil && offset==nil
cols.from_json(get_resource("/collections", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
else
cols.from_json(get_resource("/collections", limit, offset).to_json)
end
cs = cols.collections
cols.collections = []
cs.each do |c|
col = Collection.new
col.from_json(c.to_json)
cols.collections.push(col)
end
cols
end
|
#list_documents(collection_id, limit = nil, offset = nil) ⇒ Object
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
|
# File 'lib/chino_ruby.rb', line 1179
def list_documents(collection_id, limit=nil, offset=nil)
check_string(collection_id)
docs = GetDocumentsResponse.new
if limit==nil && offset==nil
docs.from_json(get_resource("/collections/#{collection_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
else
docs.from_json(get_resource("/collections/#{collection_id}/documents", limit, offset).to_json)
end
ds = docs.documents
docs.documents = []
ds.each do |d|
doc = Document.new
doc.from_json(d.to_json)
docs.documents.push(doc)
end
docs
end
|
#remove_document(document_id, collection_id) ⇒ Object
1173
1174
1175
1176
1177
|
# File 'lib/chino_ruby.rb', line 1173
def remove_document(document_id, collection_id)
check_string(document_id)
check_string(collection_id)
delete_resource("/collections/#{collection_id}/documents/#{document_id}", false)
end
|
#update_collection(collection_id, name) ⇒ Object
1152
1153
1154
1155
1156
1157
1158
1159
|
# File 'lib/chino_ruby.rb', line 1152
def update_collection(collection_id, name)
check_string(collection_id)
check_string(name)
data = {"name": name}.to_json
col = Collection.new
col.from_json(put_resource("/collections/#{collection_id}", data).to_json, true)
col
end
|