sample_core_api 0.0.1.dev

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b57b38c5aec822393177dffcfa208dad251c4d8634c77cd4c42fa663b59e680e
4
+ data.tar.gz: 2a0e6ddf3c0afa6b4abbd9c28de7706d4d557e185158c84e670ba2cdf19436bf
5
+ SHA512:
6
+ metadata.gz: 33526753dc7b7efdfe92ee57cd537efa34eb31bacf3f5106f2b6b0fb37a63141477872a61ca22f70c79a0f7d222f4a92330de447b62176f2a49ff22af8fefd93
7
+ data.tar.gz: 8ac35b355cbb20794387609a0ebdbf5a371dd7d6ee0fe7934bf10fa689207c9e592046fbca6321c99bf26f0de6d5bbc1774846ce1c0ec81d8ce3e83e5501d689
@@ -0,0 +1,12 @@
1
+ module ApplicationConfiguration
2
+ def config
3
+ {
4
+ consul: {
5
+
6
+ },
7
+ rest: {
8
+
9
+ },
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module ApplicationService
2
+ IMPORT_SERVICES = ['cassandra_service', 'consul_service']
3
+
4
+ def load_services
5
+ $service_list = {}
6
+ IMPORT_SERVICES.each do |service_name|
7
+ if !service_name.include?('rest_service')
8
+ puts "load_services #{service_name}"
9
+ class_name = service_name.split('_').map{|e| e.capitalize}.join
10
+ class_object = Object.const_get(class_name)
11
+ $service_list["#{service_name}"] = class_object.new
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ module AbstractedCassandraRepository
2
+ def find_by_id(id, keyspace_name, table_name)
3
+ puts 'find_by_id'
4
+ session = cassandra_cluster.connect(keyspace_name)
5
+ result = session.execute("SELECT * FROM #{table_name} WHERE id = ?", arguments: [id])
6
+ end
7
+
8
+ def find_all(keyspace_name, table_name)
9
+ puts 'find_all'
10
+ session = cassandra_cluster.connect(keyspace_name)
11
+ result = session.execute("SELECT * FROM #{table_name}")
12
+ end
13
+
14
+ def create(value_hashes={}, keyspace_name, table_name)
15
+ puts 'create'
16
+ session = cassandra_cluster.connect(keyspace_name)
17
+ cql = '' # Building the cql using 'INSERT INTO' with 'IF NOT EXISTS'
18
+ result = session.execute(cql)
19
+ end
20
+
21
+ def update(id, value_hashes={}, keyspace_name, table_name)
22
+ puts 'update'
23
+ session = cassandra_cluster.connect(keyspace_name)
24
+ cql = '' # Building the cql using UPDATE
25
+ result = session.execute(cql)
26
+ end
27
+
28
+ def save(value_hashes={}, keyspace_name, table_name)
29
+ puts 'save'
30
+ session = cassandra_cluster.connect(keyspace_name)
31
+ cql = '' # Building the cql using 'INSERT INTO' without 'IF NOT EXISTS'
32
+ result = session.execute(cql)
33
+ end
34
+
35
+ def delete(id, keyspace_name, table_name)
36
+ puts 'delete'
37
+ session = cassandra_cluster.connect(keyspace_name)
38
+ result = session.execute("DELETE FROM #{table_name} WHERE id = ?", arguments: [id])
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require 'cassandra'
2
+ require_relative 'abstracted_cassandra_repository'
3
+
4
+ class CassandraService
5
+ include ::AbstractedCassandraRepository
6
+
7
+ attr_accessor :cassandra_cluster
8
+
9
+ def initialize
10
+ puts 'init cassandra'
11
+ self.cassandra_cluster = Cassandra.cluster
12
+ end
13
+
14
+ def start(keyspace_name)
15
+ puts 'start cassandra, create cluster, session'
16
+ if !cassandra_cluster
17
+ cassandra_cluster = Cassandra.cluster
18
+ end
19
+ cassandra_cluster
20
+ end
21
+
22
+ def stop
23
+ puts 'stop cassandra'
24
+ if cassandra_cluster
25
+ puts 'closing'
26
+ cassandra_cluster.close
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ require 'diplomat'
2
+
3
+ module ConsulConfiguration
4
+ extend ApplicationConfiguration
5
+
6
+ CONFIG = {
7
+ port: 8500,
8
+ path: "http://localhost",
9
+ consul_service_data: {
10
+ name: "Service-1",
11
+ id: "Service1",
12
+ port: 9292,
13
+ check: {
14
+ id: "bluesky-api",
15
+ name: "HTTP Health Check API on port 9292",
16
+ http: "http://localhost:9292/health-check",
17
+ tls_skip_verify: false,
18
+ method: "GET",
19
+ interval: "10s",
20
+ timeout: "1s"
21
+ }
22
+ }
23
+ }.merge( ConsulConfiguration.config[:consul] )
24
+
25
+ def configure
26
+ Diplomat.configure do |config|
27
+ # Set up a custom Consul URL
28
+ config.url = "#{CONFIG[:path]}:#{CONFIG[:port].to_s}"
29
+ # Set up a custom Faraday Middleware
30
+ # config.middleware = MyCustomMiddleware
31
+ # Connect into consul with custom access token (ACL)
32
+ # config.acl_token = "qwertyui-asdf-zxcv-1234-123456789012"
33
+ # Set extra Faraday configuration options
34
+ # config.options = {ssl: { version: :TLSv1_2 }}
35
+ end
36
+
37
+ CONFIG[:consul_service_data]
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ require 'diplomat'
2
+ require_relative 'consul_configuration'
3
+
4
+ class ConsulService
5
+ extend ::ConsulConfiguration
6
+
7
+ attr_accessor :consul_service_data
8
+
9
+ def initialize
10
+ puts 'init consul'
11
+ self.consul_service_data = ConsulService::configure
12
+ Diplomat::Service.register(consul_service_data)
13
+ end
14
+
15
+ def start
16
+ puts 'start consul'
17
+ if !consul_service_data
18
+ consul_service_data = ConsulService::configure
19
+ end
20
+ end
21
+
22
+ def stop
23
+ puts 'stop consul'
24
+ Diplomat::Service.deregister(consul_service_data[:id])
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module RestConfiguration
2
+ extend ApplicationConfiguration
3
+
4
+ CONFIG = {
5
+ host: 'localhost:9292',
6
+ path: '/api/v1',
7
+ }.merge( RestConfiguration.config[:rest] )
8
+
9
+ end
@@ -0,0 +1,35 @@
1
+ require 'sinatra/base'
2
+ require "sinatra/namespace"
3
+ require_relative 'rest_configuration'
4
+
5
+ class RestApplication < Sinatra::Base
6
+ set :server, :puma
7
+ register Sinatra::Namespace
8
+
9
+ configure :production do
10
+ # ...
11
+ end
12
+
13
+ configure :development do
14
+ # ...
15
+ end
16
+ end
17
+
18
+ class RestService < RestApplication
19
+ extend ::RestConfiguration
20
+
21
+ # Health Check for Consul
22
+ get '/health-check' do
23
+ 'The service is healthy!'
24
+ end
25
+
26
+ # API route
27
+ namespace RestConfiguration::CONFIG[:path] do
28
+ get '/seed_1' do
29
+ 'Seed 1 API'
30
+ end
31
+ get '/seed_2' do
32
+ 'Seed 2 API'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require_relative 'application_configuration'
3
+ # require_relative 'application_service'
4
+ Dir["#{File.dirname(__FILE__)}/**/*.rb"].each {|file| require file }
5
+
6
+ class SampleCoreApi
7
+ extend ::ApplicationService
8
+ extend ::ApplicationConfiguration
9
+ end
10
+
11
+ SampleCoreApi.load_services
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sample_core_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.dev
5
+ platform: ruby
6
+ authors:
7
+ - Fusin Thang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.1
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: sinatra-contrib
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.1
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.0.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.1
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: puma
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 3.11.4
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.11.4
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 3.11.4
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.11.4
73
+ - !ruby/object:Gem::Dependency
74
+ name: cassandra-driver
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 3.2.2
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.2
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.2.2
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.2.2
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: 1.16.2
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.16.2
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.16.2
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.16.2
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake-test
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 1.0.0
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.0.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 1.0.0
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 1.0.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: rake
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 2.5.0
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.5.0
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: 2.5.0
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.5.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 3.7.0
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 3.7.0
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: 3.7.0
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 3.7.0
173
+ description: Sample Core API gem
174
+ email: fusinthang@gmail.com
175
+ executables: []
176
+ extensions: []
177
+ extra_rdoc_files: []
178
+ files:
179
+ - lib/application_configuration.rb
180
+ - lib/application_service.rb
181
+ - lib/cassandra/abstracted_cassandra_repository.rb
182
+ - lib/cassandra/cassandra_service.rb
183
+ - lib/consul/consul_configuration.rb
184
+ - lib/consul/consul_service.rb
185
+ - lib/rest/rest_configuration.rb
186
+ - lib/rest/rest_service.rb
187
+ - lib/sample_core_api.rb
188
+ homepage: http://rubygems.org/gems/sample_core_api
189
+ licenses:
190
+ - MIT
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 2.3.0
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">"
204
+ - !ruby/object:Gem::Version
205
+ version: 1.3.1
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.7.7
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Sample Core Api
212
+ test_files: []