Forum: Ruby on Rails Machine to machine with ActiveResource

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E5bfbdfee5d516a7537798be7f8c1274?d=identicon&s=25 jason (Guest)
on 2007-05-08 18:45
(Received via mailing list)
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!
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-05-08 18:48
(Received via mailing list)
On 5/8/07, jason <jason@opengrc.org> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
E5bfbdfee5d516a7537798be7f8c1274?d=identicon&s=25 jason (Guest)
on 2007-05-08 19:28
(Received via mailing list)
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
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-05-08 19:52
(Received via mailing list)
On 5/8/07, jason <jason@opengrc.org> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
19605c7ede229e507e894865308a6d53?d=identicon&s=25 Gustav Paul (Guest)
on 2007-05-08 20:35
(Received via mailing list)
jason wrote:
> Jason
>>>
>> a cron job?  Some kind of scheduler or work queue?
>>
>> --
>> Rick 
Olsonhttp://lighthouseapp.comhttp://weblog.techno-weeni...
>>
>
>
> >
>
>
Try net::http or open-uri...

irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> b = open('http://google.com').read
=> "<html><head>...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 Paul
E5bfbdfee5d516a7537798be7f8c1274?d=identicon&s=25 jason (Guest)
on 2007-05-08 23:55
(Received via mailing list)
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
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-05-08 23:57
(Received via mailing list)
On 5/8/07, jason <jason@opengrc.org> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
E5bfbdfee5d516a7537798be7f8c1274?d=identicon&s=25 jason (Guest)
on 2007-05-09 10:27
(Received via mailing list)
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
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-05-09 10:27
(Received via mailing list)
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
This topic is locked and can not be replied to.