real world fun with activeresource

17
Real World Fun with ActiveResource Rob Caporetto

Upload: rob-c

Post on 20-Aug-2015

2.092 views

Category:

Technology


2 download

TRANSCRIPT

Real World Fun with ActiveResource

Rob Caporetto

Topics

ActiveResource: A brief overview

Limitations

ActiveResource architecture & usage

Demo Time

Testing

The Is & Is Nots of ActiveResource

What ActiveResource Is

An ORM for RESTful* Web Services

Provides an ActiveRecord like way of accessing resources

What ActiveResource is Not

ActiveRecord for Web Services

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

Real World ActiveResource

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

The Client

Normal Rails Application*

Models use ActiveResource::Base

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

A Demo...

Testing

ActiveResource uses HttpMock in its Test Suite

Uses stubbed HTTP requests

Returns instantiated ActiveResource models

Test Code

Links

HyperactiveResource

github.com/lukegalea/hyperactiveresource/

faster_from_xml

http://fasterfromxml.rubyforge.org/

Dapper Resource

http://rubyforge.org/projects/dapper-resource/