Class: Cantook::SaleOfAPublication

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

Instance Attribute Summary collapse

Attributes inherited from Base

#auth, #base_url, #currency, #format, #isbn, #organisation_id, #password, #platform, #query, #response, #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

#aggregatorObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def aggregator
  @aggregator
end

#costObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def cost
  @cost
end

#countryObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def country
  @country
end

#credit_card_prefixObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def credit_card_prefix
  @credit_card_prefix
end

#customer_idObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def customer_id
  @customer_id
end

#protectionObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def protection
  @protection
end

#sale_stateObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def sale_state
  @sale_state
end

#transaction_idObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def transaction_id
  @transaction_id
end

#unameObject

TEST BOOKS Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”) Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”) Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)



49
50
51
# File 'lib/cantook/sale_of_a_publication.rb', line 49

def uname
  @uname
end

Instance Method Details

#request_urlString

Returns The full url required for this request.

Returns:

  • (String)

    The full url required for this request



92
93
94
# File 'lib/cantook/sale_of_a_publication.rb', line 92

def request_url
  base_url + "/publications/#{isbn}/sales"
end

#sale_of_a_publication(params) ⇒ True, False

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’ } 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 "mais oui"

else

puts "mais non"

end

Parameters:

  • params (Hash)

Options Hash (params):

  • :cost (Integer)
    • price in cents

  • :protection (String)
    • the file’s DRM protection eg ‘acs4’

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

  • :transaction_id (String)
    • the order’s unique ID

Returns:

  • (True)

    if response code is 201

  • (False)

    if resopnse code is anything other than 201



76
77
78
79
80
81
82
83
# File 'lib/cantook/sale_of_a_publication.rb', line 76

def sale_of_a_publication(params)
  self.cost = params[:cost]
  self.protection = params[:protection]
  self.customer_id = params[:customer_id]
  self.transaction_id = params[:transaction_id]
  do_request
  response.code == 201
end