title: Cantook gem
date: 2014-05-07
I’ve done a number of projects for book publishers in recent years, and on a few occasions have needed to take a look at integration with the Cantook digital distribution platform.
In my experience, Cantook has a very good, easily understood API , and it seemed there was no gem in existence dedicated to integrating Cantook in a Ruby on Rails application, so I created one.
Installation
Add this line to your application’s Gemfile:
gem 'cantook'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cantook
Usage
Simulate a sale
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state: 'test', format: 'epub', isbn: '123456789asdf' }
simulate_hash = { cost: '999', protection: 'acs4', country: nil }
cantook = Cantook::SimulateASale.new(base_hash)
if cantook.simulate_a_sale(simulate_hash)
puts "success"
else
puts "failure"
end
Sale of a publication
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state 'test', format: 'epub', isbn: '123456789asdf' }
sale_hash = { cost: '999', customer_id: '123', transaction_id: 'abc', protection: 'acs4' }
cantook = Cantook::SaleOfAPublication.new(base_hash)
if cantook.sale_of_a_publication(sale_hash)
puts "success"
else
puts "failure"
end
Download a publication
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state: 'test', format: 'epub', isbn: '123456789asdf' }
download_hash = { customer_id: '123', transaction_id: 'abc', uname: 'Foo Bar' }
cantook = Cantook::DownloadAPublication.new(base_hash)
download_link = cantook.download_a_publication(download_hash)
redirect_to download_link
Contributing
- Fork it
- Create your feature branch (‘git checkout -b my-new-feature’)
- Commit your changes (‘git commit -am 'Add some feature’‘)
- Push to the branch ('git push origin my-new-feature’)
- Create new Pull Request
https://github.com/gordonbisnor/cantook
I am available for Ruby on Rails consulting work and have worked with done a great deal of work with book publishers and companies that support them – get in touch to learn more.