-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.rb
73 lines (55 loc) · 1.52 KB
/
history.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'dotenv'
Dotenv.load
require 'mysql2'
class History
# Initializes a new Merveilles history instance
def initialize()
Mysql2::Client.default_query_options.merge!(:symbolize_keys => true)
@db = Mysql2::Client.new(
:host => ENV['MYSQL_HOST'],
:username => ENV['MYSQL_USER'],
:password => ENV['MYSQL_PASSWORD'],
:database => ENV['MYSQL_DATABASE']
)
end
# Retrieves a list of Merveilles users
def list_channels
results = @db.query <<-SQL
SELECT * FROM channels
SQL
results.to_a
end
# Retrieves a list of Merveilles channel names
def list_channel_names
results = @db.query <<-SQL
SELECT name FROM channels
SQL
results.to_a
end
# Retrieves a channel with the specified Slack ID
def get_channel_with_id(id)
end
# Retrieves a channel with the specified name
def get_channel_with_name(name)
statement = @db.prepare <<-SQL
SELECT * FROM channels
WHERE name = ?
SQL
results = statement.execute(name)
results.to_a.first
end
# Retrieves a list of Merveilles users
def list_users
results = @db.query <<-SQL
SELECT * FROM users
SQL
results.to_a
end
# Retrieves a list of Merveilles usernames
def list_user_names
results = @db.query <<-SQL
SELECT name FROM users
SQL
results.to_a
end
end