housing.misc.gem
Installation
gem 'housing_misc'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install housing_misc
Functions Provided
get_request_attribute_value(headers, params, key)
Parameters:
- headers (data_type: ActionDispatch::Http::Headers)
- params (data_type: ActionController::Parameters)
- key (data_type: String, description: Name of the attribute whose value is needed)
Description: Returns value against the key present in headers or params, first checks in headers if it's not there then checks in params
is_request_internal?(request)
Parameters:
- request (data_type: ActionDispatch::Request)
Description: Checks if the request passes internal host validation or not based on Rails environment and request's host and returns bool value
is_request_from_mobile?(request, params, velocity_salt)
Parameters:
- request (data_type: ActionDispatch::Request)
- params (data_type: ActionController::Parameters)
- velocity_salt (data_type: String, description: Salt to verify signed param with time stamp)
Description: Checks if the request is from mobile or not based on source, time stamp, signed param and salt and returns bool value
is_request_csrf_valid?(request, , params, csrf_encryption_key, velocity_salt)
Parameters:
- request (data_type: ActionDispatch::Request)
- cookies (data_type: ActionDispatch::Cookies::CookieJar)
- params (data_type: ActionController::Parameters)
- csrf_encryption_key (data_type: String, length: 64 characters (0-9, a-f) i.e. 32 bytes, description: Encryption key to generate csrf token. This key should be kept secret between servers.)
- velocity_salt (data_type: String, description: Salt to verify signed param with time stamp)
Description: Checks if the request passes csrf validation or not and returns bool value
internal_host_check
Description: Checks if the request passes internal host validation or not. If the validation fails then logs information in /log/unauthorized_api_requests.log and renders :json => => "You are not authorized to make this call", status: 401
Note: It can only be called from controller as it uses request (ActionDispatch::Request)
Usage: In your controller:
include HousingMisc before_action :internal_host_check, :only => [:method_1, :method_2, ...]
send_generic_mail(template_slug, template_version, users, base_vars, merge_vars, high_priority=false, =[], deferred=false, send_time=nil, google_analytics_campaign=nil)
Parameters:
- template_slug (data_type:string, descriptinon:contains name of the template)
- template_version (data_type: string, description:version of mail_template e.g. "1")
- users (data_type: [=> "xyz", "name" => "m"], description: array of email ids)
- base_vars (data_type: Hash, desciption: contains subject and callback_url)
- merge_vars (data_type: Hash, description: includes vars that are embedded in mail)
- high_priority (data_type : boolean, description:decides the priority of mail)
- attachments (:data_type : [], deacription: contains attachments to mail)
- deferred (data_type : boolean, description:decides if mail is to be sent later)
- send_time (data_tpe: Time, desciption: e.g. 2018-04-06 15:55:33 +0530, nil=send_now)
- google_analytics_campaign(data_type: string, description: Name of campaign)
Description: Sends mail for a given template and its version to mentioned users.
csrf_check(csrf_encryption_key, velocity_salt)
Parameters:
- csrf_encryption_key (data_type: String, length: 64 characters (0-9, a-f) i.e. 32 bytes, description: Encryption key to generate csrf token. This key should be kept secret between servers.)
- velocity_salt (data_type: String, description: Salt to verify signed param with time stamp)
Description: Checks if the request passes csrf validation or not. If the validation fails then logs information in /log/unauthorized_api_requests.log and renders :json => => "You are not authorized to make this call", status: 401
Note: It can only be called from controller as it uses request (ActionDispatch::Request), cookies (ActionDispatch::Cookies::CookieJar) and params (ActionController::Parameters)
Usage: In your controller:
include HousingMisc before_action :only => [:method_1, :method_2, ...] do csrf_check(Housing.csrf_encryption_key) end