Pushrod

Old dogs, new tricks

Posts Tagged ‘gems

ebay_shopping is now a gem (and now at github)

with 16 comments

OK. I’ve jumped on the Git bandwagon, and to celebrate have made the ebay_shopping plugin (a ruby on rails library for eBay’s shopping API) into a gem, hosted at Github. It’ll take a few days before the rubyforge project is approved and loaded up, but you can still download it from github, or with a github clone.

Why turn it into a gem? Well, it was originally a plugin as that was the easiest and quickest way to do it at the time — it was generated from a Rails application, after all. It also made things like getting the initial config (from a YAML file in the Rails config directory) a no-brainer, and meant I could use some of the ActiveSupport methods without thinking.

But over the past few weeks, I’ve been playing around with Merb, and decided these benefits are more than outweighed by the greater portability a gem brings. There’s also the benefit of versioning and dependencies. Finally, with Rails edging away from plugins with 2.1, and the ease of gem generation using Dr Nic’s newgem gem, there’s really no reason to stay with the plugin approach. Enter, stage left, the ebay_shopping gem.

If you’re already using the plugin, there’s no hurry to change. If not, give the gem a try and let me know how it goes. Use is almost identical to the plugin. The only difference is with the initial configuration. You can still use the same YAML config file in your Rails config folder (if you’re using Rails or Merb), you just need to set it up explictly in your environment.rb

EbayShopping::Request.config_params("#{RAILS_ROOT}/config/ebay.yml", RAILS_ENV)

Passing the RAILS_ENV as the second param just ensures it will use the correct environment settings from the config file, if you’ve got different ones for development, production, test, etc. If not, or if you don’t tell it, it will just default to the production settings.

You can also (from the console, for example), set the inital configuration with a Hash

EbayShopping::Request.config_params({:app_id => "my_app_id", :default_site_id =>"3"})

The hash must provide the app_id you’re given by ebay, and can optionally provide the ebay affiliate info and your preferred default country (e.g. the UK in the above one). This can be overridden in individual requests, or if you just leave it out it will default to ebay.com.

Enough waffle. Explore the code over at github. The documentation still needs tweaking, but the test suite and code comments should explain it all fairly well. Plus there are some use examples on the post about the original plugin, which still stand. Patches and forks welcome — this is git after all we’re talking about.

Update:

Finally gotten around to adding the gemspec file which allows github to build the gem automatically. So now all you need to do  is the usual:

gem sources -a http://gems.github.com

sudo gem install ctagg-ebay_shopping

Advertisements

Written by ctagg

May 13, 2008 at 4:54 pm

Posted in ebay, rails, ruby

Tagged with , , , ,