class Service::DeployHq < Service
  string :deploy_hook_url
  boolean :email_pusher
  
  url "http://www.deployhq.com/"
  logo_url "http://www.deployhq.com/images/deploy/logo.png"
  maintained_by :github => 'darkphnx'
  supported_by :web => 'http://support.deployhq.com/', :email => 'support@deployhq.com'

  def receive_push
    unless data['deploy_hook_url'].to_s =~ /^https:\/\/[a-z0-9\-\_]+\.deployhq.com\/deploy\/[a-z0-9\-\_]+\/to\/[a-z0-9\-\_]+\/[a-z0-9]+$/i
      raise_config_error "Deploy Hook invalid" 
    end
    email_pusher = config_boolean_true?('email_pusher')

    http.url_prefix = data['deploy_hook_url']
    http.headers['content-type'] = 'application/x-www-form-urlencoded'
    body = Faraday::Utils.build_nested_query(http.params.merge(:payload => generate_json(payload), :notify => email_pusher))

    http_post data['deploy_hook_url'], body
  end

end

class Service::DeployHq < Service
  string :deploy_hook_url
  boolean :email_pusher
  
  url "http://www.deployhq.com/"
  logo_url "http://www.deployhq.com/images/deploy/logo.png"
  maintained_by :github => 'darkphnx'
  supported_by :web => 'http://support.deployhq.com/', :email => 'support@deployhq.com'

  def receive_push
    unless data['deploy_hook_url'].to_s =~ /^https:\/\/[a-z0-9\-\_]+\.deployhq.com\/deploy\/[a-z0-9\-\_]+\/to\/[a-z0-9\-\_]+\/[a-z0-9]+$/i
      raise_config_error "Deploy Hook invalid" 
    end
    email_pusher = config_boolean_true?('email_pusher')

    http.url_prefix = data['deploy_hook_url']
    http.headers['content-type'] = 'application/x-www-form-urlencoded'
    http.headers['X-Github-Event'] = 'push'

    body = Faraday::Utils.build_nested_query(http.params.merge(:payload => generate_json(payload), :notify => email_pusher))

    http_post data['deploy_hook_url'], body
  end

end

Add an X-Github-Event header to DeployHQ service.
Add an X-Github-Event header to DeployHQ service.

To make DeployHQ more compatible with Github webooks (now the reccomended way
of integrating), Deploy now expects an X-Github-Event push header to be present.
