blsk_ruby_core_api 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: 8b62f0a05339dd11dcdf67bef08df3ff21bbe79c70584147172c56a7377b3749
4
- data.tar.gz: fef2b9fcbe9a974914cc3e22c1c0957fa5aa932d541c5a6999e5925d80156fbe
3
+ metadata.gz: 7b3b215fa09bf2314a87a1c65dd89bd2831d6e9fe5d3d1c0c029b4191c269b61
4
+ data.tar.gz: af3303db5efecd8196d61199003fd81a9359e06794d5f70c443f5de4d30228a9
5
5
  SHA512:
6
- metadata.gz: acfc64d3a0f15b22513f434d11709740c484921f9da039b1cf5b810b10adc49253e2f037a51f5e11d734db4d6b128701c813e176cda61c85294f43139be057ad
7
- data.tar.gz: f688ca59afa69fbae5b2d9b162c331d62404af913806f0cb150e825dc62f6c5ca464991234a6162d09816fc0b37a588967fa4fa68df5b63c8d1ad025dd796427
6
+ metadata.gz: de76b2ceba5a1bed4548863b5fbc5446f333b23b4867a24c532afa3db4c1727bb2637c82255ab52be7a00b05393b7f467d6861d6755c60becb7a1b24d612d6dd
7
+ data.tar.gz: eb2a7d559858d29f8f46f1496574ff030a5a66cc0d7793bcca72baeb8960a27922168163724855a027339f0334a51ec6643cc2958f5230bcf52c2af1d5e36695
@@ -4,7 +4,8 @@ module ApplicationConfiguration
4
4
  def config
5
5
  {
6
6
  rest: config_rest,
7
- consul: config_consul
7
+ consul: config_consul,
8
+ cassandra: config_cassandra
8
9
  }
9
10
  end
10
11
 
@@ -33,13 +34,22 @@ module ApplicationConfiguration
33
34
  end
34
35
 
35
36
  def config_rest
36
- config_rest = {
37
+ {
37
38
  host: 'localhost',
38
39
  port: 9292,
39
40
  path: '/api/v1'
40
41
  }
41
42
  end
42
43
 
44
+ def config_cassandra
45
+ {
46
+ # user_name: '', # turn on if any
47
+ # password: '', # turn on if any
48
+ hosts: ['172.16.15.3'],
49
+ port: 9042
50
+ }
51
+ end
52
+
43
53
  def random_name
44
54
  "health-check-#{SecureRandom.urlsafe_base64(8)}"
45
55
  end
@@ -15,12 +15,12 @@ module AbstractedCassandraRepository
15
15
  end
16
16
  end
17
17
 
18
- def create(value_hashes={}, keyspace_name=nil, table_name=nil)
18
+ def create(cql_query='', keyspace_name=nil, table_name=nil)
19
19
  # puts 'create'
20
20
  if keyspace_name && table_name
21
21
  session = cassandra_cluster.connect(keyspace_name)
22
- cql = '' # Building the cql using 'INSERT INTO' with 'IF NOT EXISTS'
23
- result = session.execute(cql)
22
+ # Building the cql using 'INSERT INTO' with 'IF NOT EXISTS'
23
+ result = session.execute(cql_query)
24
24
  end
25
25
  end
26
26
 
@@ -28,8 +28,8 @@ module AbstractedCassandraRepository
28
28
  # puts 'update'
29
29
  if keyspace_name && table_name
30
30
  session = cassandra_cluster.connect(keyspace_name)
31
- cql = '' # Building the cql using UPDATE
32
- result = session.execute(cql)
31
+ # Building the cql using UPDATE
32
+ result = session.execute(cql_query)
33
33
  end
34
34
  end
35
35
 
@@ -37,8 +37,8 @@ module AbstractedCassandraRepository
37
37
  # puts 'save'
38
38
  if keyspace_name && table_name
39
39
  session = cassandra_cluster.connect(keyspace_name)
40
- cql = '' # Building the cql using 'INSERT INTO' without 'IF NOT EXISTS'
41
- result = session.execute(cql)
40
+ # Building the cql using 'INSERT INTO' without 'IF NOT EXISTS'
41
+ result = session.execute(cql_query)
42
42
  end
43
43
  end
44
44
 
@@ -49,4 +49,11 @@ module AbstractedCassandraRepository
49
49
  result = session.execute("DELETE FROM #{table_name} WHERE id = ?", arguments: [id])
50
50
  end
51
51
  end
52
+
53
+ def run_cql(cql_query='', keyspace_name=nil, table_name=nil)
54
+ if keyspace_name && table_name
55
+ session = cassandra_cluster.connect(keyspace_name)
56
+ result = session.execute(cql_query)
57
+ end
58
+ end
52
59
  end
@@ -0,0 +1,10 @@
1
+ module CassandraConfiguration
2
+ extend ApplicationConfiguration
3
+
4
+ CONFIG = {
5
+ # user_name: '', # turn on if any
6
+ # password: '', # turn on if any
7
+ hosts: [],
8
+ port: 9042
9
+ }.merge( CassandraConfiguration.config_cassandra )
10
+ end
@@ -1,9 +1,12 @@
1
1
  require 'cassandra'
2
+ require 'query_builder'
2
3
  require_relative '../ioc/injector'
4
+ require_relative 'cassandra_configuration'
3
5
  require_relative 'abstracted_cassandra_repository'
4
6
 
5
7
  class CassandraService
6
- include ::AbstractedCassandraRepository
8
+ extend CassandraConfiguration
9
+ include AbstractedCassandraRepository
7
10
 
8
11
  injector
9
12
 
@@ -11,13 +14,13 @@ class CassandraService
11
14
 
12
15
  def initialize
13
16
  # puts 'init cassandra'
14
- self.cassandra_cluster = Cassandra.cluster
17
+ self.cassandra_cluster = Cassandra.cluster(CassandraConfiguration::CONFIG)
15
18
  end
16
19
 
17
20
  def start
18
21
  # puts 'start cassandra, create cluster'
19
22
  if !cassandra_cluster
20
- cassandra_cluster = Cassandra.cluster
23
+ cassandra_cluster = Cassandra.cluster(CassandraConfiguration::CONFIG)
21
24
  end
22
25
  cassandra_cluster
23
26
  end
@@ -2,17 +2,17 @@ require_relative '../rest/rest_service'
2
2
 
3
3
  module Validator
4
4
  def validate params={}
5
- lambda {|self_model, *args, &blk|
6
- # puts "Validate"
7
- seed_model = args[0]
8
- self_rest = args [1]
9
- valid_result = check_validate(seed_model, self_rest) # check validation and return [true]/[false, errors]
10
- if valid_result[0]
11
- true
12
- else
5
+ lambda {|self_model, *args, &blk|
6
+ # puts "Validate"
7
+ seed_model = args[0]
8
+ self_rest = args [1]
9
+ valid_result = check_validate(seed_model, self_rest) # check validation and return [true]/[false, errors]
10
+ if valid_result[0]
11
+ true
12
+ else
13
13
  valid_result[2].response_with_error(CommonError::InvalidData, valid_result[1])
14
- end
15
- }
14
+ end
15
+ }
16
16
  end
17
17
 
18
18
  def check_validate(seed_model, self_rest)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blsk_ruby_core_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fusin Thang
@@ -110,6 +110,26 @@ dependencies:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: 3.2.2
113
+ - !ruby/object:Gem::Dependency
114
+ name: query_builder
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 0.0.4
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.0.4
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.0.4
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.0.4
113
133
  - !ruby/object:Gem::Dependency
114
134
  name: request_store
115
135
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +260,7 @@ files:
240
260
  - lib/application_configuration.rb
241
261
  - lib/blsk_ruby_core_api.rb
242
262
  - lib/cassandra/abstracted_cassandra_repository.rb
263
+ - lib/cassandra/cassandra_configuration.rb
243
264
  - lib/cassandra/cassandra_service.rb
244
265
  - lib/consul/consul_configuration.rb
245
266
  - lib/consul/consul_service.rb