yieldmanager
This gem offers full access to YieldManager’s API tools (read/write) and (eventually) ad-hoc reporting through the Reportware tool.
Currently it generates a fresh wsdl from the api.yieldmanager.com site the first time you use a service (in the future it will use locally-cached copies) and re-uses that wsdl for the life of the Yieldmanager::Client object.
Installation
Yieldmanager is available as a gem on gemcutter.org.
sudo gem install yieldmanager
The project is available for review/forking on github.com
git clone git://github.com/billgathen/yieldmanager.git
To use in a Rails project, add this to config/environment.rb:
config.gem ‘yieldmanager’
Creating a Yieldmanager::Client
@ym = Yieldmanager::Client.new( :user => “bob”, :pass => “secret”, :api_version => “1.30” )
Finding available services
@ym.available_services
Using a service
@ym.session do |token| currencies = @ym.dictionary.getCurrencies(token) end
Pagination
Some calls return datasets too large to retrieve all at once. Pagination allows you to pull them back incrementally, handling the partial dataset on-the-fly or accumulating it for later use.
BLOCK_SIZE = 50 id = 1 @ym.session do |token| @ym.paginate(BLOCK_SIZE) do |block| (lines,tot) = @ym.line_item.getByBuyer(token,id,BLOCK_SIZE,block) # …do something with lines… tot # remember to return total! end end
session vs. start_session/end_session
The session
method opens a session, gives you a token to use in your service calls, then closes the session when the block ends, even if an exception is raised during processing. It’s the recommended method to ensure you don’t hang connections when things go wrong. If you use start/end, make sure you wrap your logic in a begin/ensure clause and call end_session from the ensure.
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2009 Bill Gathen. See LICENSE for details.