Ruby support for XML namespaces - ruby

I work at a small company and our production system uses a hand-rolled RESTful API, implemented in Java with JAXB. We now find that we're taking on customers who use Ruby on Rails, and I have to come up with a reference implementation to show customers how to use our API in Ruby. I'd love to be able to just tell them to use ActiveResource, but the XML required by our API uses (and absolutely requires) namespaces. Unfortunately, we've already got a number of other customers who've already integrated this API, so removing the usage of namespaces is out of the question. What's the best way to generate XML with namespaces in Ruby ?

"Best" obviously depends on your needs.
The fastest way to generate any XML in ruby is to use libxml-ruby - link to rdoc.
If your server gets any kind of load at all, this will be the way to go.
The easiest way to generate any XML in ruby is to use REXML as it's part of the standard library and therefore it "just works". If your XML generation is something that hardly ever gets used, it's probably easier to just go with rexml.
Both support XML namespaces - check the rdocs to find out how to set and get namespaces

I find myself in almost an identical situation as yours (RESTful API done with JAXB w/ namespaces).
I think the most promising project for working with XML in Ruby is HappyMapper. It is a kind of XML binding library (along the lines of an early JAXB-type implementation). It has been gaining a lot of traction recently, and a few of us have been working on providing good namespace support.
The project resides here:
http://happymapper.rubyforge.org/
with the source here:
http://github.com/jnunemaker/happymapper/tree/master
The project currently doesn't support creation of XML from Ruby Objects, and the original author has expressed no desire to provide that support, but I'll be committing some functionality for that in my fork:
http://github.com/jimmyz/happymapper/tree/master
Hope this helps.
--
Jimmy Zimmerman

Related

Why dataweave over template engines like Velocity/Freemarker/Thymeleaf

I see a broad adoption of Dataweave which I feel is more of transformation library just like Freemarker or Velocity.
In case of DW Change in transformation logic would need change in code, the very same purpose template engines got popular at the first place to seperate logic and code so that we can change transformation logic without needing to rebuild/repackage our code (more deployment hassle).
Can anyone help me to point out few reasons as to why one would prefer DW .
TLDR: If you're looking for a template engine for things like static websites, DataWeave definitely isn't the right choice. Use the right tool for the job. Also, while you can use DataWeave outside of Mule, I don't think I've seen anyone adopt DataWeave that hasn't adopted MuleSoft..
A few things to consider (and most of these I'm stating in the context of developing Mule applications):
These template engines are, typically, for outputting static text. If you're using it to output structured data rather than something like an HTML page.. you're probably doing it wrong. They aren't going to return structured data - they are going to return text. If you're at the very end of your flow and you're going to output that back out of the API or to a file, you're fine I suppose.. but if you want to actually be able to work with that output, you're going to have to convert the plain text to an actual object... introducing a lot of extra steps in this process when you could have just used DataWeave in the first place. Dataweave is especially beneficial when you want to do things like streaming because you're processing large payloads. Dataweave can understand JSON, XML, and CSV (the three most common data types I see) in a streamed format without any additional work, making it very easy to create efficient applications. The big difference between a template engine and a data transformation language is that one is for outputting text using structured data as input, and the other is for working with structured data on the input and outputting structured data that you can continue to work with. There is a reason that almost all of the template engine docs talk about building websites and not things like integrations.
The DataWeave engine is, as Aled indicated, built into the Mule runtime. Deeply so. You can use DataWeave in any field in any connector by default, even fields that don't have the f(x) button - because it's built into the runtime. This makes DataWeave what you could consider a first-class citizen within Mule, unlike something you will only be able to utilize either via connectors or by invoking java bridges/libraries.. which you do via DataWeave or a long series of connector operations.
The benefits you listed are also not things you can't do with DataWeave. You can VERY easily templatize and externalize DataWeave - for example, I have several DataWeave libraries in my maven repo I can include as dependencies. I've built several transformation services that use databases with DataWeave in order to do transformation, allowing me to change those transformations without modifying the app. You can also use dynamic DataWeave, where you use a template system to load specific parts of the script before running it. I've even taken it a step further and written a generic DataWeave script that I can use to do basic mappings without writing DataWeave - this allowed me to wrap a web UI around things pretty easily.
I wouldn't use DataWeave outside of MuleSoft unless you're a MuleSoft shop. If you are a MuleSoft shop, using the CLI to run your scripts, the same way you do with most interpreted languages, works fairly nicely - especially since you likely already have in-house expertise in DataWeave. The language is still niche enough that unless you've already adopted it for use in Mule applications I don't see any advantage in using it.
Docs / basic examples:
https://github.com/mulesoft-labs/data-weave-native
https://docs.mulesoft.com/mule-runtime/4.3/parse-template-reference
https://docs.mulesoft.com/mule-runtime/4.3/dataweave-create-module
https://github.com/mikeacjones/transform-system-api
Because it is the expression and transformation language embedded in Mule runtime. If you are using Mule it is also integrated with the IDE Anypoint Studio.
Outside Mule applications I don't think you can use DataWeave easily. You might want to go with the alternatives.

Caching objects locally for reuse (Parse.com / Backbone)

Currently using a setup that follows: Backbone, Parse, Require, and Marionette.
I've found through my application that I often need to reuse objects I've already pulled down from Parse.
Parse already does this through Parse.User.current(), However it would be great to store other entities locally rather than retrieving them over and over again.
Does anyone have any suggestions in terms of good practices or libraries to use for caching these objects locally or would having global variables that hold the information while the application runs be enough?
The Parse JavaScript SDK is open source, so you could look at the implementation of Parse.User.current and Parse.User._saveCurrentUser. Maybe you could do something similar. http://www.parsecdn.com/js/parse-1.1.11.js

data driven development framework with Ruby

Does anybody know a good data driven development framework/library/gem for Ruby? I know a ton for Rails but I couldn't find anything for Ruby itself. I have a standalone Ruby app and I want to generate test data and write test cases for different data sets. I don't want to use fixtures. Any suggestions?
You mean something like machinist? The readme mentions it can work without Rails.

Ruby Torrent Library

Is there any good library for Ruby to work with BitTorrent trackers? To download or seed files. There's a rubytorrent library on rubyforge, but it was last updated in 2005 and doesn't seem like working anymore.
see lib-torrent ruby...
https://github.com/maran/libtorrent-ruby
I'm not sure if this is what you want.
Also see this post which contains some potentially useful comments as well, including a Ruby wrapper for the Transmission API using RPCs.
My experience with libtorrent derived clients has been very positive, I would like to see something new here. (I prefer the high density interface & advanced features of qbittorrent to the sparse UI of Transmission.)
A torrent client that exchanges DHT buckets to crawl the public DHT... ?
(No web searching required.)

Tools for development SOAP-service on Ruby 1.9

Which set of libraries and tools would you recommend to use for development SOAP-service on Ruby 1.9 - soap-tools, web-servers, or maybe a web-framework?
I have researched this myself. As far as I can tell, there is just one current implementation:
wash_out
It is a very nice to do SOAP in Rails. It does the most basic stuff but it isn't a complete SOAP implementation. I think you are in for a world of hurt if you are building a SOAP service on Rails.
Soap Ui is a pretty good way to test/debug/etc.
Good luck!
Take a look at http://aws.rubyonrails.org/, when it's explained how to create web services within RubyOnRails.
SOAP doesn't seem to be popular in Ruby land. The only library for creating services I know of is SOAP4R (which comes bundled with Ruby), and the documentation for it isn't very detailed.

Resources