-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
77 lines (54 loc) · 1.79 KB
/
README
File metadata and controls
77 lines (54 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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.