Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Interacting with 3rd party services

Interacting with 3rd party services

Lightning talk at RuLu 2014

Jérémy Lecour

June 20, 2014
Tweet

More Decks by Jérémy Lecour

Other Decks in Technology

Transcript

  1. Interacting with
    3rd party web services
    Keep it simple and lightweight
    RuLu 2014, June 19-20

    View Slide

  2. Request
    • query parameters
    • JSON or XML body
    • SOAP envelope

    View Slide

  3. Response
    • JSON or XML body
    • SOAP envelope

    View Slide

  4. Mapping to Ruby objects
    • JSON to Hash : easy
    • XML to Nokogiri : doable
    • SOAP to anything : attrocious

    View Slide

  5. Too big?
    Inadequate?

    View Slide

  6. Custom mapping
    with ROXML

    View Slide

  7. require 'roxml'
    module Mapping
    class Base
    include ROXML
    xml_convention :capitalize
    end
    class Room < Base
    xml_reader :total_price, :from => '@TotalPrice', :as => Float
    xml_reader :nb_rooms, :from => '@NbRooms', :as => Integer
    def breakfast_included?
    %w(B D P A).include?(meals.to_s)
    end
    end
    class Hotel < Base
    xml_reader :native_id, :from => "@DistNum"
    xml_reader :name, :from => "@Name"
    xml_reader :rooms, :as => [Room]
    end
    class FB_MultirateRS < Base
    xml_reader :hotels, :as => [Hotel], :from => 'Hotels/Hotel'
    end
    end

    View Slide

  8. Simplify

    View Slide

  9. JSON Request
    free with Ruby Hash

    View Slide

  10. XML Request
    • raw String
    • ERB templates
    • XML builders

    View Slide

  11. Response
    • Mappers
    • Models

    View Slide

  12. Thank
    You
    with a special to Fabien Catteau

    View Slide

  13. [email protected]
    @jlecour
    jeremy.wordpress.com
    github.com/jlecour

    View Slide