Real World Fun with ActiveResource

2,475 views

Published on

Presentation I presented at the Melbourne Ruby User Group on Sep. 25 2008 on using ActiveResource in a Ruby on Rails application

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,475
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
16
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Real World Fun with ActiveResource

  1. 1. Real World Fun with ActiveResource Rob Caporetto
  2. 2. Topics ActiveResource: A brief overview Limitations ActiveResource architecture & usage Demo Time Testing
  3. 3. The Is & Is Nots of ActiveResource
  4. 4. What ActiveResource Is An ORM for RESTful* Web Services Provides an ActiveRecord like way of accessing resources
  5. 5. What ActiveResource is Not ActiveRecord for Web Services
  6. 6. Limitations No ActiveRecord Style Validations Use hyperactiveresource or write your own Values Not Always Present hyperactiveresource allows these to be defined Ensure attributes are included on the server end
  7. 7. More Limitations Deserialisation Performance Look at faster_from_xml plugin Class Level connections Giles Bowkett’s Dapper Resource
  8. 8. Real World ActiveResource
  9. 9. The Server Rails Application with exposes Resources Uses ActiveRecord to talk to the DB Needs to support .xml format for resources Can support HTTP Basic Authentication if required
  10. 10. The Client Normal Rails Application* Models use ActiveResource::Base
  11. 11. Model Code class Person < ActiveResource::Base self.site = quot;http://api.people.com:3000/quot; self.username = “api” self.password = “api” end
  12. 12. Doing Calls person = Person.find(1) person.first_name = “John” person.last_name = “Smith” person.save other_person = Person.new other_person.first_name = “Bill” other_person.last_name = “Jones” other_person.save
  13. 13. A Demo...
  14. 14. Testing ActiveResource uses HttpMock in its Test Suite Uses stubbed HTTP requests Returns instantiated ActiveResource models
  15. 15. Test Code
  16. 16. Links HyperactiveResource github.com/lukegalea/hyperactiveresource/ faster_from_xml http://fasterfromxml.rubyforge.org/ Dapper Resource http://rubyforge.org/projects/dapper-resource/
  17. 17. More Links More on using http_mock in tests seangeo.blogspot.com/2007/09/testing- activeresource.html giantrobots.thoughtbot.com/2007/2/2/ activeresource-and-testing

×