Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

May 7, 2014


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

  1. Fork it
  2. Create your feature branch (‘git checkout -b my-new-feature’)
  3. Commit your changes (‘git commit -am 'Add some feature’‘)
  4. Push to the branch ('git push origin my-new-feature’)
  5. 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.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus