SlideShare a Scribd company logo
1 of 19
Download to read offline
/vendor/plugins/panmind
Spinoffs from a large Rails Application




                               Ruby Social Club night @MIKAMAI
Why?
‣ Code     you write in /app will be obsolete soon

‣ Code     you write in /lib will be obsolete less soon (maybe)

‣ Code     you you share with the Open Source community could live
 really long and beyond your expectations



‣ It’s   a sane engineering principle to write reusable code

‣ Sharing    the code makes you write good documentation




                                                       Ruby Social Club night @MIKAMAI
How?
‣ gem     uninstall -f copy-paste ide-tools

‣ Abstract    early, abstract often

‣ Create    temporary modules in your models, helpers, controllers

‣ Move     those modules away in /lib[1] - SOON

‣ Decouple     ‘em from the app assumptions, logic and configuration

‣ Move     ‘em in /vendor/plugins



‣ [1]:   Optional but recommended:
 config.load_once_paths.push((Rails.root+'lib').to_s)

                                                      Ruby Social Club night @MIKAMAI
A real world example
    http://github.com/Panmind/bigbro/commits/master

‣ Write   code in /lib, include the rusty module(s) in your app
‣ Decouple    configuration:
    -     def account
    -       Config[:id]
    +     attr_accessor :account
    +     def self.set(options = {})
    +        self.account = options[:account]
‣   Remove initialization code and put it in init.rb
‣   Rename the module and move code around
‣   Write documentation
‣   Release (Git is your friend: co, cherry-pick and rebase -i)
‣   Present at a Ruby event so someone else will write tests ;-)

                                                       Ruby Social Club night @MIKAMAI
Compatibility checklist
‣ Ruby    1.9.1-p378
‣ Rails   2.3.8
‣ rails_xss       plugin


‣ Patches   to support older versions of Ruby/Rails
 and/or without the rails_xss plugin more than
 welcome! (it’s just an .html_safe after all :-)


                                           Ruby Social Club night @MIKAMAI
Release #1: SSLHelper - What
    http://github.com/Panmind/ssl_helper

‣   require_ssl / ignore_ssl / refuse_ssl DSL for your
    controllers (simple wrap of a before_filter)
‣   Named route helpers (ssl_ / plain_ relatives) and test helpers
    (with_ / without_ssl, use_ / forget_ssl) generation
    redirect_to ssl_login_url
    <%= link_to “Sign up”, ssl_signup_url %>
    <% form_tag plain_search_url do %> ... <% end %>
    without_ssl do
      get :show, :id => @project.id
      assert_redirected_to ssl_project_url(@project.id)
    end

                                                    Ruby Social Club night @MIKAMAI
Release #1: SSLHelper - How
‣   Checks HTTPS / X-Forwarded-Proto variables via Rails’
    request.ssl?
‣   Includes the controller DSL straight into ActionController::Base
‣   Inserts into Rails’ router initialization by extending
    ActionController::Routing::Routes and overriding the
    reload! method (returning super do ... end)
‣   Generates ssl_ and plain_ wrappers of every named route helper
    defined in your app and puts them into an anonymous Module
‣   Includes it in ActionView::Base and in ActionController::
    {Base,Integration::Session,TestCase}


                                                             Ruby Social Club night @MIKAMAI
Release #2: BigBro - What
    http://github.com/Panmind/bigbro
‣   Google Analytics -- let’s get it straight (and async)
‣   Optimizes GA’s protocol check (it’s http://www. or https://ssl.?)
‣   Generates <noscript> tracking code
‣   Contains an embryo of a jQuery GA toolkit (in the js/ directory)
    <%= analytics %> or
    <%= analytics :track => false %>
    context “an user”
      should “be aware to live in 1984”
            get :index
            assert_analytics
      end
    end

                                                            Ruby Social Club night @MIKAMAI
Release #2: BigBro - How
‣   A submodule contains view helpers, another one test helpers
‣   The top-level module singleton class holds the initialization
    method and the GA account into an instance variable:
    class << self
      attr_accessor :account
      def set(options = {}) ... end
    end
‣   View helpers are included in ActionView::Base
‣   Test helpers are included in ActionController::TestCase

    ...Whoops, the plugin currently adds ‘em in ActiveSupport::
    TestCase! who’ll be the first to send out a pull request? :-)


                                                               Ruby Social Club night @MIKAMAI
Release #3: ReCaptcha - What
    http://github.com/Panmind/recaptcha

‣   Embeds ReCaptcha JS / Generates <noscript> code

‣   Provides a require_valid_captcha controller class method

‣   Chats with ReCaptcha HTTP service - handling timeouts

‣   AJAX validation via a custom jQuery plugin (untied to this one)

    <%= recaptcha :label => 'Human?', :theme => 'clean' %>
    require_valid_captcha :only => :create
    def invalid_captcha
      @user.errors.add_to_base('Captcha failed')
      render :new, :layout => 'login'
    end
                                                       Ruby Social Club night @MIKAMAI
Release #3: ReCaptcha - Test
Using mocha -- gem install it if you don’t have it

context ‘a guest’ do
  should ‘insert a valid captcha’
    mock_invalid_captcha
    post :signup, :email => ‘vjt@openssl.it’, ...
    assert_response :precondition_failed # 412

    mock_valid_captcha
    post :signup, :email => ‘vjt@openssl.it’, ...
    assert_redirected_to root_url # 302
  end
end

                                               Ruby Social Club night @MIKAMAI
Release #3: ReCaptcha - How
‣   Controller, View and Test helpers live in separate modules
‣   The top-level module singleton class contains the initialization
    method and the ReCaptcha keys
    class << self
      attr_accessor :private_key, :public_key, ...
      def set(options = {}) ... end
    end
‣   Controller methods included in ActionController::Base, and
    self.included() adds the require_valid_captcha method
‣   View helpers are included in ActionView::Base
‣   Test helpers are included in ActionController::TestCase

                                                       Ruby Social Club night @MIKAMAI
Release #3: ReCaptcha - AJAX
‣   ReCaptchas can be validated only once
‣   The jquery.ajax-validate plugin calls a controller action
    (Metal is better) that returns different HTTP status codes
‣   If successful, a flag is saved in the flash
‣   When the form is submitted, if the flag is true, ReCaptcha
    validation is skipped
‣   Unless your session cookies can be tampered with, the code is not
    vulnerable to replay attacks
‣   Older versions used a DB table first, memcached after.. but the
    flash is the best choice -- see the commit history for details :-)


                                                       Ruby Social Club night @MIKAMAI
Release #4: Zendesk - What
    http://github.com/Panmind/zendesk
‣   Zendesk? The best support platform / CRM in town
‣   View helpers to generate the trendy “feedback” button code --->
    and to generate links that display the feedback form
‣   Route and controller methods to implement Zendesk’s remote
    authentication: your users won’t have to register and log in on the
    support forum
‣   View helpers to generate links to the support forum
    <%= zendesk_dropbox_tags %>
    <%= zendesk_link_to ‘Support’ %>
    map.zendesk ‘/support’, :controller => :sessions

                                                       Ruby Social Club night @MIKAMAI
Release #4: Zendesk - How
‣   View helpers are included into ActionView::Base
‣   The route generation method is included into
    ActionController::Routing::RouteSet::Mapper
‣   This time, you have to include the controller methods into your
    login controller: in development mode they would be lost because
    of ActiveSupport’s reloading (solutions welcome!)


‣   Too much configuration is needed to make it work; your login
    action must implement a redirect_to params[:return_to]
    -- does anyone want to help?

                                                     Ruby Social Club night @MIKAMAI
Release #4: Zendesk - Flow
1. Guest clicks on zendesk_link_to(‘Support’)
2. Guest is taken to the support forum
3. Guest clicks ‘login’ in the support forum
4. Guest is redirected to the login page by the
  zendesk_handle_guests filter of the zendesk_login action
5. User is redirected to the zendesk_login action
6. User is redirected to zendesk’s remote authentication endpoint with a
  set of query string parameters (hash, timestamp, ...) and logged in
  ----------------------------------------------------------
1. User clicks on zendesk_link_to(‘Support’)
2. GOTO 5

                                                        Ruby Social Club night @MIKAMAI
Release #5: Leaker
Don’t use this plugin.
It’s an example of how plugins can be
evil. Even if written elegantly.

If you’re really curious why you shouldn’t, read the documentation
on GitHub - http://github.com/Panmind/leaker


You have been warned :-p


                                                  Ruby Social Club night @MIKAMAI
Where is the live demo?
SSLHelper: curl -I http://panmind.org/login -> 301

BigBro: have a look at the source of any panmind.org page, and
search for ga.js

ReCaptcha: https://panmind.org/signup input wrong data first and
then sign up

Zendesk: try the “Support” link in the footer and the “feedback” ->
button on the right of every page - both before and after logging in

Leaker: no way! :-)


                                                   Ruby Social Club night @MIKAMAI
Thank you! :-)

@vjt - vjt@openssl.it
http://panmind.org/



                        Ruby Social Club night @MIKAMAI

More Related Content

What's hot

Hackathon - Building vaadin add on components
Hackathon - Building vaadin add on componentsHackathon - Building vaadin add on components
Hackathon - Building vaadin add on componentsJoonas Lehtinen
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsSami Ekblad
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Matt Raible
 
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Matt Raible
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should knowPovilas Korop
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Ukraine
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Zach Lendon
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementZach Lendon
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSShekhar Gulati
 
What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017Matt Raible
 
Building fast and performant apps
Building fast and performant appsBuilding fast and performant apps
Building fast and performant appsRahul Yadav
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptKaty Slemon
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...Katy Slemon
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinJava User Group Latvia
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5Rob Tweed
 
webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)Hendrik Ebbers
 
Predictable Web Apps with Angular and Redux
Predictable Web Apps with Angular and ReduxPredictable Web Apps with Angular and Redux
Predictable Web Apps with Angular and ReduxFITC
 

What's hot (20)

Hackathon - Building vaadin add on components
Hackathon - Building vaadin add on componentsHackathon - Building vaadin add on components
Hackathon - Building vaadin add on components
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
 
Os Johnson
Os JohnsonOs Johnson
Os Johnson
 
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
 
Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails Spring Boot
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017
 
Hack the Future
Hack the FutureHack the Future
Hack the Future
 
Building fast and performant apps
Building fast and performant appsBuilding fast and performant apps
Building fast and performant apps
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
 
webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)
 
Predictable Web Apps with Angular and Redux
Predictable Web Apps with Angular and ReduxPredictable Web Apps with Angular and Redux
Predictable Web Apps with Angular and Redux
 

Viewers also liked

RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011Marcello Barnaba
 
Zarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychZarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychMarcinStachniuk
 
Полный цикл разработки на Python + Django
Полный цикл разработки на Python + DjangoПолный цикл разработки на Python + Django
Полный цикл разработки на Python + DjangoAzamat Tokhtaev
 
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychLiquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychMarcinStachniuk
 
Failcon Atlanta - A Post-mortem of a healthcare startup
Failcon Atlanta - A Post-mortem of a healthcare startupFailcon Atlanta - A Post-mortem of a healthcare startup
Failcon Atlanta - A Post-mortem of a healthcare startupClassPass
 

Viewers also liked (7)

RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011
 
Zarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychZarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danych
 
Полный цикл разработки на Python + Django
Полный цикл разработки на Python + DjangoПолный цикл разработки на Python + Django
Полный цикл разработки на Python + Django
 
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychLiquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
 
Retrospekcja warsztat Agile3M
Retrospekcja warsztat Agile3MRetrospekcja warsztat Agile3M
Retrospekcja warsztat Agile3M
 
Failcon Atlanta - A Post-mortem of a healthcare startup
Failcon Atlanta - A Post-mortem of a healthcare startupFailcon Atlanta - A Post-mortem of a healthcare startup
Failcon Atlanta - A Post-mortem of a healthcare startup
 
Penetrationtestinglovesfreesoftware libreplaner2017-christianfernandez-hispag...
Penetrationtestinglovesfreesoftware libreplaner2017-christianfernandez-hispag...Penetrationtestinglovesfreesoftware libreplaner2017-christianfernandez-hispag...
Penetrationtestinglovesfreesoftware libreplaner2017-christianfernandez-hispag...
 

Similar to Panmind at Ruby Social Club Milano

Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformIhor Uzhvenko
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-publicChul Ju Hong
 
Quick Start: ActiveScaffold
Quick Start: ActiveScaffoldQuick Start: ActiveScaffold
Quick Start: ActiveScaffoldDavid Keener
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatternsChul Ju Hong
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsDevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsAmazon Web Services
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaPantheon
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation Zivtech, LLC
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon praguehernanibf
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Matt Raible
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentsadomovalex
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Matt Raible
 
Vue micro frontend implementation patterns
Vue micro frontend implementation patternsVue micro frontend implementation patterns
Vue micro frontend implementation patternsAlbert Brand
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with RailsPaul Gallagher
 

Similar to Panmind at Ruby Social Club Milano (20)

Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Basic Rails Training
Basic Rails TrainingBasic Rails Training
Basic Rails Training
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platform
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Quick Start: ActiveScaffold
Quick Start: ActiveScaffoldQuick Start: ActiveScaffold
Quick Start: ActiveScaffold
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsDevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon prague
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint development
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Vue micro frontend implementation patterns
Vue micro frontend implementation patternsVue micro frontend implementation patterns
Vue micro frontend implementation patterns
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with Rails
 

Recently uploaded

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Panmind at Ruby Social Club Milano

  • 1. /vendor/plugins/panmind Spinoffs from a large Rails Application Ruby Social Club night @MIKAMAI
  • 2. Why? ‣ Code you write in /app will be obsolete soon ‣ Code you write in /lib will be obsolete less soon (maybe) ‣ Code you you share with the Open Source community could live really long and beyond your expectations ‣ It’s a sane engineering principle to write reusable code ‣ Sharing the code makes you write good documentation Ruby Social Club night @MIKAMAI
  • 3. How? ‣ gem uninstall -f copy-paste ide-tools ‣ Abstract early, abstract often ‣ Create temporary modules in your models, helpers, controllers ‣ Move those modules away in /lib[1] - SOON ‣ Decouple ‘em from the app assumptions, logic and configuration ‣ Move ‘em in /vendor/plugins ‣ [1]: Optional but recommended: config.load_once_paths.push((Rails.root+'lib').to_s) Ruby Social Club night @MIKAMAI
  • 4. A real world example http://github.com/Panmind/bigbro/commits/master ‣ Write code in /lib, include the rusty module(s) in your app ‣ Decouple configuration: - def account - Config[:id] + attr_accessor :account + def self.set(options = {}) + self.account = options[:account] ‣ Remove initialization code and put it in init.rb ‣ Rename the module and move code around ‣ Write documentation ‣ Release (Git is your friend: co, cherry-pick and rebase -i) ‣ Present at a Ruby event so someone else will write tests ;-) Ruby Social Club night @MIKAMAI
  • 5. Compatibility checklist ‣ Ruby 1.9.1-p378 ‣ Rails 2.3.8 ‣ rails_xss plugin ‣ Patches to support older versions of Ruby/Rails and/or without the rails_xss plugin more than welcome! (it’s just an .html_safe after all :-) Ruby Social Club night @MIKAMAI
  • 6. Release #1: SSLHelper - What http://github.com/Panmind/ssl_helper ‣ require_ssl / ignore_ssl / refuse_ssl DSL for your controllers (simple wrap of a before_filter) ‣ Named route helpers (ssl_ / plain_ relatives) and test helpers (with_ / without_ssl, use_ / forget_ssl) generation redirect_to ssl_login_url <%= link_to “Sign up”, ssl_signup_url %> <% form_tag plain_search_url do %> ... <% end %> without_ssl do get :show, :id => @project.id assert_redirected_to ssl_project_url(@project.id) end Ruby Social Club night @MIKAMAI
  • 7. Release #1: SSLHelper - How ‣ Checks HTTPS / X-Forwarded-Proto variables via Rails’ request.ssl? ‣ Includes the controller DSL straight into ActionController::Base ‣ Inserts into Rails’ router initialization by extending ActionController::Routing::Routes and overriding the reload! method (returning super do ... end) ‣ Generates ssl_ and plain_ wrappers of every named route helper defined in your app and puts them into an anonymous Module ‣ Includes it in ActionView::Base and in ActionController:: {Base,Integration::Session,TestCase} Ruby Social Club night @MIKAMAI
  • 8. Release #2: BigBro - What http://github.com/Panmind/bigbro ‣ Google Analytics -- let’s get it straight (and async) ‣ Optimizes GA’s protocol check (it’s http://www. or https://ssl.?) ‣ Generates <noscript> tracking code ‣ Contains an embryo of a jQuery GA toolkit (in the js/ directory) <%= analytics %> or <%= analytics :track => false %> context “an user” should “be aware to live in 1984” get :index assert_analytics end end Ruby Social Club night @MIKAMAI
  • 9. Release #2: BigBro - How ‣ A submodule contains view helpers, another one test helpers ‣ The top-level module singleton class holds the initialization method and the GA account into an instance variable: class << self attr_accessor :account def set(options = {}) ... end end ‣ View helpers are included in ActionView::Base ‣ Test helpers are included in ActionController::TestCase ...Whoops, the plugin currently adds ‘em in ActiveSupport:: TestCase! who’ll be the first to send out a pull request? :-) Ruby Social Club night @MIKAMAI
  • 10. Release #3: ReCaptcha - What http://github.com/Panmind/recaptcha ‣ Embeds ReCaptcha JS / Generates <noscript> code ‣ Provides a require_valid_captcha controller class method ‣ Chats with ReCaptcha HTTP service - handling timeouts ‣ AJAX validation via a custom jQuery plugin (untied to this one) <%= recaptcha :label => 'Human?', :theme => 'clean' %> require_valid_captcha :only => :create def invalid_captcha @user.errors.add_to_base('Captcha failed') render :new, :layout => 'login' end Ruby Social Club night @MIKAMAI
  • 11. Release #3: ReCaptcha - Test Using mocha -- gem install it if you don’t have it context ‘a guest’ do should ‘insert a valid captcha’ mock_invalid_captcha post :signup, :email => ‘vjt@openssl.it’, ... assert_response :precondition_failed # 412 mock_valid_captcha post :signup, :email => ‘vjt@openssl.it’, ... assert_redirected_to root_url # 302 end end Ruby Social Club night @MIKAMAI
  • 12. Release #3: ReCaptcha - How ‣ Controller, View and Test helpers live in separate modules ‣ The top-level module singleton class contains the initialization method and the ReCaptcha keys class << self attr_accessor :private_key, :public_key, ... def set(options = {}) ... end end ‣ Controller methods included in ActionController::Base, and self.included() adds the require_valid_captcha method ‣ View helpers are included in ActionView::Base ‣ Test helpers are included in ActionController::TestCase Ruby Social Club night @MIKAMAI
  • 13. Release #3: ReCaptcha - AJAX ‣ ReCaptchas can be validated only once ‣ The jquery.ajax-validate plugin calls a controller action (Metal is better) that returns different HTTP status codes ‣ If successful, a flag is saved in the flash ‣ When the form is submitted, if the flag is true, ReCaptcha validation is skipped ‣ Unless your session cookies can be tampered with, the code is not vulnerable to replay attacks ‣ Older versions used a DB table first, memcached after.. but the flash is the best choice -- see the commit history for details :-) Ruby Social Club night @MIKAMAI
  • 14. Release #4: Zendesk - What http://github.com/Panmind/zendesk ‣ Zendesk? The best support platform / CRM in town ‣ View helpers to generate the trendy “feedback” button code ---> and to generate links that display the feedback form ‣ Route and controller methods to implement Zendesk’s remote authentication: your users won’t have to register and log in on the support forum ‣ View helpers to generate links to the support forum <%= zendesk_dropbox_tags %> <%= zendesk_link_to ‘Support’ %> map.zendesk ‘/support’, :controller => :sessions Ruby Social Club night @MIKAMAI
  • 15. Release #4: Zendesk - How ‣ View helpers are included into ActionView::Base ‣ The route generation method is included into ActionController::Routing::RouteSet::Mapper ‣ This time, you have to include the controller methods into your login controller: in development mode they would be lost because of ActiveSupport’s reloading (solutions welcome!) ‣ Too much configuration is needed to make it work; your login action must implement a redirect_to params[:return_to] -- does anyone want to help? Ruby Social Club night @MIKAMAI
  • 16. Release #4: Zendesk - Flow 1. Guest clicks on zendesk_link_to(‘Support’) 2. Guest is taken to the support forum 3. Guest clicks ‘login’ in the support forum 4. Guest is redirected to the login page by the zendesk_handle_guests filter of the zendesk_login action 5. User is redirected to the zendesk_login action 6. User is redirected to zendesk’s remote authentication endpoint with a set of query string parameters (hash, timestamp, ...) and logged in ---------------------------------------------------------- 1. User clicks on zendesk_link_to(‘Support’) 2. GOTO 5 Ruby Social Club night @MIKAMAI
  • 17. Release #5: Leaker Don’t use this plugin. It’s an example of how plugins can be evil. Even if written elegantly. If you’re really curious why you shouldn’t, read the documentation on GitHub - http://github.com/Panmind/leaker You have been warned :-p Ruby Social Club night @MIKAMAI
  • 18. Where is the live demo? SSLHelper: curl -I http://panmind.org/login -> 301 BigBro: have a look at the source of any panmind.org page, and search for ga.js ReCaptcha: https://panmind.org/signup input wrong data first and then sign up Zendesk: try the “Support” link in the footer and the “feedback” -> button on the right of every page - both before and after logging in Leaker: no way! :-) Ruby Social Club night @MIKAMAI
  • 19. Thank you! :-) @vjt - vjt@openssl.it http://panmind.org/ Ruby Social Club night @MIKAMAI