Commit f7e826bf authored by Cool Fire's avatar Cool Fire

Initial commit

parents
Pipeline #307 passed with stages
in 2 minutes and 19 seconds
---
stages:
- syntax
- linting
syntax:
stage: syntax
image: ruby:2.4
script:
- find . -name '*\.rb' -exec bash -c 'echo -ne "{}\t\t\t" && ruby -c {}' \;
lint_ruby:
stage: linting
image: ruby:2.4
script:
- gem install rubocop --no-ri --no-rdoc
- rubocop -l -f s
lint_yaml:
stage: linting
image: ruby:2.4
script:
- gem install yamllint --no-ri --no-rdoc
- yamllint *.yaml
GEM
remote: https://rubygems.org/
specs:
mustermann (1.0.0)
rack (2.0.3)
rack-protection (2.0.0)
rack
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
tilt (~> 2.0)
tilt (2.0.7)
PLATFORMS
ruby
DEPENDENCIES
sinatra
BUNDLED WITH
1.14.6
require File.expand_path '../nanoapi_app.rb', __FILE__
run Sinatra::Application
---
key: foobar
# frozen_string_literal: true
require 'json'
require 'sinatra'
require 'socket'
require 'yaml'
def check_key(key)
config = YAML.load_file 'config.yaml'
halt 401 if key != config['key']
end
def forward_message(message)
sock = TCPSocket.open 'localhost', 2000
sock.puts message
rescue Errno::ECONNREFUSED
halt 500
end
get '/' do
'Nanobot API ready.'
end
post '/v1/message' do
check_key params[:key]
return 'Parameter dest is missing' unless params.key? :dest
return 'Parameter message is missing' unless params.key? :message
forward_message({ dest: params[:dest], message: params[:message] }.to_json)
'Message accepted'
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment