Skip to content

Instantly share code, notes, and snippets.

@Patrick-Cao
Patrick-Cao / gist:50f0b82a49453b83622c90aeb032d860
Created September 8, 2016 18:17 — forked from mislav/gist:938183
Faraday SSL example
connection = Faraday::Connection.new('http://example.com') do |builder|
builder.request :url_encoded # for POST/PUT params
builder.adapter :net_http
end
# same as above, short form:
connection = Faraday.new 'http://example.com'
# GET
connection.get '/posts'
@Patrick-Cao
Patrick-Cao / faraday_cert_auth.rb
Created September 8, 2016 18:16 — forked from chills42/faraday_cert_auth.rb
Faraday client certificate authentication
# I'm starting with a .pfx, so the first step is to get it to a .pem caintaining the cert and key
# This can be done using the following command
#
# openssl pkcs12 -in certs/mycert.pfx -out certs/mycert.pem -nodes
#
require 'faraday'
require 'openssl'
# create an x509 certificate
@Patrick-Cao
Patrick-Cao / rails.rb
Created August 20, 2016 00:54
Use SSL in Rails development. First: to create a local SSL certificate and start a SSL webserver checkout *shell.sh*. Second: to configure Rails checkout *rails.rb*
# To enable SSL in Rails you could now simply use *force_ssl* in your
# ApplicationController but there is two more things to think about:
# In development our SSL webserver is running on port 3001 so we would
# actually need to use *force_ssl port: 3001* but then this wouldn't
# work for production.
# Also there is a good chance you might not always want to use SSL in development
# so it would be nice if we could just enable or disable SSL in the config.
# To make all this work first copy the file *ssl_with_configured_port.rb* to
# your *lib* directory. Second to enable SSL add *config.use_ssl = true*
@Patrick-Cao
Patrick-Cao / application_controller.rb
Created July 15, 2016 21:40 — forked from itskingori/application_controller.rb
How to handle exceptions like 401, 501, 404 in Rails
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
@Patrick-Cao
Patrick-Cao / API.md
Created July 11, 2016 17:20 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method: