Class: Hercules::RequestHandler
- Inherits:
-
Object
- Object
- Hercules::RequestHandler
- Includes:
- EM::Deferrable
- Defined in:
- lib/request_handler.rb
Overview
Class that knows how to handle deploy requests. This implementation will just parse a JSON as defined by github http hooks. In order to use other hook formats this class should be reimplemented.
Instance Method Summary collapse
-
#branch ⇒ Object
Returns the branch of the repository that fired the request.
-
#hdi ⇒ Object
Returns the assembled HDI.
-
#initialize(options) ⇒ RequestHandler
constructor
We must pass the request data (method, path, query and body).
-
#message ⇒ Object
Returns the message generated as response for the request passed in the initializer.
-
#repository_name ⇒ Object
Returns the repository name that fired the request.
-
#repository_url ⇒ Object
Returns the url of the repository that fired the request.
-
#request_hdi? ⇒ Boolean
Returns true whenever the request made was a HDI request.
-
#request_token ⇒ Object
Returns the security token that fired the request.
- #run ⇒ Object
-
#status ⇒ Object
Returns the status generated as response for the request passed in the initializer.
Constructor Details
#initialize(options) ⇒ RequestHandler
We must pass the request data (method, path, query and body).
-
options is a hash containing all the request data described above plus the logger and the config hash.
16 17 18 19 20 21 22 |
# File 'lib/request_handler.rb', line 16 def initialize() @method = [:method] @body = [:body] @log = [:log] @path = [:path] @config = [:config] end |
Instance Method Details
#branch ⇒ Object
Returns the branch of the repository that fired the request.
74 75 76 |
# File 'lib/request_handler.rb', line 74 def branch payload['ref'].split('/').pop end |
#hdi ⇒ Object
Returns the assembled HDI
60 61 62 63 64 65 66 |
# File 'lib/request_handler.rb', line 60 def hdi response = "" css = "" File.open(File.dirname(__FILE__) + "/../hdi/site/index.html", 'r'){|f| response = f.read } File.open(File.dirname(__FILE__) + "/../hdi/site/stylesheets/style.css", 'r'){|f| css = f.read } response.gsub(/<link href="stylesheets\/style.css" media="all" rel="stylesheet" type="text\/css">/, "<style>#{css}</style>").gsub(/##REQUEST_ADDRESS##/, @path.gsub(/\/hdi/, "")) end |
#message ⇒ Object
Returns the message generated as response for the request passed in the initializer. We also store the message for further queries.
31 32 33 34 |
# File 'lib/request_handler.rb', line 31 def @result ||= process_request @result[:message] end |
#repository_name ⇒ Object
Returns the repository name that fired the request.
44 45 46 47 |
# File 'lib/request_handler.rb', line 44 def repository_name return payload['repository']['name'] if @method == "POST" return @path.split('/')[1] if @method == "GET" end |
#repository_url ⇒ Object
Returns the url of the repository that fired the request.
69 70 71 |
# File 'lib/request_handler.rb', line 69 def repository_url payload['repository']['url'] end |
#request_hdi? ⇒ Boolean
Returns true whenever the request made was a HDI request
55 56 57 |
# File 'lib/request_handler.rb', line 55 def request_hdi? @path.split('/')[3] == 'hdi' and @method == "GET" end |
#request_token ⇒ Object
Returns the security token that fired the request.
50 51 52 |
# File 'lib/request_handler.rb', line 50 def request_token @path.split('/')[2] end |
#run ⇒ Object
24 25 26 27 28 |
# File 'lib/request_handler.rb', line 24 def run status set_deferred_status :succeeded end |
#status ⇒ Object
Returns the status generated as response for the request passed in the initializer. We also store the status for further queries.
38 39 40 41 |
# File 'lib/request_handler.rb', line 38 def status @result ||= process_request @result[:status] end |