2016-08-04 22:18:42 +02:00
|
|
|
$agent = Mechanize.new
|
2016-05-05 04:25:01 +02:00
|
|
|
|
2017-02-15 07:08:48 +01:00
|
|
|
def plainRequest(path, data = {}, method = 'POST')
|
2017-01-14 01:58:59 +01:00
|
|
|
uri = 'http://localhost:8080' + path
|
|
|
|
|
2017-02-15 07:08:48 +01:00
|
|
|
if method == 'POST'
|
|
|
|
@response = $agent.post(uri, data)
|
|
|
|
else
|
|
|
|
@response = $agent.get(uri, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
return @response
|
2017-01-14 01:58:59 +01:00
|
|
|
end
|
|
|
|
|
2016-07-27 05:44:07 +02:00
|
|
|
def request(path, data = {})
|
2016-08-04 06:37:23 +02:00
|
|
|
uri = 'http://localhost:8080' + path
|
2016-08-04 22:18:42 +02:00
|
|
|
response = $agent.post(uri, data)
|
2016-05-05 04:25:01 +02:00
|
|
|
|
|
|
|
return JSON.parse(response.body)
|
|
|
|
end
|
|
|
|
|
2016-05-11 03:35:36 +02:00
|
|
|
class Database
|
|
|
|
def initialize()
|
2018-03-28 04:30:18 +02:00
|
|
|
mysqlHost = ENV['MYSQL_HOST'] || '127.0.0.1'
|
2016-07-27 05:44:07 +02:00
|
|
|
mysqlUser = ENV['MYSQL_USER'] || 'root'
|
|
|
|
mysqlPass = ENV['MYSQL_PASSWORD'] || ''
|
2018-03-28 04:30:18 +02:00
|
|
|
@connection = Mysql.new(mysqlHost, mysqlUser, mysqlPass, 'development', 4040)
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|
2016-05-05 04:25:01 +02:00
|
|
|
|
2016-05-11 03:35:36 +02:00
|
|
|
def close()
|
|
|
|
@connection.close
|
|
|
|
end
|
2016-05-05 04:25:01 +02:00
|
|
|
|
2016-05-11 03:35:36 +02:00
|
|
|
def getRow(table, value, field = 'id')
|
|
|
|
queryResponse = @connection.query("select * from #{table} where #{field}='#{value.to_s}'")
|
|
|
|
|
|
|
|
return queryResponse.fetch_hash
|
|
|
|
end
|
2016-12-29 21:25:45 +01:00
|
|
|
|
|
|
|
def getLastRow(table)
|
|
|
|
queryResponse = @connection.query("select * from #{table} order by id desc limit 1")
|
|
|
|
|
|
|
|
return queryResponse.fetch_hash
|
|
|
|
end
|
2017-01-12 20:30:58 +01:00
|
|
|
|
|
|
|
def query(query_string)
|
|
|
|
return @connection.query(query_string);
|
|
|
|
end
|
2016-05-05 04:25:01 +02:00
|
|
|
end
|
2016-05-11 03:35:36 +02:00
|
|
|
|
|
|
|
$database = Database.new
|
2016-09-25 06:16:10 +02:00
|
|
|
|
|
|
|
$staff = {
|
|
|
|
:email => 'staff@opensupports.com',
|
|
|
|
:password => 'staff'
|
|
|
|
}
|