dbAccessor 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67a4c4de72687a32de28ac35f226e3005b85861f
4
- data.tar.gz: eb556c400dc24d68c43499faa3e9076fe0b8c8aa
3
+ metadata.gz: 79af26c2ea9e2dd2159b10d45f1482cfd4940c4c
4
+ data.tar.gz: 025fa79b1230afcc6b225f204fd8cfd213299c21
5
5
  SHA512:
6
- metadata.gz: f781d73d92df60d8cdadcedff1602148324a5c77fadd7e745331fc2d7e43b7f81283dc5bb9ad717146273f0ab1b38ff1da86d4fd5b1f3232e8c09aeb397b5222
7
- data.tar.gz: ef21b5958da09dbf4e5d51d3b00a6153f5839b7dd36d4586c569c888e6bd74ac9ebe6346c529bc1182ebd9bff3b1f7be7bbcfccebaaae2c74f059b2beb8cfc49
6
+ metadata.gz: 91d866e68e3c0d32cf151b14219ea11f6af318c23fb1d9c35ccc67dd97dc97136febc9eccc4e8520f863bc3d94203dbe90d042801d19c939eab677bc350f3fc5
7
+ data.tar.gz: c16f94e505d41b3f6cd48f4741c30a2dd1315a02ffa9a9d711075e648959d3fdf28688fda4ff70c481edffa96ae8b66795342aa986b321107d67b1674bdec329
data/dbAccessor.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rake", "~> 10.3", ">= 10.3.2"
29
29
  spec.add_development_dependency "pg", "~> 0.17", ">= 0.17.1"
30
30
  spec.add_development_dependency "redis"
31
+ spec.add_development_dependency "rest-client"
31
32
  end
@@ -34,7 +34,8 @@ class DbAccessor::Reader < Db_Accessor::Base
34
34
  waited_keys = [:model_name,:identifiers]
35
35
  if validate(given_param,waited_keys) && validate_id(given_param[:identifiers])
36
36
  model_name = get_model_name(given_param)
37
- result = model_name.where(deleted: false).find(given_param[:identifiers])
37
+ result = model_name.where(deleted: false).where(id: given_param[:identifiers])
38
+ p result
38
39
  result.nil? ? return_response(404,"Not found") : return_response(200,result)
39
40
  else
40
41
  return_response(404,"Not found")
@@ -0,0 +1,33 @@
1
+ require_relative '../../../spec/feed/resources/environment'
2
+ require 'redis'
3
+
4
+ class Synchronizer
5
+
6
+ def self.load
7
+ apps = Application.all
8
+ users = User.all
9
+ redis = Redis.current
10
+ clean_redis(redis)
11
+
12
+ users.each do |u|
13
+ redis.sadd('users',{login: u.login,password: u.password}.to_json)
14
+ end
15
+
16
+ apps.each do |a|
17
+ redis.sadd('applications',{api_key: a.api_key}.to_json)
18
+ end
19
+ end
20
+
21
+ private ###############################################################################
22
+
23
+ def self.clean_redis(redis)
24
+ redis.del('users')
25
+ redis.del('applications')
26
+ end
27
+
28
+
29
+
30
+
31
+ end
32
+
33
+ Synchronizer.load
@@ -1,3 +1,3 @@
1
1
  module DbAccessor
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,10 +1,14 @@
1
1
 
2
2
  require 'active_record'
3
+ require 'rest-client'
3
4
  require_relative 'user'
4
5
  require_relative 'engine'
6
+ require_relative 'config'
7
+
5
8
 
6
9
  class Application < ActiveRecord::Base
7
10
  attr_accessor :api_key_to_update
11
+
8
12
 
9
13
  validates_presence_of :name, :api_key, :url
10
14
  validates_uniqueness_of :api_key, :url
@@ -25,7 +29,7 @@ class Application < ActiveRecord::Base
25
29
  def save_app
26
30
  option = {user: false,app: true}
27
31
  to_save = {api_key: api_key}.to_json
28
- AuthManager::Adder.save?(to_save,option)
32
+ RestClient.post("#{AUTH_MANAGER_URI}auth_manager/adder/save",{object: to_save,option: option})
29
33
  end
30
34
 
31
35
  def update_app
@@ -33,9 +37,9 @@ class Application < ActiveRecord::Base
33
37
  old_obj = {api_key: @api_key_to_update}.to_json
34
38
  to_update = {api_key: api_key}.to_json
35
39
  if deleted == false
36
- AuthManager::Updater.update(old_obj,to_update,option)
40
+ RestClient.put("#{AUTH_MANAGER_URI}auth_manager/updater/update",{object: to_update,old_object: old_obj,option: option})
37
41
  else
38
- AuthManager::Deleter.delete?(to_update,option)
42
+ RestClient.delete("#{AUTH_MANAGER_URI}auth_manager/deleter/delete",{object: to_update,option: option})
39
43
  end
40
44
  end
41
45
 
@@ -0,0 +1 @@
1
+ AUTH_MANAGER_URI = "http://localhost:9292/"
@@ -1,7 +1,9 @@
1
1
  require 'active_record'
2
2
  require 'auth_manager'
3
3
  require 'json'
4
+ require 'rest-client'
4
5
  require_relative 'application'
6
+ require_relative 'config'
5
7
 
6
8
  class User < ActiveRecord::Base
7
9
 
@@ -25,7 +27,7 @@ class User < ActiveRecord::Base
25
27
  def save_user
26
28
  option = {user: true,app: false}
27
29
  to_save = {login: login,password: password}.to_json
28
- AuthManager::Adder.save?(to_save,option)
30
+ RestClient.post("#{AUTH_MANAGER_URI}auth_manager/adder/save",{object: to_save,option: option})
29
31
  end
30
32
 
31
33
  def update_user
@@ -33,9 +35,9 @@ class User < ActiveRecord::Base
33
35
  old_obj = {login: @login_to_update,password: @passwd_to_update}.to_json
34
36
  to_update = {login: login,password: password}.to_json
35
37
  if deleted == false
36
- AuthManager::Updater.update(old_obj,to_update,option)
38
+ RestClient.put("#{AUTH_MANAGER_URI}auth_manager/updater/update",{object: to_update,old_object: old_obj,option: option})
37
39
  else
38
- AuthManager::Deleter.delete?(to_update,option)
40
+ RestClient.delete("#{AUTH_MANAGER_URI}auth_manager/deleter/delete",{object: to_update,option: option})
39
41
  end
40
42
  end
41
43
 
data/spec/reader_spec.rb CHANGED
@@ -53,6 +53,8 @@ describe DbAccessor::Reader do
53
53
 
54
54
  context "when it reads on a model with an id" do
55
55
  it {expect((DbAccessor::Reader.select_by_id({model_name: "User",identifiers: [5]}))[:code]).to eq 200 }
56
+
57
+ it {expect((DbAccessor::Reader.select_by_id({model_name: "User",identifiers: [5]}))[:message]).to_not eq nil }
56
58
  end
57
59
 
58
60
  context "when one of the ids is incorrect" do
data/spec/updater_spec.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  require_relative 'spec_helper'
2
+ require 'redis'
2
3
 
3
4
  describe DbAccessor::Updater do
4
5
 
5
6
  describe ".update_by_id" do
7
+
6
8
  context "updates one or many users by id" do
7
- param = {model_name: "User",attributes: { 72 => {login: "mamadouPouye"}} }
9
+ param = {model_name: "User",attributes: { 149 => {login: "mamadouPouye"}} }
8
10
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
9
11
  end
10
12
 
11
13
  context "updates one or many applications by id" do
12
- param = {model_name: "Application",attributes: { 3 => { name: "apache"},2 => {name: "site du zero"}} }
14
+ param = {model_name: "Application",attributes: {13 => {name: "apachou"},11 => {name: "site du zerou"}} }
13
15
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
14
16
  end
15
17
 
@@ -62,8 +64,8 @@ describe DbAccessor::Updater do
62
64
 
63
65
  end
64
66
 
65
- describe ".update_all_objects" do
66
- parameter={model_name: "User", attributes: {login: 'doudouna',password: 'passe'}}
67
+ describe ".update_all_objects" do
68
+ parameter={model_name: "User", attributes: {password: 'passe'}}
67
69
  context "when it updates all model objects" do
68
70
  it {expect((DbAccessor::Updater.update_all_objects(parameter))[:code]).to eq 200 }
69
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbAccessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fabira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-16 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,20 @@ dependencies:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: rest-client
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
135
149
  description: '"Module d''acces a la base de donnees "'
136
150
  email:
137
151
  - fabira90@gmail.com
@@ -152,6 +166,7 @@ files:
152
166
  - lib/dbAccessor/dbConnector.rb
153
167
  - lib/dbAccessor/deleter/deleter.rb
154
168
  - lib/dbAccessor/reader/reader.rb
169
+ - lib/dbAccessor/synchronizer/synchronizer.rb
155
170
  - lib/dbAccessor/updater/updater.rb
156
171
  - lib/dbAccessor/version.rb
157
172
  - lib/dbAccessor/writer/writer.rb
@@ -165,6 +180,7 @@ files:
165
180
  - spec/feed/dbTest/model/action.rb
166
181
  - spec/feed/dbTest/model/application.rb
167
182
  - spec/feed/dbTest/model/assignment.rb
183
+ - spec/feed/dbTest/model/config.rb
168
184
  - spec/feed/dbTest/model/engine.rb
169
185
  - spec/feed/dbTest/model/engine_data.rb
170
186
  - spec/feed/dbTest/model/user.rb
@@ -211,6 +227,7 @@ test_files:
211
227
  - spec/feed/dbTest/model/action.rb
212
228
  - spec/feed/dbTest/model/application.rb
213
229
  - spec/feed/dbTest/model/assignment.rb
230
+ - spec/feed/dbTest/model/config.rb
214
231
  - spec/feed/dbTest/model/engine.rb
215
232
  - spec/feed/dbTest/model/engine_data.rb
216
233
  - spec/feed/dbTest/model/user.rb