Module: ForstokTrigger::Webhook::Repository::WebhookRepository

Defined in:
lib/forstok_trigger/webhook/repository/webhook_repository.rb

Overview

This TriggerRepository is class for connect to database

Class Method Summary collapse

Class Method Details

.configurationObject



67
68
69
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 67

def self.configuration
  @configuration ||= ForstokTrigger::Webhook.configuration
end

.configuration_eventObject



63
64
65
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 63

def self.configuration_event
  configuration.event
end

.configuration_listObject



59
60
61
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 59

def self.configuration_list
  configuration.list
end

.webhook_insert_pending(event, url, event_payload, channel_id) ⇒ Object



53
54
55
56
57
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 53

def self.webhook_insert_pending(event, url, event_payload, channel_id)
  sql = webhook_insert_query
  sql += webhook_insert_value(event, url, event_payload, channel_id)
  ForstokTrigger::Webhook::Repository.client.query(sql)
end

.webhook_insert_queryObject



39
40
41
42
43
44
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 39

def self.webhook_insert_query
  sql = 'INSERT INTO ' + configuration.db + '.'
  sql += configuration.buffer_table
  sql += '(url, event, event_payload, channel_id) VALUES '
  sql
end

.webhook_insert_value(event, url, event_payload, channel_id) ⇒ Object



46
47
48
49
50
51
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 46

def self.webhook_insert_value(event, url, event_payload, channel_id)
  sql = "('" + url.to_s + "', '" + event.to_s + "', '"
  sql += Mysql2::Client.escape(event_payload.to_s) + "', "
  sql += channel_id.to_s + ')'
  sql
end

.webhook_list(event, channel_id) ⇒ Object



32
33
34
35
36
37
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 32

def self.webhook_list(event, channel_id)
  sql = webhook_list_query_select
  sql += webhook_list_query_condition(event, channel_id)
  results = ForstokTrigger::Webhook::Repository.client.query(sql)
  results
end

.webhook_list_query_condition(event, channel_id) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 24

def self.webhook_list_query_condition(event, channel_id)
  sql = 'WHERE ' + configuration_list
  sql += '.channel_id=' + channel_id.to_s
  sql += ' AND ' + configuration_event
  sql += ".name like '" + event.to_s + "'"
  sql
end

.webhook_list_query_joinObject



16
17
18
19
20
21
22
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 16

def self.webhook_list_query_join
  sql = ' FROM ' + configuration_list
  sql += ' JOIN ' + configuration_event
  sql += ' on ' + configuration_list + '.event_id='
  sql += configuration_event + '.id '
  sql
end

.webhook_list_query_selectObject



8
9
10
11
12
13
14
# File 'lib/forstok_trigger/webhook/repository/webhook_repository.rb', line 8

def self.webhook_list_query_select
  sql = 'SELECT ' + configuration_list + '.id, '
  sql += configuration_list + '.url, '
  sql += configuration_event + '.name '
  sql += webhook_list_query_join
  sql
end