Class: ChinoRuby::Documents
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
#create_document(schema_id, content) ⇒ Object
999
1000
1001
1002
1003
1004
1005
1006
|
# File 'lib/chino_ruby/classes.rb', line 999
def create_document(schema_id, content)
check_string(schema_id)
check_json(content)
data = {"content": content}.to_json
document = Document.new
document.from_json(post_resource("/schemas/#{schema_id}/documents", data).to_json, true)
document
end
|
#delete_document(document_id, force) ⇒ Object
1021
1022
1023
1024
1025
|
# File 'lib/chino_ruby/classes.rb', line 1021
def delete_document(document_id, force)
check_string(document_id)
check_boolean(force)
delete_resource("/documents/#{document_id}", force)
end
|
#get_document(document_id) ⇒ Object
965
966
967
968
969
970
|
# File 'lib/chino_ruby/classes.rb', line 965
def get_document(document_id)
check_string(document_id)
d = Document.new
d.from_json(get_resource("/documents/#{document_id}").to_json, true)
d
end
|
#list_documents(schema_id, full_document, limit = nil, offset = nil) ⇒ Object
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
|
# File 'lib/chino_ruby/classes.rb', line 972
def list_documents(schema_id, full_document, limit=nil, offset=nil)
check_string(schema_id)
check_boolean(full_document)
docs = GetDocumentsResponse.new
if limit==nil && offset==nil
if full_document
docs.from_json(get_resource("/schemas/#{schema_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0, true).to_json)
else
docs.from_json(get_resource("/schemas/#{schema_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
end
else
if full_document
docs.from_json(get_resource("/schemas/#{schema_id}/documents", limit, offset, true).to_json)
else
docs.from_json(get_resource("/schemas/#{schema_id}/documents", limit, offset).to_json)
end
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
|
#update_document(document_id, content, is_active = nil) ⇒ Object
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
|
# File 'lib/chino_ruby/classes.rb', line 1008
def update_document(document_id, content, is_active=nil)
check_string(document_id)
check_json(content)
if is_active.nil?
data = {"content": content}.to_json
else
data = {"content": content, "is_active": is_active}.to_json
end
document = Document.new
document.from_json(put_resource("/documents/#{document_id}", data).to_json, true)
document
end
|