Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Response • JSON or XML body • SOAP envelope

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Too big? Inadequate?

Slide 6

Slide 6 text

Custom mapping with ROXML

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Simplify

Slide 9

Slide 9 text

JSON Request free with Ruby Hash

Slide 10

Slide 10 text

XML Request • raw String • ERB templates • XML builders

Slide 11

Slide 11 text

Response • Mappers • Models

Slide 12

Slide 12 text

Thank You with a special to Fabien Catteau

Slide 13

Slide 13 text

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