SlideShare una empresa de Scribd logo
1 de 45
Descargar para leer sin conexión
Making and Breaking
  Web Services
   (with Ruby)
      Chris Wanstrath
          Err Free
     http://errfree.com
ttp://farm1.static.flickr.com/138/320699460_b8e7c1e7e6_o.jpg
SOAP
• Simple Object Access Protocol?
• Lies.
• Service Oriented Architecture Protocol
• wtf.
Newsletters!
“Outbound”

• Slow response time
• Duplication of data
• Hard to debug
• require ‘soap/wsdlDriver’
Ruby SOAP Library:
      Your Friend

• Creates methods on the fly
• Seems to work pretty well
• Transparently converts Ruby types to SOAP
  definitions
Ruby SOAP Library:
      Your Enemy

• Hard to debug (dump req/res to file)
• No one has ever used it
• There are not any alternatives
• The code is a jungle
Why use SOAP?


• One reason: legacy.
Wrapping SOAP
def update_user(email, subs = [], unsubs = [])
  client.updateUser(brand, email, email, demo, subs, unsubs)
end
Wrapping SOAP
def update_user(email, subs = [], unsubs = [])
  client.updateUser(brand, email, email, demo, subs, unsubs)
end




def get_user(email)
  client.getUser(email, brand)
end
Wrapping SOAP
def update_user(email, subs = [], unsubs = [])
  client.updateUser(brand, email, email, demo, subs, unsubs)
end




def get_user(email)
  client.getUser(email, brand)
end
Wrapping SOAP
def update_user(email, subs = [], unsubs = [])
  client.updateUser(brand, email, email, demo, subs, unsubs)
end




def get_user(email)
  client.getUser(email, brand)
end
Testing SOAP


• Use mocks
• Mocha: http://mocha.rubyforge.org
Testing SOAP

def test_get_user_should_hit_client
  email = 'chrisw@nstrath.com'
  Outbound.client.expects(:getUser).with(email, Outbound.brand)
  Outbound.get_user(email)
end
Testing SOAP

soap_methods = {
  :getUser    => true,
  :updateUser => true
}

Outbound.stubs(:client).returns(mock('SOAP Service', soap_methods))
Running a SOAP Server
       in Ruby
Just Kidding
Microformats!
• Your website is your API
• Plant classes in HTML
• Tell parsers what information is important
• http://microformats.org
hReview
hReview
<div id="review_16873" class="hreview">
  <h5 class="item"><span class="fn">Beringer California Collection White Merlot 20
  <abbr class="dtreviewed" title="20070420">(1 day ago)</abbr>
  <span class="reviewer vcard">
     <img class="photo" src="/assets/avatars/c19d1b2080f73765d420b461d3133ffa.jpg"
     <a class="url fn" href="/people/garyvaynerchuk">garyvaynerchuk</a>
  </span>
  <abbr class="rating" title="50.0">50.0<em>/100</em></abbr>
  <blockquote class="description">Had this in an industry event the other day, man
  <p class="tags">Tasting Tags:
  <a href="/tags/pink" rel="tag" class="rel-tag" title="view all wines with this t
  <a href="/tags/sugar" rel="tag" class="rel-tag" title="view all wines with this
</p>
</div>
hReview
<div id="review_16873" class="hreview">
  <h5 class="item"><span class="fn">Beringer California Collection White Merlot 20
  <abbr class="dtreviewed" title="20070420">(1 day ago)</abbr>
  <span class="reviewer vcard">
     <img class="photo" src="/assets/avatars/c19d1b2080f73765d420b461d3133ffa.jpg"
     <a class="url fn" href="/people/garyvaynerchuk">garyvaynerchuk</a>
  </span>
  <abbr class="rating" title="50.0">50.0<em>/100</em></abbr>
  <blockquote class="description">Had this in an industry event the other day, man
  <p class="tags">Tasting Tags:
  <a href="/tags/pink" rel="tag" class="rel-tag" title="view all wines with this t
  <a href="/tags/sugar" rel="tag" class="rel-tag" title="view all wines with this
</p>
</div>
mofo
$ sudo gem install mofo
Successfully installed mofo-0.2.2
$ irb -rubygems
>> require 'mofo/hreview'
=> true
>> review = HReview.find :first => 'http://corkd.com/wine/view/21670'
=> #<HReview:0x1598d04 ...>
>> review.properties
=> ["description", "item", "dtreviewed", "tags", "rating", "reviewer"]
>> review.rating
=> 50.0
>> review.item.fn
=> "Beringer California Collection White Merlot 2005"
>> review.reviewer.fn
=> "garyvaynerchuk"
mofo/hreview.rb
class HReview < Microformat
  one :version, :summary, :type, :dtreviewed,
      :rating, :description

 one :reviewer => HCard

  one :item! do
    one :fn
  end
end
microformat.rb
def collector
  collector = Hash.new([])
  def collector.method_missing(method, *classes)
    super unless %w(one many).include? method.to_s
    self[method] += Microformat.send(:break_out_hashes, classes)
  end
  collector
end
mofo supports...

              • xoxo
• hCard
              • geo
• hCalendar
              • adr
• hReview
              • xfn
• hEntry
• hResume
What else can they do?
Operator
Operator
Okay.
Hpricot




( by _why )
Hpricot
$ irb -rubygems -r'open-uri'
>> require 'hpricot'
=> true
>> page = Hpricot open('http://google.com')
=> #<Hpricot::Doc ...>
>> page.search(:a).size
=> 20
>> page.at(:a)
=> {elem <a href="/url?sa=p&pref=ig&pval=3
   &q=http://www.google.com/ig%3Fhl%3Den&usg=
   AFrqEzfPu3dYlSVsfjI7gUHePgEkcx_VXg">
   "Personalize this page" </a>}
Hpricot
Can use XPATH, CSS selectors, whatever, to search
Hpricot

>>   page = Hpricot(open('http://brainspl.at'))
=>   #<Hpricot::Doc ...>
>>   page.search('.post').size
=>   10
Hpricot
>>   corkd = 'http://corkd.com/wine/view/21670'
=>   'http://corkd.com/wine/view/21670'
>>   page = Hpricot(open(corkd))
=>   #<Hpricot::Doc ...>
>>   page.search('.hreview').size
=>   4
Hpricot/:mofo
>> page.at('.hreview').at('.item').at('.fn').inner_text
=> "Beringer California Collection White Merlot 2005"




>> review.item.fn
=> "Beringer California Collection White Merlot 2005"
Oh, you can use Hpricot
     for XML, too.
  <Export>
    <Product>
      <SKU>403276</SKU>
      <ItemName>Trivet</ItemName>
      <CollectionNo>0</CollectionNo>
      <Pages>0</Pages>
    </Product>
  </Export>
Oh, you can use Hpricot
         for XML, too.
fields = %w(SKU ItemName CollectionNo Pages)

doc = Hpricot(open("my.xml"))
(doc/:product).each do |xml_product|
  attributes = fields.inject({}) do |hash, field|
    hash.merge(field => xml_product.at(field).innerHTML)
  end
  Product.create(attributes)
end


        ( also there’s Hpricot::XML() )
But who uses XML?
Cheat!
     http://cheat.errtheblog.com


(insert short, live demo here)
Thanks
•   http://mofo.rubyforge.org

•   http://code.whytheluckystiff.net/hpricot

•   https://addons.mozilla.org/en-US/firefox/addon/4106

•   http://microformats.org

•   http://upcoming.yahoo.com/

•   http://corkd.com/

•   http://chow.com

•   http://chowhound.com
Thanks

•   http://ronrothman.com/gallery/cnet/cnet_neon

•   http://flickr.com/photos/bootbearwdc/466751240/

•   http://flickr.com/photos/segana/320699460/

•   http://flickr.com/photos/spiffariffic/456211526/

Más contenido relacionado

La actualidad más candente

Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2RORLAB
 
Even Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax ExperienceEven Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax ExperienceSteve Souders
 
RubyMotion
RubyMotionRubyMotion
RubyMotionMark
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2RORLAB
 
Damage Control
Damage ControlDamage Control
Damage Controlsintaxi
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014Guillaume POTIER
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101Nando Vieira
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsKai Cui
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsMichelangelo van Dam
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesjerryorr
 
20111030i phonedeveloperworkshoppublished
20111030i phonedeveloperworkshoppublished20111030i phonedeveloperworkshoppublished
20111030i phonedeveloperworkshoppublishedYoichiro Sakurai
 
javascript for backend developers
javascript for backend developersjavascript for backend developers
javascript for backend developersThéodore Biadala
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2RORLAB
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 

La actualidad más candente (20)

Excellent
ExcellentExcellent
Excellent
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
RSpec
RSpecRSpec
RSpec
 
Even Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax ExperienceEven Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax Experience
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
 
Damage Control
Damage ControlDamage Control
Damage Control
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
20111030i phonedeveloperworkshoppublished
20111030i phonedeveloperworkshoppublished20111030i phonedeveloperworkshoppublished
20111030i phonedeveloperworkshoppublished
 
javascript for backend developers
javascript for backend developersjavascript for backend developers
javascript for backend developers
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
 

Similar a Making and Breaking Web Services with Ruby

Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperfNew Relic
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)True-Vision
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with RackDonSchado
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with PerlPerrin Harkins
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략Jeen Lee
 
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseRuby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseWisely chen
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPMarc Gear
 
WebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerWebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerElixir Club
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
performance vamos dormir mais?
performance vamos dormir mais?performance vamos dormir mais?
performance vamos dormir mais?tdc-globalcode
 
Michelin Starred Cooking with Chef
Michelin Starred Cooking with ChefMichelin Starred Cooking with Chef
Michelin Starred Cooking with ChefJon Cowie
 
Integration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + SeleniumIntegration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + Seleniumtka
 

Similar a Making and Breaking Web Services with Ruby (20)

Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with Perl
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략
 
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseRuby on Rails in UbiSunrise
Ruby on Rails in UbiSunrise
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
WebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerWebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan Wintermeyer
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
performance vamos dormir mais?
performance vamos dormir mais?performance vamos dormir mais?
performance vamos dormir mais?
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Michelin Starred Cooking with Chef
Michelin Starred Cooking with ChefMichelin Starred Cooking with Chef
Michelin Starred Cooking with Chef
 
ApacheCon 2005
ApacheCon 2005ApacheCon 2005
ApacheCon 2005
 
Integration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + SeleniumIntegration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + Selenium
 

Más de err

Inside GitHub
Inside GitHubInside GitHub
Inside GitHuberr
 
The Real-Time Web (and Other Buzzwords)
The Real-Time Web (and Other Buzzwords)The Real-Time Web (and Other Buzzwords)
The Real-Time Web (and Other Buzzwords)err
 
Git: The Lean, Mean, Distributed Machine
Git: The Lean, Mean, Distributed MachineGit: The Lean, Mean, Distributed Machine
Git: The Lean, Mean, Distributed Machineerr
 
Kings of Code 2009
Kings of Code 2009Kings of Code 2009
Kings of Code 2009err
 
Forbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeForbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeerr
 
Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)err
 
Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)err
 

Más de err (7)

Inside GitHub
Inside GitHubInside GitHub
Inside GitHub
 
The Real-Time Web (and Other Buzzwords)
The Real-Time Web (and Other Buzzwords)The Real-Time Web (and Other Buzzwords)
The Real-Time Web (and Other Buzzwords)
 
Git: The Lean, Mean, Distributed Machine
Git: The Lean, Mean, Distributed MachineGit: The Lean, Mean, Distributed Machine
Git: The Lean, Mean, Distributed Machine
 
Kings of Code 2009
Kings of Code 2009Kings of Code 2009
Kings of Code 2009
 
Forbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeForbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTree
 
Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)
 
Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)
 

Último

Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFChandresh Chudasama
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Americas Got Grants
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Peter Ward
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in PhilippinesDavidSamuel525586
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxsaniyaimamuddin
 
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!Doge Mining Website
 
Call Girls Contact Number Andheri 9920874524
Call Girls Contact Number Andheri 9920874524Call Girls Contact Number Andheri 9920874524
Call Girls Contact Number Andheri 9920874524najka9823
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 

Último (20)

Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDF
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in Philippines
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
 
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!
Unlocking the Future: Explore Web 3.0 Workshop to Start Earning Today!
 
Call Girls Contact Number Andheri 9920874524
Call Girls Contact Number Andheri 9920874524Call Girls Contact Number Andheri 9920874524
Call Girls Contact Number Andheri 9920874524
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 

Making and Breaking Web Services with Ruby

  • 1. Making and Breaking Web Services (with Ruby) Chris Wanstrath Err Free http://errfree.com
  • 3. SOAP • Simple Object Access Protocol? • Lies. • Service Oriented Architecture Protocol • wtf.
  • 5. “Outbound” • Slow response time • Duplication of data • Hard to debug • require ‘soap/wsdlDriver’
  • 6. Ruby SOAP Library: Your Friend • Creates methods on the fly • Seems to work pretty well • Transparently converts Ruby types to SOAP definitions
  • 7. Ruby SOAP Library: Your Enemy • Hard to debug (dump req/res to file) • No one has ever used it • There are not any alternatives • The code is a jungle
  • 8. Why use SOAP? • One reason: legacy.
  • 9.
  • 10. Wrapping SOAP def update_user(email, subs = [], unsubs = []) client.updateUser(brand, email, email, demo, subs, unsubs) end
  • 11. Wrapping SOAP def update_user(email, subs = [], unsubs = []) client.updateUser(brand, email, email, demo, subs, unsubs) end def get_user(email) client.getUser(email, brand) end
  • 12. Wrapping SOAP def update_user(email, subs = [], unsubs = []) client.updateUser(brand, email, email, demo, subs, unsubs) end def get_user(email) client.getUser(email, brand) end
  • 13. Wrapping SOAP def update_user(email, subs = [], unsubs = []) client.updateUser(brand, email, email, demo, subs, unsubs) end def get_user(email) client.getUser(email, brand) end
  • 14.
  • 15. Testing SOAP • Use mocks • Mocha: http://mocha.rubyforge.org
  • 16. Testing SOAP def test_get_user_should_hit_client email = 'chrisw@nstrath.com' Outbound.client.expects(:getUser).with(email, Outbound.brand) Outbound.get_user(email) end
  • 17. Testing SOAP soap_methods = { :getUser => true, :updateUser => true } Outbound.stubs(:client).returns(mock('SOAP Service', soap_methods))
  • 18. Running a SOAP Server in Ruby
  • 20. Microformats! • Your website is your API • Plant classes in HTML • Tell parsers what information is important • http://microformats.org
  • 22. hReview <div id="review_16873" class="hreview"> <h5 class="item"><span class="fn">Beringer California Collection White Merlot 20 <abbr class="dtreviewed" title="20070420">(1 day ago)</abbr> <span class="reviewer vcard"> <img class="photo" src="/assets/avatars/c19d1b2080f73765d420b461d3133ffa.jpg" <a class="url fn" href="/people/garyvaynerchuk">garyvaynerchuk</a> </span> <abbr class="rating" title="50.0">50.0<em>/100</em></abbr> <blockquote class="description">Had this in an industry event the other day, man <p class="tags">Tasting Tags: <a href="/tags/pink" rel="tag" class="rel-tag" title="view all wines with this t <a href="/tags/sugar" rel="tag" class="rel-tag" title="view all wines with this </p> </div>
  • 23. hReview <div id="review_16873" class="hreview"> <h5 class="item"><span class="fn">Beringer California Collection White Merlot 20 <abbr class="dtreviewed" title="20070420">(1 day ago)</abbr> <span class="reviewer vcard"> <img class="photo" src="/assets/avatars/c19d1b2080f73765d420b461d3133ffa.jpg" <a class="url fn" href="/people/garyvaynerchuk">garyvaynerchuk</a> </span> <abbr class="rating" title="50.0">50.0<em>/100</em></abbr> <blockquote class="description">Had this in an industry event the other day, man <p class="tags">Tasting Tags: <a href="/tags/pink" rel="tag" class="rel-tag" title="view all wines with this t <a href="/tags/sugar" rel="tag" class="rel-tag" title="view all wines with this </p> </div>
  • 24. mofo $ sudo gem install mofo Successfully installed mofo-0.2.2 $ irb -rubygems >> require 'mofo/hreview' => true >> review = HReview.find :first => 'http://corkd.com/wine/view/21670' => #<HReview:0x1598d04 ...> >> review.properties => ["description", "item", "dtreviewed", "tags", "rating", "reviewer"] >> review.rating => 50.0 >> review.item.fn => "Beringer California Collection White Merlot 2005" >> review.reviewer.fn => "garyvaynerchuk"
  • 25. mofo/hreview.rb class HReview < Microformat one :version, :summary, :type, :dtreviewed, :rating, :description one :reviewer => HCard one :item! do one :fn end end
  • 26. microformat.rb def collector collector = Hash.new([]) def collector.method_missing(method, *classes) super unless %w(one many).include? method.to_s self[method] += Microformat.send(:break_out_hashes, classes) end collector end
  • 27. mofo supports... • xoxo • hCard • geo • hCalendar • adr • hReview • xfn • hEntry • hResume
  • 28.
  • 29.
  • 30. What else can they do?
  • 33. Okay.
  • 35. Hpricot $ irb -rubygems -r'open-uri' >> require 'hpricot' => true >> page = Hpricot open('http://google.com') => #<Hpricot::Doc ...> >> page.search(:a).size => 20 >> page.at(:a) => {elem <a href="/url?sa=p&pref=ig&pval=3 &q=http://www.google.com/ig%3Fhl%3Den&usg= AFrqEzfPu3dYlSVsfjI7gUHePgEkcx_VXg"> "Personalize this page" </a>}
  • 36. Hpricot Can use XPATH, CSS selectors, whatever, to search
  • 37. Hpricot >> page = Hpricot(open('http://brainspl.at')) => #<Hpricot::Doc ...> >> page.search('.post').size => 10
  • 38. Hpricot >> corkd = 'http://corkd.com/wine/view/21670' => 'http://corkd.com/wine/view/21670' >> page = Hpricot(open(corkd)) => #<Hpricot::Doc ...> >> page.search('.hreview').size => 4
  • 39. Hpricot/:mofo >> page.at('.hreview').at('.item').at('.fn').inner_text => "Beringer California Collection White Merlot 2005" >> review.item.fn => "Beringer California Collection White Merlot 2005"
  • 40. Oh, you can use Hpricot for XML, too. <Export> <Product> <SKU>403276</SKU> <ItemName>Trivet</ItemName> <CollectionNo>0</CollectionNo> <Pages>0</Pages> </Product> </Export>
  • 41. Oh, you can use Hpricot for XML, too. fields = %w(SKU ItemName CollectionNo Pages) doc = Hpricot(open("my.xml")) (doc/:product).each do |xml_product| attributes = fields.inject({}) do |hash, field| hash.merge(field => xml_product.at(field).innerHTML) end Product.create(attributes) end ( also there’s Hpricot::XML() )
  • 43. Cheat! http://cheat.errtheblog.com (insert short, live demo here)
  • 44. Thanks • http://mofo.rubyforge.org • http://code.whytheluckystiff.net/hpricot • https://addons.mozilla.org/en-US/firefox/addon/4106 • http://microformats.org • http://upcoming.yahoo.com/ • http://corkd.com/ • http://chow.com • http://chowhound.com
  • 45. Thanks • http://ronrothman.com/gallery/cnet/cnet_neon • http://flickr.com/photos/bootbearwdc/466751240/ • http://flickr.com/photos/segana/320699460/ • http://flickr.com/photos/spiffariffic/456211526/