<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Moves On Rails: Tag ActiveResource</title>
    <link>http://www.movesonrails.com/articles/tag/activeresource?tag=activeresource</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>New ways to look at software</description>
    <item>
      <title>libxml-ruby and Windows</title>
      <description>&lt;p&gt;So, my first post on movesonrails.com! You might not know me, but I am one of the Nedap Healthcare developers. Usually I don't work on Moves or even with ruby on rails, but I needed some functionality...&lt;/p&gt;

&lt;p&gt;You might have seen a patch by Bart that allowed ActiveResource to be used with Libxml-ruby, with a dramatic performance increase. The downside was, you can't use libxml with Windows, limiting your applications to mac-os and linux. There was one build of libxml-ruby, which didn't really work, is an older version and missed some rather important files.&lt;/p&gt;

&lt;p&gt;But now you can use libxml-ruby in windows! Just unpack &lt;a href="http://www.movesonrails.com/files/libxml-ruby-0.5.2.0.zip"&gt;this zip&lt;/a&gt; into your ruby directory, rename ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xmlparser.so to xmlparser.s_ and you'll have libxml 0.5.2.0 !&lt;/p&gt;

&lt;p&gt;If you'd rather had libxml-ruby 0.3.8.4, you can download &lt;a href="http://www.movesonrails.com/files/libxml-ruby-0.3.8.4.zip"&gt;this zip&lt;/a&gt; instead, or even &lt;a href="http://www.movesonrails.com/files/libxml-ruby-windows.zip"&gt;0.5.1.0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To achieve this, I spent a morning compiling libxml with mingw. Just forget the following if you just want to use this, but for the sake of future version, this is what i had to do:&lt;/p&gt;

&lt;p&gt;1 . install mingw and MSYS in the standard directories (c:\mingw)&lt;/p&gt;

&lt;p&gt;2 . download the ruby source and compile, in a different directory than c:\ruby:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;&lt;pre&gt;./configure --with-prefix=c:/mingw/ruby
    make
    make install&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3 . download the zlib, iconv and libxml sources&lt;/p&gt;

&lt;p&gt;4 . compile all of them with :&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;&lt;pre&gt;./configure --with-prefix=c:/mingw
    make
    make install&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;5 . download libxml-ruby&lt;/p&gt;

&lt;p&gt;6 . now, the tricky part. You won't have rake (you didn't compile it) so we have to do a trick. Go to your libxml-ruby source directory and type:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;&lt;pre&gt;
    /c/mingw/ruby/bin/ruby ext/xml/extconf.rb
    make
    make install&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;7 . everything has been compiled. Just copy these files:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;&lt;pre&gt;
    to ruby\bin:
    c:\mingw\bin\iconv-2.dll
    c:\mingw\bin\libxml2-2.dll
    &lt;/pre&gt;&lt;/code&gt;
    &lt;code&gt;&lt;pre&gt;
    to ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml:
    C:\MinGW\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml\libxml_so.o
    &lt;/pre&gt;&lt;/code&gt;
    &lt;code&gt;&lt;pre&gt;
    to ruby\lib\ruby\site_ruby\1.8\xml
    C:\MinGW\ruby\lib\ruby\site_ruby\1.8\xml\libxml.rb
    &lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;have fun with a 20 times faster XML parser :)&lt;/p&gt;

&lt;h2&gt;update! versions 0.5.2.0 and 0.3.8.4 also available!&lt;/h2&gt;

&lt;p&gt;download &lt;a href="http://www.movesonrails.com/files/libxml-ruby-0.5.2.0.zip"&gt;0.5.2.0&lt;/a&gt; or &lt;a href="http://www.movesonrails.com/files/libxml-ruby-0.3.8.4.zip"&gt;0.3.8.4&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 09 Oct 2007 14:23:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:8d7a8e6e-c1a4-4e8e-821c-4e073b714236</guid>
      <author>pieter.bos@nedap.com (Pieter Bos)</author>
      <link>http://www.movesonrails.com/articles/2007/10/09/libxml-ruby-and-windows</link>
      <category>libxml</category>
      <category>compile</category>
      <category>win32</category>
      <category>windows</category>
      <category>ruby</category>
      <category>ActiveResource</category>
      <enclosure type="application/zip" length="2296262" url="http://www.movesonrails.com/files/libxml-ruby-0.5.2.0.zip"/>
    </item>
    <item>
      <title>ActiveResource: REST, WSDL, XSD?</title>
      <description>&lt;p&gt;We love REST. It's simple and clean, and combined with ActiveResource it is certainly the best app to app bridge we've worked with so far. But...&lt;/p&gt;

&lt;p&gt;What if you want to have more freedom? Say we want to build a database based on a REST webservice. Now imagine we don't want any info about the service in the ruby program that actually builds the db.&lt;/p&gt;

&lt;p&gt;We are facing two major problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We don't know which resources are available.&lt;/li&gt;
&lt;li&gt;We don't know the fields and types of the resource in advance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first problem will eventually be solved with WSDL 2.0 or if you need a solution right now: by a default listing resource. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
 # Our default object is called a Resource, on the server we have 
 # a Resource object that just returns each resource we have in 
 # a string array.
&lt;/pre&gt;&lt;/code&gt;
&lt;code&gt;&lt;pre&gt;
 resources = Resource.find(:all)
   =&gt; ["address","person","country"]
&lt;/pre&gt;&lt;/code&gt;
&lt;code&gt;&lt;pre&gt;
 # Now we can do all kinds of crazy stuff :)
 resources.each do |resource|
   name = resource.capitalize.to_sym
   new_resource = Object.const_set(name, Class.new(ActiveResource::Base))
   new_resource.site = Resource.site
 end
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this little piece of code we have a full dynamic set of ActiveResource classes ready to be used :)&lt;/p&gt;

&lt;p&gt;The second problem we face is much more interesting. Normally some kind of resource definition would be applied like XSD. But native ruby XSD support is kind of lacking (it sucks) and more importantly it doesn't feel like a rails solution.&lt;/p&gt;

&lt;p&gt;We wanted a cleaner, simpler and more elegant (more RESTy) solution. How about &lt;code&gt;Person.schema&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;It returns an ActiveResourceSchema object:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
Person.schema.fields
   =&gt; { :name =&gt; FixNum, :date_of_birth =&gt; DateTime, 
:parents =&gt; [{ :id =&gt; FixNum }] }
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What happens is actually quite simple. When the Resource objects receives the schema method call it calls find(:first,  :params =&gt; { :schema =&gt; true }).&lt;/p&gt;

&lt;p&gt;The server responds to this param with a sample record, with just the field names and types. We build an ActiveResourceSchema object to wrap those and return a nice array of fields :)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; These code snippets are just examples, we are currently building this. If there's enough interest we might submit it as a plugin/patch for ARes.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 15:57:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:5ff4b915-4fc7-4012-b445-707df57b1a1d</guid>
      <author>andre.foeken@movesonrails.com (Andre Foeken)</author>
      <link>http://www.movesonrails.com/articles/2007/09/24/rest-wsdl-xsd</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>ActiveResource</category>
      <category>wdsl</category>
      <category>xsd</category>
      <category>REST</category>
      <category>XML</category>
    </item>
    <item>
      <title>Speeding up Active Resource</title>
      <description>&lt;p&gt;As I was trying to import 12 MB of XML, it quickly became very clear that the SimpleXML used in Hash.from_xml was not going to cut it. It took nearly four minutes to convert the xml data to a hash! &lt;/p&gt;

&lt;p&gt;As Active Resource will probably be used to handle large xml files, I created a patch so that libxml is used to parse the xml. This made fetching the active resource go from 240 seconds to 12 seconds. That 20 times faster!&lt;/p&gt;

&lt;p&gt;The net override (also included) makes downloading a factor four faster.&lt;/p&gt;

&lt;p&gt;Find the patch here:
&lt;a href="http://dev.rubyonrails.org/ticket/9017"&gt;http://dev.rubyonrails.org/ticket/9017&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 19 Jul 2007 10:18:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:df8ad3e4-304c-4101-b930-a5a9219abce3</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2007/07/19/speeding-up-active-resource</link>
      <category>Rails</category>
      <category>ruby</category>
      <category>libxml</category>
      <category>ActiveResource</category>
      <category>slow</category>
      <category>hash</category>
      <category>from_xml</category>
    </item>
    <item>
      <title>Testing a REST full activeresource</title>
      <description>&lt;p&gt;Active Resources are nice, nut when you're trying to test your active resources , you're in for a long night. Luckally someone did a lot of the basic work for us. The HTTPMock class in ActiveResource is a very handy tool for testing your active resources. Unfortunately there is absolutely no documentation about how to use it, and it has some behaviour you might not expect. Therefore I present you with this code example.&lt;/p&gt;

&lt;p&gt;The remote models of our REST connection live in Connections::IO::REST. When requesting the Employees via Connections::IO::REST::Employee.find(:all), we are actually requesting /employees.xml from our HTTPMock class. The HTTPMock class then just outputs the XML file of the testset we got from our friend which wrote the REST-connector we are connecting to. In the example, this is: /test/remote_fixtures/connector/employees.xml&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; class IORestConnectionTest &amp;lt; Test::Unit::TestCase

 def setup
   @pre      = Connections::IO::REST
   @mock_url = 'http://localhost/'
   @headers  = {"User-Agent"=&amp;gt;"Moves", "Accept-Encoding"=&amp;gt;"deflate", "Content-Type"=&amp;gt;"application/xml"}
   ActiveResource::HttpMock.respond_to do |mock|
     mock.get "/employees.xml", @headers, ioconnect_resources('employees')
     mock.get "/clients.xml"  , @headers, ioconnect_resources('clients')
   end

   # Overwrite all site URLS
   @pre::Resource.site = @mock_url
 end

 def ioconnect_resources(name)
   path = File.join(RAILS_ROOT, "test", "remote_fixtures", "ioconnect", "#{name.to_s}.xml")
   return nil unless File.exists?(path)
   File.read path
 end

 def teardown
     ActiveResource::HttpMock.reset!
 end

 def test_should_find_all_employees_via_rest
   employees = @pre:Employee.find(:all)
   assert_equal employees.count, 20
 end

 end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;One last note: HTTPMock was created to be as simple as possible. If you request  something with a different header or parameters in the URL, it will return absolutely nothing. So if you get no response from your mock activeresource, be sure to check the headers you sent.&lt;/p&gt;</description>
      <pubDate>Wed, 04 Jul 2007 15:38:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:b7187f5b-d67e-45aa-b365-e5ad650a2957</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2007/07/04/testing-a-rest-full-activeresource</link>
      <category>Rails</category>
      <category>REST</category>
      <category>Resource</category>
      <category>ActiveResource</category>
      <category>Test</category>
      <category>HTTPMock</category>
    </item>
    <item>
      <title>SOAP hell? ARes Heaven?</title>
      <description>&lt;p&gt;Linking Ruby to Ruby was no problem. Even Java to Ruby seemed to work just fine. But the problems started as we grew past the infant stage and tried to send more that say a thousand records over the SOAPy connection.&lt;/p&gt;

&lt;p&gt;The amount of XML was just to big to handle, the speed became unacceptable. Our first instinct was Gzipping the files, but that made almost no difference. Finally we tried SWA, SOAP with Attachments. SWA worked flawlessly...in Java...and in Ruby. Just not together. We tried everything but no luck.&lt;/p&gt;

&lt;p&gt;Finally we decided we needed a fresh start, we threw the SOAP away (with the bathwater) and took a look at ActiveResource (Ruby) and RESTLets (Java).&lt;/p&gt;

&lt;p&gt;ARes is wonderful, it worked (&lt;em&gt;almost&lt;/em&gt;) out of the box and there was a lot less overhead. Combined with Zlib::Deflate this proved to be a good alternative. Sure it still doesn't win any speed races, but it is functional, easy to set up and simple to maintain.&lt;/p&gt;

&lt;p&gt;The definition of almost:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.rubyonrails.org/ticket/8563"&gt;Ticket 8563&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.rubyonrails.org/ticket/8566"&gt;Ticket 8566&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.rubyonrails.org/ticket/8567"&gt;Ticket 8567&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.rubyonrails.org/ticket/8568"&gt;Ticket 8568&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 04 Jun 2007 18:43:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:76526da6-2500-48e5-98d1-506ad6bd9f24</guid>
      <author>andre.foeken@movesonrails.com (Andre Foeken)</author>
      <link>http://www.movesonrails.com/articles/2007/06/04/soap-hell-ares-heaven</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>soap</category>
      <category>ActiveResource</category>
      <category>XML</category>
      <category>RESTLet</category>
    </item>
  </channel>
</rss>
