# Machine to machine with ActiveResource

**URL:** <https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636>\
**Category:** Rails\
**Created:** [May 8, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636 "2007-05-08T18:45:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/1 "2007-05-08T18:45:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 6:48pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/2 "2007-05-08T18:48:15Z")

</div>

On 5/8/07, jason [removed\_email\_address@domain.invalid](mailto: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://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/3 "2007-05-08T19:28:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/4 "2007-05-08T19:52:28Z")

</div>

On 5/8/07, jason [removed\_email\_address@domain.invalid](mailto: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://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/5 "2007-05-08T23:55:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/6 "2007-05-08T20:35:36Z")

</div>

jason wrote:

> Jason
> 
> > > 
> > 
> > a cron job? Some kind of scheduler or work queue?
> > 
> > –  
> > Rick O.[http://lighthouseapp.comhttp](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](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.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 9, 2007, 10:27am UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/7 "2007-05-09T10:27:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 9, 2007, 10:27am UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/8 "2007-05-09T10:27:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 8, 2007, 11:57pm UTC](https://www.ruby-forum.com/t/machine-to-machine-with-activeresource/103636/9 "2007-05-08T23:57:08Z")

</div>

On 5/8/07, jason [removed\_email\_address@domain.invalid](mailto: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://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
