ActiveRecord Adapters

1 view
Skip to first unread message

Henry Maddocks

unread,
Jun 30, 2009, 7:52:38 PM6/30/09
to WellR...@googlegroups.com
My Google fu is failing me today ;(

I am thinking of writing an 'Active Record like' interface to a public
API (Digital NZ in this case). What's the best way to go about it?

Should I write an adapter?
Should I monkey patch the find methods on Active Record?
Should I avoid Active Record entirely?
Or is there an easier way?

TIA

Henry


scottmotte

unread,
Jun 30, 2009, 8:03:07 PM6/30/09
to WellRailed
Henry,

I recommend using httparty. Works like a charm for apis.

http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited
http://github.com/jnunemaker/httparty/tree/master

You just include it in your model. Here's a post I did on using it,
but you'll find jnunemaker's info more well written:
http://scottmotte.com/archives/218.html

Henry Maddocks

unread,
Jun 30, 2009, 8:30:47 PM6/30/09
to WellR...@googlegroups.com

On 1/07/2009, at 12:03 PM, scottmotte wrote:

I recommend using httparty. Works like a charm for apis.

That's a bit lower level than I was thinking. I've already got the http stuff working. 

What I'm after is the recommended way to provide the active record style interface, eg 

find_by_blah :order => 'foo', :limit => 'lots and lots'

scottmotte

unread,
Jun 30, 2009, 9:13:18 PM6/30/09
to WellRailed
I'm not certain, but I'm pretty sure that means you'd have to go
through the process of creating helpers, packaging them up as a gem -
basically building your own object relational mapper. Not sure what
you're building, but my 2 cents would say that's a lot of work :). My
understanding is that basically activerecord is just a big thing of
syntactic sugar that maps to the low level sql. I'm no expert though.
I've never built an orm or even helped with one so maybe someone else
can chime in.

Tim Uckun

unread,
Jun 30, 2009, 9:22:07 PM6/30/09
to WellR...@googlegroups.com
> I recommend using httparty. Works like a charm for apis.
>
> That's a bit lower level than I was thinking. I've already got the http
> stuff working.
> What I'm after is the recommended way to provide the active record style
> interface, eg
> find_by_blah :order => 'foo', :limit => 'lots and lots'
>


Maybe something like activeresource?

http://api.rubyonrails.org/classes/ActiveResource/Base.html

Henry Maddocks

unread,
Jun 30, 2009, 10:42:14 PM6/30/09
to WellR...@googlegroups.com

On 1/07/2009, at 1:22 PM, Tim Uckun wrote:


Maybe something like activeresource?

Something like it yes. The problem with activeresource is it's only useful if you're connecting to another rails app.

Might have a poke around in the code. See what pops up.

Walter McGinnis

unread,
Jul 6, 2009, 2:52:53 AM7/6/09
to WellR...@googlegroups.com
MongoMapper has some similar goals like being ActiveRecord-like, although obviously aimed at MongoDB.


I mention it for a place to get example code rather than something that will do what you want.

It's from the previously mentioned and much admired John Nunkemaker, too.  I would imagine it would have some fresher ideas than ActiveResource as is it a brandnew piece of code.

All this might be for not.  Judging by your post to DigitalNZ list, you've already done the work.

Cheers,
Walter

Henry Maddocks

unread,
Jul 6, 2009, 5:28:18 AM7/6/09
to WellR...@googlegroups.com

On 6/07/2009, at 6:52 PM, Walter McGinnis wrote:

> MongoMapper has some similar goals like being ActiveRecord-like,
> although obviously aimed at MongoDB.

Thanks, I'll take a look.


> All this might be for not. Judging by your post to DigitalNZ list,
> you've already done the work.

I've just done the basics. I'm leaving the fancy pants stuff for
another day.

Henry


Reply all
Reply to author
Forward
0 new messages