Class: Cantook::DownloadAPublication

Inherits:
Base
  • Object
show all
Defined in:
lib/cantook/download_a_publication.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#auth, #base_url, #currency, #format, #isbn, #organisation_id, #password, #platform, #query, #response, #sale_state, #username

Instance Method Summary collapse

Methods inherited from Base

#initialize, #response_code, #response_hash

Constructor Details

This class inherits a constructor from Cantook::Base

Instance Attribute Details

#customer_idObject

RESPONSE CODES Code Content Description 200 url Chronodegradable download URL (expires after 1 minute). Redirect user toward this URL. 400 missing_transaction_id You did not enter a transaction ID. 401 access_denied You do not have access to the resource. 404 not_found Your organisation could not be found.



25
26
27
# File 'lib/cantook/download_a_publication.rb', line 25

def customer_id
  @customer_id
end

#transaction_idObject

RESPONSE CODES Code Content Description 200 url Chronodegradable download URL (expires after 1 minute). Redirect user toward this URL. 400 missing_transaction_id You did not enter a transaction ID. 401 access_denied You do not have access to the resource. 404 not_found Your organisation could not be found.



25
26
27
# File 'lib/cantook/download_a_publication.rb', line 25

def transaction_id
  @transaction_id
end

#unameObject

RESPONSE CODES Code Content Description 200 url Chronodegradable download URL (expires after 1 minute). Redirect user toward this URL. 400 missing_transaction_id You did not enter a transaction ID. 401 access_denied You do not have access to the resource. 404 not_found Your organisation could not be found.



25
26
27
# File 'lib/cantook/download_a_publication.rb', line 25

def uname
  @uname
end

Instance Method Details

#download_a_publication(params) ⇒ String

Example: base_hash = { username: Settings.cantook.username, password: Settings.cantook.password, platform: Settings.cantook.platform, organisation_id: Settings.cantook.organisation_id, sale_state: Settings.cantook.sale_state, 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

Parameters:

  • params (Hash)

Options Hash (params):

  • :customer_id (String)
    • your customer’s unique ID

  • :transaction_id (String)
    • the orders unique ID

  • :uname (String)
    • Your customer’s first and last name, for the watermark

Returns:

  • (String)

    If successful, returns the download link



39
40
41
42
43
44
45
# File 'lib/cantook/download_a_publication.rb', line 39

def download_a_publication(params)
	self.customer_id = params[:customer_id]
	self.transaction_id = params[:transaction_id]
	self.uname = params[:uname]
	do_request
	response.parsed_response
end

#request_urlString

Returns The full url required for this request.

Returns:

  • (String)

    The full url required for this request



54
55
56
# File 'lib/cantook/download_a_publication.rb', line 54

def request_url
	base_url + "/customers/#{customer_id}/transactions/#{transaction_id}/publications/#{isbn}/download_links/#{format}"
end