real world fun with activeresource
TRANSCRIPT
Topics
ActiveResource: A brief overview
Limitations
ActiveResource architecture & usage
Demo Time
Testing
What ActiveResource Is
An ORM for RESTful* Web Services
Provides an ActiveRecord like way of accessing resources
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
More Limitations
Deserialisation Performance
Look at faster_from_xml plugin
Class Level connections
Giles Bowkett’s Dapper Resource
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
Model Code
class Person < ActiveResource::Base self.site = "http://api.people.com:3000/" self.username = “api” self.password = “api”end
Doing Calls
person = Person.find(1)person.first_name = “John”person.last_name = “Smith”person.save
other_person = Person.newother_person.first_name = “Bill”other_person.last_name = “Jones”other_person.save
Testing
ActiveResource uses HttpMock in its Test Suite
Uses stubbed HTTP requests
Returns instantiated ActiveResource models
Links
HyperactiveResource
github.com/lukegalea/hyperactiveresource/
faster_from_xml
http://fasterfromxml.rubyforge.org/
Dapper Resource
http://rubyforge.org/projects/dapper-resource/
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