-
Notifications
You must be signed in to change notification settings - Fork 0
guillec/structo_client
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Structo Client:
This gem allows you to easily interface with your Structo Application.
Gem Dependencies:
gem 'rest-client'
gem 'json'
There are two ways to use this gem.
Non-MVC application:
1. require 'structo_client'
2. Create an instance of StructoClient:
c = StructoClient.new("app_name", "public_key", "private_key")
Your app_name must match your Structo application name.
3. Start using the basic CRUD methods:
To create:
c.create("Person")
If you have fields you need to pass them as a Hash.
c.create("Person", {"name" => "john"})
To retrieve:
c.retrieve("Person", "id")
To update:
c.update("Person", "id", {"name" => "juan"})
To delete:
c.delete("Person", "id")
To search
If you dont pass any search criteria it will return a list of all the values.
c.search("Person") #This will return a list
If you pass search criteria it will search based on the parameters.
c.search("Person", {"name" => "juan"}) #This will return all entries with the name Juan
Adding StructoRecord to your Rails app:
1. Add the gems to your rails project:
gem 'structo_client'
gem 'rest-client'
gem 'json'
2. Add a initializer file called structo_config.rb
Insert the following constants:
STRUCTO_APP_NAME='your application name'
STRUCTO_PUBLIC_KEY='your public key'
STRUCTO_PRIVATE_KEY='your private key'
3. Add a model that extends StructoRecord::Base
class Person < StructoRecord::Base
end
4. Using the CRUD methods:
To create:
p = Person.create
If you have attribute the pass in a Hash, example:
p = Person.create({“name” => “sam”}}
To retreive:
r = Person.retrieve(“id”)
To update:
u = Person.update(“id”, {“name” => “bob”})
To delete:
Person.delete(“id”)
To search
Person.search({“name” => “john”})
If you just say Person.search with no attributes it will return a list of all entries.
About
Client to communicate with Structo
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published