Machine to machine with ActiveResource


#1

This is probably really obvious. But I can’t see it.

I have ActiveResource enabled client talking to RESTful server.
Instead of using link_to from the client to call the resource on the
server, I’d like to do this machine-to-machine, ie with no human
intervention.

What’s the link_to equivalent for the client to call the server
without human intervention?

As I say, I’m sure this is obvious … but not to me!


#2

On 5/8/07, jason removed_email_address@domain.invalid wrote:

As I say, I’m sure this is obvious … but not to me!

a cron job? Some kind of scheduler or work queue?


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com


#3

Hi
I’m probably not making myself clear. I just want to do this within
the code. Or is this not sensible?
So far as I understand many of the methods available on the server
through Rails (like column statistics sum, average) are not available
on the client. Instead the client just has access to xml from calling
the REST api.
I’d like to get the xml without ‘browsing’, i.e. let the code make the
call to the url and get the xml response. Or I could be barking up
the wrong tree completely.
Jason


#4

On 5/8/07, jason removed_email_address@domain.invalid wrote:

the wrong tree completely.
Jason

Well, if a human isn’t browsing to your site, you need an automated
script to do it, hence the suggestion to use cron or something
similar. Look at script/runner perhaps.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com


#5

Hi
This has been helpful, since it confirms I’m not missing anything
simple.
For those interested there is a fuller discussion of open-uri in Ruby
Cookbook by Carlson & Richardson, page 500.
thx
Jason


#6

jason wrote:

Jason

a cron job? Some kind of scheduler or work queue?


Rick O.http://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com

Try net::http or open-uri…

irb(main):001:0> require ‘open-uri’
=> true
irb(main):002:0> b = open(‘http://google.com’).read
=> “…etc”

this is a GET request to the given url and returns the response (in your
case the given url will return xml which can then be parsed with REXML,
Hash.from_xml(b), etc)

Hope this helps,
Gustav P.


#7

Hi
Personally, yes, I’m sticking with ActiveResource. This post for me
was about understanding where the edges are. I’d become used to
writing code in controller and views that accessed the models when I
needed them. Now I understand I’ve got to pull the data together more
fully on the server and also that this architecture has some
limitations in terms of using some of the sweetness of Rails.
Actually I like the boundaries, it’s just about understanding what
they are.
Jason


#8

ActiveResource is pretty durn simple.

Well, I struggled with it for a bit, but that was because I needed to
secure the connection with self-signed certs. Unfortunately,
ActiveResource does not expose it’s Net::HTTP object or offer delegate
setters for the cert, key, and ca_file properties, so I had to
monkey-patch it.

But that aside, you can use a one app’s ActiveRecord data in another app
simply by declaring a model of the same name which extends
ActiveResource::Base and provides the url of the other app.

b


#9

On 5/8/07, jason removed_email_address@domain.invalid wrote:

Hi
This has been helpful, since it confirms I’m not missing anything
simple.
For those interested there is a fuller discussion of open-uri in Ruby
Cookbook by Carlson & Richardson, page 500.
thx
Jason

Wouldn’t you just use activeresource instead of bothering with
open-uri or something like curl? That’s what it was written for.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com