Interacting with 3rd party services

Interacting with 3rd party services

Lightning talk at RuLu 2014

7d1caf9df777b3b2cf474ff743494335?s=128

Jérémy Lecour

June 20, 2014
Tweet

Transcript

  1. Interacting with 3rd party web services Keep it simple and

    lightweight RuLu 2014, June 19-20
  2. Request • query parameters • JSON or XML body •

    SOAP envelope
  3. Response • JSON or XML body • SOAP envelope

  4. Mapping to Ruby objects • JSON to Hash : easy

    • XML to Nokogiri : doable • SOAP to anything : attrocious
  5. Too big? Inadequate?

  6. Custom mapping with ROXML

  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
  8. Simplify

  9. JSON Request free with Ruby Hash

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

    builders
  11. Response • Mappers • Models

  12. Thank You with a special to Fabien Catteau

  13. jeremy.lecour@gmail.com @jlecour jeremy.wordpress.com github.com/jlecour