towsta 0.1.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/towsta/synchronizer.rb +7 -7
- data/lib/towsta/version.rb +1 -1
- data/lib/towsta/vertical.rb +26 -8
- data/lib/towsta.rb +4 -0
- metadata +4 -4
data/lib/towsta/synchronizer.rb
CHANGED
@@ -73,13 +73,13 @@ module Towsta
|
|
73
73
|
|
74
74
|
def self.callback json
|
75
75
|
json = JSON.parse json, :symbolize_names => true
|
76
|
-
if json[:action] == 'create'
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
return eval(json[:vertical]).new json[:attributes] if json[:action] == 'create'
|
77
|
+
return eval(json[:vertical]).update json[:attributes] if json[:action] == 'update'
|
78
|
+
eval(json[:vertical]).destroy json[:attributes][:id]
|
79
|
+
end
|
80
|
+
|
81
|
+
def authenticate code
|
82
|
+
JSON.parse Net::HTTP.start("manager.towsta.com"){|http| @json = http.get("/synchronizers/#{@secret}/#{code}.json").body}, :symbolize_names => true
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
data/lib/towsta/version.rb
CHANGED
data/lib/towsta/vertical.rb
CHANGED
@@ -13,6 +13,10 @@ module Towsta
|
|
13
13
|
def self.create(args)
|
14
14
|
klass = Class.new do
|
15
15
|
|
16
|
+
class << self
|
17
|
+
attr_accessor :all, :attributes
|
18
|
+
end
|
19
|
+
|
16
20
|
args[:slices].each do |attr, kind|
|
17
21
|
eval "def #{attr}= value; #{Vertical.parse_set attr, kind}; end;"
|
18
22
|
eval "def #{attr}; #{Vertical.parse_get attr, kind}; end;"
|
@@ -20,10 +24,6 @@ module Towsta
|
|
20
24
|
eval "def self.find_all_by_#{attr} value; found = []; self.all.each {|e| found << e if e.#{attr} == value}; found; end;"
|
21
25
|
end
|
22
26
|
|
23
|
-
class << self
|
24
|
-
attr_accessor :all, :tree
|
25
|
-
end
|
26
|
-
|
27
27
|
def self.count
|
28
28
|
self.all.size
|
29
29
|
end
|
@@ -37,12 +37,11 @@ module Towsta
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.find id
|
40
|
-
self.
|
40
|
+
self.find_by_id id
|
41
41
|
end
|
42
42
|
|
43
43
|
def initialize args
|
44
44
|
args.each {|k,v| eval "self.#{k}= '#{v}';"}
|
45
|
-
self.class.tree ? self.class.tree.add(self) : self.class.tree=(Tree.new(self))
|
46
45
|
self.class.all << self
|
47
46
|
end
|
48
47
|
|
@@ -56,17 +55,35 @@ module Towsta
|
|
56
55
|
|
57
56
|
def destroy
|
58
57
|
self.class.all.delete self
|
59
|
-
self.class.tree.delete self
|
60
58
|
self
|
61
59
|
end
|
62
60
|
|
63
61
|
def self.destroy id
|
64
62
|
element = self.find id
|
65
63
|
self.all.delete element
|
66
|
-
self.tree.delete element
|
67
64
|
element
|
68
65
|
end
|
69
66
|
|
67
|
+
def save creator=$towsta_default_author
|
68
|
+
export = self.attributes
|
69
|
+
export.delete :author
|
70
|
+
export.delete :vertical
|
71
|
+
id_aux = export.delete(:id)
|
72
|
+
export = {:creator => creator, :vertical => self.class.to_s, :attributes => export, :id => id_aux}
|
73
|
+
uri = URI.parse("http://manager.towsta.com/synchronizers/#{$towsta_secret}/insert.json")
|
74
|
+
JSON.parse Net::HTTP.post_form(uri, {:code => export.to_json}).body.to_s, :symbolize_names => true
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.create args
|
78
|
+
self.new(args).save
|
79
|
+
end
|
80
|
+
|
81
|
+
def attributes
|
82
|
+
horizontal = {:vertical => self.class.to_s}
|
83
|
+
self.class.attributes.each {|attr| horizontal[attr] = eval(attr.to_s).to_s}
|
84
|
+
horizontal
|
85
|
+
end
|
86
|
+
|
70
87
|
def find_horizontal id
|
71
88
|
Vertical.all.each do |v|
|
72
89
|
horizontal = v.find_by_id id.to_i
|
@@ -77,6 +94,7 @@ module Towsta
|
|
77
94
|
|
78
95
|
end
|
79
96
|
klass.all = []
|
97
|
+
klass.attributes = args[:slices].keys
|
80
98
|
Object.const_set args[:name], klass
|
81
99
|
end
|
82
100
|
|
data/lib/towsta.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mortaro
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-17 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|