Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created July 12, 2020 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancom/6e25d89a8ac317545872ec8b80a4c292 to your computer and use it in GitHub Desktop.
Save stephancom/6e25d89a8ac317545872ec8b80a4c292 to your computer and use it in GitHub Desktop.
Application to Topline
# _ _ _
# | |_ ___ _ __| (_)_ _ ___ __ _ __ _ _ __ ___ ___
# | _/ _ \ '_ \ | | ' \/ -_) / _` / _` | ' \/ -_|_-<
# \__\___/ .__/_|_|_||_\___| \__, \__,_|_|_|_\___/__/
# |_| |___/
#
# application application
#
# (c) 2013 stephan.com
require 'sinatra'
require 'json'
require 'net/http'
application = {
'name' => 'stephan.com',
'email' => 'stephan@stephan.com',
'phone_number' => '310.384.3771',
'position_title'=> 'Senior Ruby Developer, CTO or Rockstar Programmer',
'resume_url' => 'https://dl.dropboxusercontent.com/u/235909/Stephan%20Resume%202013.pdf',
'github_profile'=> 'https://github.com/stephancom',
'message' => 'software is to poetry as architecture is to sculpture',
'additional_links' => {
'home' => 'http://stephan.com',
'sculpture' => 'http://shapes.stephan.com',
'terpster' => 'http://terpster.com',
'twitter' => 'https://twitter.com/stephancom',
'stkovrflo' => 'http://stackoverflow.com/users/444955/stephan-com',
'patents' => 'http://stephan.com/publications',
'art' => 'http://stephan.com/portfolio/index.html',
'widgets' => 'http://stephan.com/widgets/',
'slideshow' => 'http://www.flickr.com/photos/stephan/sets/72157621806237816/',
'video' => 'http://www.youtube.com/playlist?list=PLmsOa_3qxBk2Iuldcj3nJHOKAt58tvLD9',
'imdb' => 'http://www.imdb.com/name/nm0583630/',
'lemonade' => 'http://www.flickr.com/photos/stephan/9675596883/'
}
}
test_url = 'http://localhost:4567/apply'
real_url = 'http://toplinegamelabs.com/api/jobs/apply'
# just spit out the application hash to check it
get '/' do
application.to_json
end
def send_application(url, application)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request["Content-Type"] = "application/json"
request["Accept"] = "application/json"
request.body = application.to_json
response = http.request(request)
puts " _ _ _ _ _ "
puts " __ _ _ __ _ __| (_)__ __ _| |_(_)___ _ _ ___ ___ _ _| |_ "
puts "/ _` | '_ \\ '_ \\ | / _/ _` | _| / _ \\ ' \\ (_-</ -_) ' \\ _|"
puts "\\__,_| .__/ .__/_|_\\__\\__,_|\\__|_\\___/_||_| /__/\\___|_||_\\__|"
puts " |_| |_| "
puts response.code
puts response.body
response.body
end
# endpoint to test the application works - receive and parse json
post '/apply' do
pass unless request.accept? 'application/json'
return "Bad type" unless request.content_type == "application/json"
begin
data = JSON.parse(request.body.read)
if data == application
"Good job\n"
else
"fail\n"
end
rescue JSON::ParserError
"oops\n"
end
end
# test sending to myself
put '/test' do
send_application(test_url, application)
end
put '/send' do
# "are you sure?\n"
send_application(real_url, application)
end
# spec, appended for reference
# https://jobs.github.com/positions/595ccd7a-de94-11e2-989f-62eec0979a4f
# For SUPER bonus points, apply via our jobs API:
# URI: http://toplinegamelabs.com/api/jobs/apply
# Method: POST
# Header: Accept: application/json
# Body (JSON):
# {
# "name": "string, required",
# "email": "string, required",
# "phone_number": "string, required",
# "position_title": "string, required",
# "resume_url": "string, required",
# "github_profile": "string, strongly recommended",
# "message": "string, make us laugh",
# "additional_links": {"any": "other", "links": "you", "want": "to", "send": "like", "twitter": "@toplinegamelabs"}
# }
# Returns (JSON):
# {
# "message": "A delightful acknowledgment of a successful application."
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment