If you need to accept incoming data into your application or host data from your module over HTTP, you can use web actions to create HTTP endpoints within the Sirportly application which execute your own code.
class Deliver < Module
add_web_action "accept_mail" do |config, account, request|
## This method must return a hash with the return data as outlined below
{:status => 200, :header => {'Content-Type' => 'text/plain'}, :body => "Hello!"}
end
end
Once the web action has been defined it can be accessed by visiting yoursupportdomain.com/modules/deliver/accept_mail, replacing 'deliver' with the name of your module and 'accept_mail' with the method name you specified when you added the add_web_action
method.
The add_web_action
method accepts one parameter which is the path to itself after 'modules/module_name'. It may include slashes if appropriate. There is no built in restriction of HTTP method although, for example, you could use request.post?
to determine if the request was a POST request.
When the block is executed, it is passed three parameters:
config
- contains a hash of the configuration for the account. See the configuration page for further details.account
- the account object for the domain which has been accessedrequest
- an ActionDispatch::Request
instance for the current requestThe block must return a hash containing the :status
as a numeric HTTP status code, :headers
: which is a hash of HTTP headers and body
which is a string of data to be sent back. Alternatively, you can return false
which will return a 400 Bad Request
status with no body.