Class: ChinoRuby::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
Instance Method Details
#add_document(document_id, collection_id) ⇒ Object
1111
1112
1113
1114
1115
|
# File 'lib/chino_ruby/classes.rb', line 1111
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
1088
1089
1090
1091
1092
1093
1094
|
# File 'lib/chino_ruby/classes.rb', line 1088
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
1105
1106
1107
1108
1109
|
# File 'lib/chino_ruby/classes.rb', line 1105
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
1064
1065
1066
1067
1068
1069
|
# File 'lib/chino_ruby/classes.rb', line 1064
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
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
|
# File 'lib/chino_ruby/classes.rb', line 1071
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
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
|
# File 'lib/chino_ruby/classes.rb', line 1123
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
1117
1118
1119
1120
1121
|
# File 'lib/chino_ruby/classes.rb', line 1117
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
1096
1097
1098
1099
1100
1101
1102
1103
|
# File 'lib/chino_ruby/classes.rb', line 1096
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
|