forstok_trigger 0.1.0

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: 946b93abbbe70dc56f19407828e9cf67c379e9679c2ea539a3daf1aec53707be
4
+ data.tar.gz: ac74359702af2f73c1bdcba470fb34eb7cf571f0e2b9ff7115acc03fba9de9d8
5
+ SHA512:
6
+ metadata.gz: 0c3ec974752f633c7bfd3da83739615a56316621d1485c7ef57b44c6c0f86dc9a9deb1c71e27d85b63ad7449361ec098165275e278f5729cc3edca33abff8d3c
7
+ data.tar.gz: 6518cc22d0d405e61e47fece72d6062e1e21fc3f58c9edda491d95014d6eac9bbe815da9e254262abe518cdfab051c209f5ac3cf81535bf07b89665bb6bcd01b
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ class Configuration
5
+ # This Configuration class is for initialize config to database
6
+ class ExportConfiguration < Configuration
7
+ attr_accessor :buffer_table
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ class Configuration
5
+ # This Configuration class is for initialize config to database
6
+ class ValidityConfiguration < Configuration
7
+ attr_accessor :buffer_table
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ class Configuration
5
+ # This Configuration class is for initialize config to database
6
+ class WebhookConfiguration < Configuration
7
+ attr_accessor :buffer_table, :list, :event
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ # This Configuration class is for initialize config to database
5
+ class Configuration
6
+ attr_accessor :db, :host, :port, :username, :password
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ module Export
5
+ module Repository
6
+ # This TriggerRepository is class for connect to database
7
+ module ExportRepository
8
+ def self.export_insert_query
9
+ sql = 'INSERT INTO ' + configuration.db + '.'
10
+ sql += configuration.buffer_table
11
+ sql += '(listing_id, account_id, channel_id, mode) VALUES '
12
+ sql
13
+ end
14
+
15
+ def self.export_insert_value(listing_id, account_id, channel_id, mode)
16
+ sql = '(' + listing_id.to_s + ', ' + account_id.to_s + ', '
17
+ sql += channel_id.to_s + ", '" + mode.to_s + "')"
18
+ sql
19
+ end
20
+
21
+ def self.export_insert_pending(listing_id, account_id, channel_id, mode)
22
+ sql = export_insert_query
23
+ sql += export_insert_value(listing_id, account_id, channel_id, mode)
24
+ ForstokTrigger::Export::Repository.client.query(sql)
25
+ end
26
+
27
+ def self.configuration
28
+ @configuration ||= ForstokTrigger::Export.configuration
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql2'
4
+ module ForstokTrigger
5
+ module Export
6
+ # Class Trigger is main class for run perform
7
+ module Repository
8
+ def self.client
9
+ Mysql2::Client.new(
10
+ host: configuration.host,
11
+ port: configuration.port,
12
+ username: configuration.username,
13
+ password: configuration.password,
14
+ database: configuration.db
15
+ )
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= ForstokTrigger::Export.configuration
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/export/repository/export_repository.rb'
4
+ module ForstokTrigger
5
+ module Export
6
+ # Module Trigger is main module for run perform export trigger
7
+ module Trigger
8
+ def self.perform(listing_id, account_id, channel_id, mode)
9
+ ForstokTrigger::Export::Repository::ExportRepository
10
+ .export_insert_pending(
11
+ listing_id,
12
+ account_id,
13
+ channel_id,
14
+ mode
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/export/trigger.rb'
4
+ require 'forstok_trigger/export/repository/export_repository.rb'
5
+ require 'forstok_trigger/configuration/export_configuration.rb'
6
+ module ForstokTrigger
7
+ # Class Trigger is main class for run perform
8
+ module Export
9
+ def self.configuration
10
+ @configuration ||= ForstokTrigger::Configuration::ExportConfiguration.new
11
+ end
12
+
13
+ def self.reset
14
+ @configuration = ForstokTrigger::Configuration::ExportConfiguration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ module Validity
5
+ module Repository
6
+ # This TriggerRepository is class for connect to database
7
+ module ValidityRepository
8
+ def self.validity_insert_query
9
+ sql = 'INSERT INTO ' + configuration.db + '.'
10
+ sql += configuration.buffer_table
11
+ sql += '(listing_id, account_id, channel_id, mode) VALUES '
12
+ sql
13
+ end
14
+
15
+ def self.validity_insert_value(listing_id, account_id, channel_id, mode)
16
+ sql = '(' + listing_id.to_s + ', ' + account_id.to_s + ', '
17
+ sql += channel_id.to_s + ", '" + mode.to_s + "')"
18
+ sql
19
+ end
20
+
21
+ def self.validity_insert_pending(listing_id, account_id, channel_id, mode)
22
+ sql = validity_insert_query
23
+ sql += validity_insert_value(listing_id, account_id, channel_id, mode)
24
+ ForstokTrigger::Validity::Repository.client.query(sql)
25
+ end
26
+
27
+ def self.configuration
28
+ @configuration ||= ForstokTrigger::Validity.configuration
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql2'
4
+ module ForstokTrigger
5
+ module Validity
6
+ # Class Trigger is main class for run perform
7
+ module Repository
8
+ def self.client
9
+ Mysql2::Client.new(
10
+ host: configuration.host,
11
+ port: configuration.port,
12
+ username: configuration.username,
13
+ password: configuration.password,
14
+ database: configuration.db
15
+ )
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= ForstokTrigger::Validity.configuration
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/validity/repository/validity_repository.rb'
4
+ module ForstokTrigger
5
+ module Validity
6
+ # Module Trigger is main module for run perform validity trigger
7
+ module Trigger
8
+ def self.perform(listing_id, account_id, channel_id, mode)
9
+ ForstokTrigger::Validity::Repository::ValidityRepository
10
+ .validity_insert_pending(
11
+ listing_id,
12
+ account_id,
13
+ channel_id,
14
+ mode
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/validity/trigger.rb'
4
+ require 'forstok_trigger/validity/repository/validity_repository.rb'
5
+ require 'forstok_trigger/configuration/validity_configuration.rb'
6
+ module ForstokTrigger
7
+ # Class Trigger is main class for run perform
8
+ module Validity
9
+ def self.configuration
10
+ @configuration ||= ForstokTrigger::Configuration::ValidityConfiguration.new
11
+ end
12
+
13
+ def self.reset
14
+ @configuration = ForstokTrigger::Configuration::ValidityConfiguration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForstokTrigger
4
+ module Webhook
5
+ module Repository
6
+ # This TriggerRepository is class for connect to database
7
+ module WebhookRepository
8
+ def self.webhook_list_query_select
9
+ sql = 'SELECT ' + configuration_list + '.id, '
10
+ sql += configuration_list + '.url, '
11
+ sql += configuration_event + '.name '
12
+ sql += webhook_list_query_join
13
+ sql
14
+ end
15
+
16
+ def self.webhook_list_query_join
17
+ sql = ' FROM ' + configuration_list
18
+ sql += ' JOIN ' + configuration_event
19
+ sql += ' on ' + configuration_list + '.event_id='
20
+ sql += configuration_event + '.id '
21
+ sql
22
+ end
23
+
24
+ def self.webhook_list_query_condition(event, channel_id)
25
+ sql = 'WHERE ' + configuration_list
26
+ sql += '.channel_id=' + channel_id.to_s
27
+ sql += ' AND ' + configuration_event
28
+ sql += ".name like '" + event.to_s + "'"
29
+ sql
30
+ end
31
+
32
+ def self.webhook_list(event, channel_id)
33
+ sql = webhook_list_query_select
34
+ sql += webhook_list_query_condition(event, channel_id)
35
+ results = ForstokTrigger::Webhook::Repository.client.query(sql)
36
+ results
37
+ end
38
+
39
+ def self.webhook_insert_query
40
+ sql = 'INSERT INTO ' + configuration.db + '.'
41
+ sql += configuration.buffer_table
42
+ sql += '(url, event, event_payload) VALUES '
43
+ sql
44
+ end
45
+
46
+ def self.webhook_insert_value(event, url, event_payload)
47
+ sql = "('" + url.to_s + "', '" + event.to_s + "', "
48
+ sql += event_payload.to_s + ')'
49
+ sql
50
+ end
51
+
52
+ def self.webhook_insert_pending(event, url, event_payload)
53
+ sql = webhook_insert_query
54
+ sql += webhook_insert_value(event, url, event_payload)
55
+ ForstokTrigger::Webhook::Repository.client.query(sql)
56
+ end
57
+
58
+ def self.configuration_list
59
+ configuration.list
60
+ end
61
+
62
+ def self.configuration_event
63
+ configuration.event
64
+ end
65
+
66
+ def self.configuration
67
+ @configuration ||= ForstokTrigger::Webhook.configuration
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql2'
4
+ module ForstokTrigger
5
+ module Webhook
6
+ # Class Trigger is main class for run perform
7
+ module Repository
8
+ def self.client
9
+ Mysql2::Client.new(
10
+ host: configuration.host,
11
+ port: configuration.port,
12
+ username: configuration.username,
13
+ password: configuration.password,
14
+ database: configuration.db
15
+ )
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= ForstokTrigger::Webhook.configuration
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/webhook/repository/webhook_repository.rb'
4
+ module ForstokTrigger
5
+ module Webhook
6
+ # Module Trigger is main module for run perform webhook trigger
7
+ module Trigger
8
+ def self.perform(event, event_payload, channel_id)
9
+ webhooks = get_webhooks(event, channel_id)
10
+ webhooks.each do |webhook|
11
+ ForstokTrigger::Webhook::Repository::WebhookRepository
12
+ .webhook_insert_pending(
13
+ webhook['name'],
14
+ webhook['url'],
15
+ event_payload
16
+ )
17
+ end
18
+ end
19
+
20
+ def self.get_webhooks(event, channel_id)
21
+ ForstokTrigger::Webhook::Repository::WebhookRepository
22
+ .webhook_list(event, channel_id)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/webhook/trigger.rb'
4
+ require 'forstok_trigger/webhook/repository/webhook_repository.rb'
5
+ require 'forstok_trigger/configuration/webhook_configuration.rb'
6
+ module ForstokTrigger
7
+ # Class Trigger is main class for run perform
8
+ module Webhook
9
+ def self.configuration
10
+ @configuration ||= ForstokTrigger::Configuration::WebhookConfiguration.new
11
+ end
12
+
13
+ def self.reset
14
+ @configuration = ForstokTrigger::Configuration::WebhookConfiguration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forstok_trigger/version'
4
+ require 'forstok_trigger/webhook'
5
+ require 'forstok_trigger/export'
6
+ require 'forstok_trigger/configuration'
7
+ require 'forstok_trigger/webhook/trigger'
8
+ require 'forstok_trigger/webhook/repository'
9
+ require 'forstok_trigger/webhook/repository/webhook_repository'
10
+ require 'forstok_trigger/export/trigger'
11
+ require 'forstok_trigger/export/repository'
12
+ require 'forstok_trigger/export/repository/export_repository'
13
+
14
+ module ForstokTrigger
15
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forstok_trigger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Ivander
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 11.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 11.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.79.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.79.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.3
97
+ description: Forstok Gem trigger in microservice
98
+ email:
99
+ - kevin.ivander@forstok.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - lib/forstok_trigger.rb
105
+ - lib/forstok_trigger/configuration.rb
106
+ - lib/forstok_trigger/configuration/export_configuration.rb
107
+ - lib/forstok_trigger/configuration/validity_configuration.rb
108
+ - lib/forstok_trigger/configuration/webhook_configuration.rb
109
+ - lib/forstok_trigger/export.rb
110
+ - lib/forstok_trigger/export/repository.rb
111
+ - lib/forstok_trigger/export/repository/export_repository.rb
112
+ - lib/forstok_trigger/export/trigger.rb
113
+ - lib/forstok_trigger/validity.rb
114
+ - lib/forstok_trigger/validity/repository.rb
115
+ - lib/forstok_trigger/validity/repository/validity_repository.rb
116
+ - lib/forstok_trigger/validity/trigger.rb
117
+ - lib/forstok_trigger/version.rb
118
+ - lib/forstok_trigger/webhook.rb
119
+ - lib/forstok_trigger/webhook/repository.rb
120
+ - lib/forstok_trigger/webhook/repository/webhook_repository.rb
121
+ - lib/forstok_trigger/webhook/trigger.rb
122
+ homepage:
123
+ licenses:
124
+ - MIT
125
+ metadata:
126
+ allowed_push_host: https://rubygems.org
127
+ source_code_uri: https://bitbucket.org/forstok/forstok_trigger/src/master
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.0.6
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Forstok Trigger
147
+ test_files: []