Class: Cantook::SimulateASale

Inherits:
Base
  • Object
show all
Defined in:
lib/cantook/simulate_a_sale.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

#costObject

RESPONSE CODES Code Content Description 200 valid The simulation was executed successfully. 400 cannot_sell You cannot sell this publication. 400 missing_isbn You did not enter the ISBN. 400 missing_format You did not enter the format. 400 invalid_format The selected format is not available for this publication. 400 missing_cost You did not enter the price. 400 invalid_cost The price does not correspond to the price in the Platform. 400 missing_protection You did not enter the protection type. 400 invalid_protection This protection is not available for this format of the publication. 401 access_denied You do not have access to the resource. 404 not_found Your organization could not be found. 503 service_unavailable A problem has occured while connecting to the server.



34
35
36
# File 'lib/cantook/simulate_a_sale.rb', line 34

def cost
  @cost
end

#countryObject

RESPONSE CODES Code Content Description 200 valid The simulation was executed successfully. 400 cannot_sell You cannot sell this publication. 400 missing_isbn You did not enter the ISBN. 400 missing_format You did not enter the format. 400 invalid_format The selected format is not available for this publication. 400 missing_cost You did not enter the price. 400 invalid_cost The price does not correspond to the price in the Platform. 400 missing_protection You did not enter the protection type. 400 invalid_protection This protection is not available for this format of the publication. 401 access_denied You do not have access to the resource. 404 not_found Your organization could not be found. 503 service_unavailable A problem has occured while connecting to the server.



34
35
36
# File 'lib/cantook/simulate_a_sale.rb', line 34

def country
  @country
end

#protectionObject

RESPONSE CODES Code Content Description 200 valid The simulation was executed successfully. 400 cannot_sell You cannot sell this publication. 400 missing_isbn You did not enter the ISBN. 400 missing_format You did not enter the format. 400 invalid_format The selected format is not available for this publication. 400 missing_cost You did not enter the price. 400 invalid_cost The price does not correspond to the price in the Platform. 400 missing_protection You did not enter the protection type. 400 invalid_protection This protection is not available for this format of the publication. 401 access_denied You do not have access to the resource. 404 not_found Your organization could not be found. 503 service_unavailable A problem has occured while connecting to the server.



34
35
36
# File 'lib/cantook/simulate_a_sale.rb', line 34

def protection
  @protection
end

Instance Method Details

#request_urlString

Returns The full url required for this request.

Returns:

  • (String)

    The full url required for this request



62
63
64
# File 'lib/cantook/simulate_a_sale.rb', line 62

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

#simulate_a_sale(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’ } simulate_hash = { cost: ‘999’, protection: ‘acs4’, country: nil } cantook = Cantook::SimulateASale.new(base_hash) result = cantook.simulate_a_sale(simulate_hash)

Parameters:

  • params (Hash)

Options Hash (params):

  • :cost (Integer)
    • price in cents

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

  • :country (String)
    • eg ‘can’

Returns:

  • (True)

    if response code is 200

  • (False)

    if response code is not 200



47
48
49
50
51
52
53
# File 'lib/cantook/simulate_a_sale.rb', line 47

def simulate_a_sale(params)
  self.cost = params[:cost]
  self.protection = params[:protection]
  self.country = params[:country]
  do_request
  response.code == 200
end