Permalink
Browse files

Added simple example run like tutorial

at http://code.google.com/p/xci-clients/wiki/SimpleContactExample

Signed-off-by: xoopit <cameron+xoopit@nb.io>
  • Loading branch information...
cee-dub authored and xoopit committed May 4, 2009
1 parent b42a34c commit a98cf6a99f6344b7452beaf6d32e38002d769faa
Showing with 93 additions and 7 deletions.
  1. +67 −0 README.markdown
  2. +0 −7 README.rdoc
  3. +26 −0 simple.contact.xml
@@ -0,0 +1,67 @@
cloudquery
==========
Client for Xoopit's cloudquery API
## Simple contacts application example
> require 'cloudquery'
=> true
> include Cloudquery
=> Object
> secret = Client.get_secret(<account_name>, <password>)
=> "your secret appears here"
> c = Client.new(:account => '<account_name>', :secret => secret)
=> #<Cloudquery::Client:0x10b1b24 @secure=true, @secret="your secret appears here", @account="<account_name>", @document_id_method=nil>
> c.add_indexes('superheroes')
=> {"result"=>["kMzzzybpqpY"], "size"=>1, "STATUS"=>200}
> c.add_schema(File.open('simple.contact.xml'))
=> {"result"=>["ubKme0EX3H2ud7VhBU7qngk3........."], "size"=>1, "STATUS"=>201}
> doc = {
'simple.contact.name' => 'Steve Rogers',
'simple.contact.email' => ['steve.rogers@example.com','captain.america@marvel.com'],
'simple.contact.telephone' => ['555-555-5555','123-456-6789'],
'simple.contact.address' => ['Lower East Side, NY NY'],
'simple.contact.birthday' => Date.parse('July 4, 1917'),
'simple.contact.note' => 'Captain America!',
}
=> {"simple.contact.birthday"=>#<Date: 4842827/2,0,2299161>, "simple.contact.address"=>["Lower East Side, NY NY"], "simple.contact.telephone"=>["555-555-5555", "123-456-6789"], "simple.contact.note"=>"Captain America!", "simple.contact.email"=>["steve.rogers@example.com", "captain.america@marvel.com"], "simple.contact.name"=>"Steve Rogers"}
> c.add_documents('superheroes', doc, 'simple.contact')
=> {"result"=>["nDLCNLPo3oHtxANzG4YBn5kMzzzybpqpY"], "size"=>1, "STATUS"=>201}
> docs = [
{
'simple.contact.name' => 'Clark Kent',
'simple.contact.email' => ['clark.kent@example.com','superman@dc.com'],
'simple.contact.telephone' => ['555-123-1234','555-456-6789'],
'simple.contact.address' => ['344 Clinton St., Apt. #3B, Metropolis', 'The Fortess of Solitude, North Pole'],
'simple.contact.birthday' => Date.parse('June 18, 1938'),
'simple.contact.note' => 'Superhuman strength, speed, stamina, durability, senses, intelligence, regeneration, and longevity; super breath, heat vision, x-ray vision and flight. Member of the justice league.'
},
{
'simple.contact.name' => 'Bruce Wayne',
'simple.contact.email' => ['bruce.wayne@example.com','batman@dc.com'],
'simple.contact.telephone' => ['555-123-6666','555-456-6666'],
'simple.contact.address' => ['1007 Mountain Drive, Gotham', 'The Batcave, Gotham'],
'simple.contact.birthday' => Date.parse('February 19, 1939'),
'simple.contact.note' => 'Sidekick is Robin. Has problems with the Joker. Member of e justice league.'
}
]
> c.add_documents('superheroes', docs, 'simple.contact')
=> {"result"=>["lQgByVSvJk1skHtKpMYX40kMzzzybpqpY", "weJF4uDPJrlvrETTJQNibFkMzzzybpqpY"], "size"=>2, "STATUS"=>201}
> c.count_documents('superheroes', '*', 'simple.contact')
=> {"result"=>3, "matches"=>3, "STATUS"=>200}
> c.get_documents('superheroes', '*', {:fields => 'simple.contact.name'}, 'simple.contact')
=> {"result"=>[{"simple.contact.name"=>"Steve Rogers"}, {"simple.contact.name"=>"Clark Kent"}, {"simple.contact.name"=>"Bruce Wayne"}], "matches"=>3, "size"=>3, "STATUS"=>200}
> c.get_documents('superheroes', 'name:Steve', {:fields => 'simple.contact.name'}, 'simple.contact')
=> {"result"=>[{"simple.contact.name"=>"Steve Rogers"}], "matches"=>1, "size"=>1, "STATUS"=>200}
> c.get_documents('superheroes', ':@:justice', {:fields => 'simple.contact.name'}, 'simple.contact')
=> {"result"=>[{"simple.contact.name"=>"Clark Kent"}, {"simple.contact.name"=>"Bruce Wayne"}], "matches"=>2, "size"=>2, "STATUS"=>200}
> c.modify_documents('superheroes', 'name:steve', {'simple.contact.note' => 'His name is STEVE!'}, 'simple.contact')
=> {"result"=>["nDLCNLPo3oHtxANzG4YBn5kMzzzybpqpY"], "matches"=>1, "size"=>1, "STATUS"=>200}
> c.delete_documents('superheroes', 'name:steve', 'simple.contact') => {"result"=>["nDLCNLPo3oHtxANzG4YBn5kMzzzybpqpY"], "matches"=>2, "size"=>1, "STATUS"=>200}
Copyright
---------
Copyright (c) 2009 nb.io, LLC and Xoopit, Inc. See LICENSE for details.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,26 @@
<schema name="simple.contact" store="yes">
<!-- The full name of the contact -->
<field name="name"
type="string"
analyzer="LCWhitespaceAnalyzer"
usage="user" />
<!-- The email addresses. A json array: email address -->
<field name="email"
type="string"
usage="user" />
<!-- The phone numbers. A json array: phone number -->
<field name="telephone"
type="string"
usage="user" />
<!-- The addresses. A json array: address -->
<field name="address"
type="string"
usage="user" />
<!-- The birthday of the contact-->
<field name="birthday"
type="date" />
<!-- A note for the contact-->
<field name="note"
type="text"
usage="user" />
</schema>

0 comments on commit a98cf6a

Please sign in to comment.