cantook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/cantook.gemspec +24 -0
- data/lib/cantook/base.rb +77 -0
- data/lib/cantook/download_a_publication.rb +67 -0
- data/lib/cantook/sale_of_a_publication.rb +114 -0
- data/lib/cantook/simulate_a_sale.rb +74 -0
- data/lib/cantook.rb +7 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d244a7cbf9c6ff39604a67e2e42345eb16937b4f
|
4
|
+
data.tar.gz: 4b0daa97abbcacd2d4bfc8b76e27ec719f0edb8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab5364abb5bc5a740adbbdba2dea562f3d1a3f04e531b4c046ffae94bc84246676d7916ebc35fa8fdc1a822964314f37fd78f202ead14220a74498b6c6c633b6
|
7
|
+
data.tar.gz: a9b62062f55b20e4ce0c8d14be435d56f13c2e9e572393dbf49f852ba955079f3c9e2c1495af58538a0106d02699b72e3bc56f219db04852fc339dd7990f41fb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Gordon B. Isnor
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Cantook
|
2
|
+
|
3
|
+
Facilitates Ruby and Ruby on Rails interaction with the Cantook API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cantook'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cantook
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Simulate a sale
|
22
|
+
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state: 'test', format: 'epub', isbn: '123456789asdf' }
|
23
|
+
simulate_hash = { cost: '999', protection: 'acs4', country: nil }
|
24
|
+
cantook = Cantook::SimulateASale.new(base_hash)
|
25
|
+
|
26
|
+
if cantook.simulate_a_sale(simulate_hash)
|
27
|
+
puts "success"
|
28
|
+
else
|
29
|
+
puts "failure"
|
30
|
+
end
|
31
|
+
|
32
|
+
### Sale of a publication
|
33
|
+
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state 'test', format: 'epub', isbn: '123456789asdf' }
|
34
|
+
sale_hash = { cost: '999', customer_id: '123', transaction_id: 'abc', protection: 'acs4' }
|
35
|
+
cantook = Cantook::SaleOfAPublication.new(base_hash)
|
36
|
+
|
37
|
+
if cantook.sale_of_a_publication(sale_hash)
|
38
|
+
puts "success"
|
39
|
+
else
|
40
|
+
puts "failure"
|
41
|
+
end
|
42
|
+
|
43
|
+
### Download a publication
|
44
|
+
base_hash = { username: 'foo', password: 'bar', platform: 'www.cantook.net', organisation_id: 123, sale_state: 'test', format: 'epub', isbn: '123456789asdf' }
|
45
|
+
download_hash = { customer_id: '123', transaction_id: 'abc', uname: 'Foo Bar' }
|
46
|
+
cantook = Cantook::DownloadAPublication.new(base_hash)
|
47
|
+
download_link = cantook.download_a_publication(download_hash)
|
48
|
+
redirect_to download_link
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/cantook.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cantook"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Gordon B. Isnor"]
|
9
|
+
spec.email = ["gordonbisnor@gmail.com"]
|
10
|
+
spec.description = %q{Cantook gem}
|
11
|
+
spec.summary = %q{Facilitates Ruby and Ruby on Rails interactions with the Cantook API}
|
12
|
+
spec.homepage = "http://www.github.com/gordonbisnor/cantook"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency('httparty')
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/lib/cantook/base.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Base class sets up common functionality for other classes to inherit behavior from
|
3
|
+
#
|
4
|
+
# @author Gordon B. Isnor
|
5
|
+
#
|
6
|
+
module Cantook
|
7
|
+
|
8
|
+
class Base
|
9
|
+
|
10
|
+
# Name Mandatory Description
|
11
|
+
# platform Yes The platform that you're using to connect to your account. For example : www.entrepotnumerique.com, www.edenlivres.fr, edigita.cantook.net or transcontinental.cantook.net.
|
12
|
+
# organisation_id Yes Your merchant number. This number is provided upon registration.
|
13
|
+
# isbn Yes The publication's ISBN.
|
14
|
+
# format Yes The publication's format (pdf/epub/mobi).
|
15
|
+
|
16
|
+
attr_accessor :base_url,
|
17
|
+
:auth,
|
18
|
+
:username,
|
19
|
+
:password,
|
20
|
+
:platform,
|
21
|
+
:organisation_id,
|
22
|
+
:isbn,
|
23
|
+
:format,
|
24
|
+
:response,
|
25
|
+
:sale_state
|
26
|
+
|
27
|
+
# @param [Hash] params
|
28
|
+
# @option params [String] :username - your Cantook API username
|
29
|
+
# @option params [String] :username - your Cantook API password
|
30
|
+
# @option params [String] :platform - your Cantook platform eg 'www.cantook.net'
|
31
|
+
# @option params [String] :organisation_id - your Cantook organisation ID number
|
32
|
+
# @option params [String] :isbn - ISBN of the publication you are selling
|
33
|
+
# @option params [String] :format - format of the publication being sold, eg 'epub' or 'mobi'
|
34
|
+
# @option params [String] :sale_state - use 'test' for test/development, nil for production (real sales)
|
35
|
+
def initialize(params = {})
|
36
|
+
@username = params[:username]
|
37
|
+
@password = params[:password]
|
38
|
+
@platform = params[:platform]
|
39
|
+
@organisation_id = params[:organisation_id]
|
40
|
+
@isbn = params[:isbn]
|
41
|
+
@format = params[:format]
|
42
|
+
@sale_state = params[:sale_state]
|
43
|
+
@base_url = "https://#{platform}/api/organisations/#{organisation_id}"
|
44
|
+
@auth = { username: username, password: password }
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Hash] A basic hash of options common to all Cantook requests
|
48
|
+
def base_options
|
49
|
+
{ format: format, isbn: isbn, sale_state: sale_state }
|
50
|
+
end
|
51
|
+
private :base_options
|
52
|
+
|
53
|
+
# @param [Hash] options
|
54
|
+
def get_request options
|
55
|
+
HTTParty.get(request_url, query: options.merge(base_options), basic_auth: auth)
|
56
|
+
end
|
57
|
+
private :get_request
|
58
|
+
|
59
|
+
# @param [Hash] options
|
60
|
+
def post_request options
|
61
|
+
HTTParty.post(request_url, query: options.merge(base_options), basic_auth: auth)
|
62
|
+
end
|
63
|
+
private :post_request
|
64
|
+
|
65
|
+
# @return [Fixnum] the response code of the Cantook request
|
66
|
+
def response_code
|
67
|
+
response.code
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Hash] The response hash, with symbolized keys
|
71
|
+
def response_hash
|
72
|
+
response.parsed_response.deep_symbolize_keys!
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Provides a download link that customer should be redirected to
|
3
|
+
#
|
4
|
+
# @author Gordon B. Isnor
|
5
|
+
#
|
6
|
+
module Cantook
|
7
|
+
class DownloadAPublication < Cantook::Base
|
8
|
+
|
9
|
+
# https://[platform]/api/organisations/[organisation_id]/customers/[customer_id] /transactions/[transaction_id]/publications/[isbn]/download_links/[format]
|
10
|
+
|
11
|
+
# GET REQUEST
|
12
|
+
|
13
|
+
# PARAMETERS
|
14
|
+
# customer_id Yes The client's unique ID number. Alphanumerical characters ("-" and "_" accepted).
|
15
|
+
# transaction_id Yes The transaction / purchase basket's unique ID number.
|
16
|
+
# uname Yes First and last name of the user. The value of this parameter will appear in the text of the digital watermark that will be placed on the file.
|
17
|
+
|
18
|
+
# RESPONSE CODES
|
19
|
+
# Code Content Description
|
20
|
+
# 200 url Chronodegradable download URL (expires after 1 minute). Redirect user toward this URL.
|
21
|
+
# 400 missing_transaction_id You did not enter a transaction ID.
|
22
|
+
# 401 access_denied You do not have access to the resource.
|
23
|
+
# 404 not_found Your organisation could not be found.
|
24
|
+
|
25
|
+
attr_accessor :customer_id, :transaction_id, :uname
|
26
|
+
|
27
|
+
# Example:
|
28
|
+
# 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' }
|
29
|
+
# download_hash = { customer_id: '123', transaction_id: 'abc', uname: 'Foo Bar' }
|
30
|
+
# cantook = Cantook::DownloadAPublication.new(base_hash)
|
31
|
+
# download_link = cantook.download_a_publication(download_hash)
|
32
|
+
# redirect_to download_link
|
33
|
+
#
|
34
|
+
# @param [Hash] params
|
35
|
+
# @option params [String] :customer_id - your customer’s unique ID
|
36
|
+
# @option params [String] :transaction_id - the orders unique ID
|
37
|
+
# @option params [String] :uname - Your customer’s first and last name, for the watermark
|
38
|
+
# @return [String] If successful, returns the download link
|
39
|
+
def download_a_publication(params)
|
40
|
+
self.customer_id = params[:customer_id]
|
41
|
+
self.transaction_id = params[:transaction_id]
|
42
|
+
self.uname = params[:uname]
|
43
|
+
do_request
|
44
|
+
response.parsed_response
|
45
|
+
end
|
46
|
+
|
47
|
+
# sets and returns the response
|
48
|
+
def do_request
|
49
|
+
self.response = get_request(options)
|
50
|
+
end
|
51
|
+
private :do_request
|
52
|
+
|
53
|
+
# @return [String] The full url required for this request
|
54
|
+
def request_url
|
55
|
+
base_url + "/customers/#{customer_id}/transactions/#{transaction_id}/publications/#{isbn}/download_links/#{format}"
|
56
|
+
end
|
57
|
+
private :request_url
|
58
|
+
|
59
|
+
# @return [Hash] required parameters not included in the Cantook::Base base_options hash
|
60
|
+
def options
|
61
|
+
{ customer_id: customer_id, transaction_id: transaction_id, uname: uname }
|
62
|
+
end
|
63
|
+
private :options
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# Notifies Cantook of sale
|
3
|
+
#
|
4
|
+
# @author Gordon B. Isnor
|
5
|
+
#
|
6
|
+
module Cantook
|
7
|
+
class SaleOfAPublication < Cantook::Base
|
8
|
+
|
9
|
+
# https://[platform]/api/organisations/[organisation_id]/publications/[isbn]/sales
|
10
|
+
|
11
|
+
# POST REQUEST
|
12
|
+
|
13
|
+
# PARAMETERS
|
14
|
+
# Name Mandatory Description
|
15
|
+
# cost Yes The price of the sale in cents (e.g., $19.99 => 1999).
|
16
|
+
# protection Yes The type of protection on the sold publication (none/watermark/acs4/acs4_time_limited).
|
17
|
+
# customer_id Yes Your client's unique ID number. Alphanumerical characters only ("-" and "_" also accepted).
|
18
|
+
# transaction_id Yes The transaction / purchase basket's unique ID number. Multiple sales can be added to a basket, as long as they have the same unique ID number and are related to a single user. Alphanumerical characters only ("-" and "_" also accepted).
|
19
|
+
# credit_card_prefix No 4 first numbers of the credit card number used for payment. It allows the publisher to check if the territory constraints (determined by these 4 first numbers) are respected.
|
20
|
+
# sale_state No The sale state. By default, a sale is always in "active" state, but it is possible to specify that the sale must be in "test" state using this parameter. Possible values: active / test
|
21
|
+
# country No The country which will be considered to validate the price of the publication. Value by default: the country of your organization. ISO 3166-1 Alpha-3 (can, fra, ita) format.
|
22
|
+
# aggregator No When a parent store makes a sale for one of it's child store, this field represents the ID of the parent store.
|
23
|
+
# uname No First and last name of the user. The value of this parameter will appear in the text of the digital watermark that will be placed on the file. When this parameter is provided on Sale API call, the watermarking delay will be shortened on the download request (the download will begin as soon as the user clicks on the download button instead of waiting for the platform to generate the watermarked copy).
|
24
|
+
|
25
|
+
# RESPONSE CODES
|
26
|
+
# Code Content Description
|
27
|
+
# 201 created The sale has been added successfully.
|
28
|
+
# 400 cannot_sell You cannot sell this publication.
|
29
|
+
# 400 missing_isbn You did not enter the ISBN.
|
30
|
+
# 400 missing_format You did not enter the format.
|
31
|
+
# 400 invalid_format The selected format is not available for this publication.
|
32
|
+
# 400 missing_cost You did not enter the price.
|
33
|
+
# 400 invalid_cost The price does not correspond to the price in the Platform.
|
34
|
+
# 400 missing_customer_id You did not enter your client's unique ID number.
|
35
|
+
# 400 missing_transaction_id You did not enter the transaction's unique ID number.
|
36
|
+
# 400 missing_protection You did not enter the protection type.
|
37
|
+
# 400 invalid_protection This protection is not available for this format of the publication.
|
38
|
+
# 400 invalid_sale_state The sale state is invalid.
|
39
|
+
# 401 duplicate The sale already exists.
|
40
|
+
# 401 access_denied You do not have access to the resource.
|
41
|
+
# 404 not_found Your organization could not be found.
|
42
|
+
# 503 service_unavailable A problem has occured while connecting to the server.
|
43
|
+
|
44
|
+
# TEST BOOKS
|
45
|
+
# Title: test-1. PDF format: 9990000000001 ePub format: 9991000000001 protection: watermark (“protection=watermark”) cost: $0, 0 euro (“cost=0”)
|
46
|
+
# Title: test-2. PDF format: 9990000000002 ePub format: 9991000000002 protection: ACS4 (“protection=acs4”) cost: $1.00, 1.00 euro (“cost=100”)
|
47
|
+
# Title: test-3. PDF format: 9990000000003 ePub format: 9991000000003 protection : ACS4 (“protection=acs4”) cost: $0, 0 euro (“cost=0”)
|
48
|
+
|
49
|
+
attr_accessor :cost,
|
50
|
+
:protection,
|
51
|
+
:customer_id,
|
52
|
+
:transaction_id,
|
53
|
+
:credit_card_prefix,
|
54
|
+
:sale_state,
|
55
|
+
:country,
|
56
|
+
:aggregator,
|
57
|
+
:uname
|
58
|
+
|
59
|
+
# Example:
|
60
|
+
# 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' }
|
61
|
+
# sale_hash = { cost: '999', customer_id: '123', transaction_id: 'abc', protection: 'acs4' }
|
62
|
+
# cantook = Cantook::SaleOfAPublication.new(base_hash)
|
63
|
+
# if cantook.sale_of_a_publication(sale_hash)
|
64
|
+
# puts "mais oui"
|
65
|
+
# else
|
66
|
+
# puts "mais non"
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# @param [Hash] params
|
70
|
+
# @option params [Integer] :cost - price in cents
|
71
|
+
# @option params [String] :protection - the file’s DRM protection eg 'acs4'
|
72
|
+
# @option params [String] :customer_id - the customer’s unique ID
|
73
|
+
# @option params [String] :transaction_id - the order’s unique ID
|
74
|
+
# @return [True] if response code is 201
|
75
|
+
# @return [False] if resopnse code is anything other than 201
|
76
|
+
def sale_of_a_publication(params)
|
77
|
+
self.cost = params[:cost]
|
78
|
+
self.protection = params[:protection]
|
79
|
+
self.customer_id = params[:customer_id]
|
80
|
+
self.transaction_id = params[:transaction_id]
|
81
|
+
do_request
|
82
|
+
response.code == 201
|
83
|
+
end
|
84
|
+
|
85
|
+
# sets and returns the response
|
86
|
+
def do_request
|
87
|
+
self.response = post_request(options)
|
88
|
+
end
|
89
|
+
private :do_request
|
90
|
+
|
91
|
+
# @return [String] The full url required for this request
|
92
|
+
def request_url
|
93
|
+
base_url + "/publications/#{isbn}/sales"
|
94
|
+
end
|
95
|
+
private :request_url
|
96
|
+
|
97
|
+
# @return [Hash] required parameters not included in the Cantook::Base base_options hash
|
98
|
+
def options
|
99
|
+
{
|
100
|
+
cost: cost,
|
101
|
+
protection: protection,
|
102
|
+
customer_id: customer_id,
|
103
|
+
transaction_id: transaction_id,
|
104
|
+
credit_card_prefix: credit_card_prefix,
|
105
|
+
sale_state: sale_state,
|
106
|
+
country: country,
|
107
|
+
aggregator: aggregator,
|
108
|
+
uname: uname
|
109
|
+
}
|
110
|
+
end
|
111
|
+
private :options
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Simulates a sale to determine if sale will be viable
|
3
|
+
#
|
4
|
+
# @author Gordon B. Isnor
|
5
|
+
#
|
6
|
+
module Cantook
|
7
|
+
class SimulateASale < Cantook::Base
|
8
|
+
|
9
|
+
# https://[platform]/api/organisations/[organisation_id]/publications/[isbn]/sales/new
|
10
|
+
|
11
|
+
# GET REQUEST
|
12
|
+
|
13
|
+
# PARAMETERS
|
14
|
+
# Name Mandatory Description
|
15
|
+
# cost Yes The price of the sale in cents (e.g., $19.99 => 1999).
|
16
|
+
# protection Yes The type of protection on the sold publication (none/watermark/acs4/acs4_time_limited).
|
17
|
+
# country No The country which will be considered to validate the price of the publication. Value by default: the country of your organization. ISO 3166-1 alpha-3 (can, fra, ita) format.
|
18
|
+
|
19
|
+
# RESPONSE CODES
|
20
|
+
# Code Content Description
|
21
|
+
# 200 valid The simulation was executed successfully.
|
22
|
+
# 400 cannot_sell You cannot sell this publication.
|
23
|
+
# 400 missing_isbn You did not enter the ISBN.
|
24
|
+
# 400 missing_format You did not enter the format.
|
25
|
+
# 400 invalid_format The selected format is not available for this publication.
|
26
|
+
# 400 missing_cost You did not enter the price.
|
27
|
+
# 400 invalid_cost The price does not correspond to the price in the Platform.
|
28
|
+
# 400 missing_protection You did not enter the protection type.
|
29
|
+
# 400 invalid_protection This protection is not available for this format of the publication.
|
30
|
+
# 401 access_denied You do not have access to the resource.
|
31
|
+
# 404 not_found Your organization could not be found.
|
32
|
+
# 503 service_unavailable A problem has occured while connecting to the server.
|
33
|
+
|
34
|
+
attr_accessor :cost, :protection, :country
|
35
|
+
|
36
|
+
# Example:
|
37
|
+
# 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' }
|
38
|
+
# simulate_hash = { cost: '999', protection: 'acs4', country: nil }
|
39
|
+
# cantook = Cantook::SimulateASale.new(base_hash)
|
40
|
+
# result = cantook.simulate_a_sale(simulate_hash)
|
41
|
+
# @param [Hash] params
|
42
|
+
# @option params [Integer] :cost - price in cents
|
43
|
+
# @option params [String] :protection - the file’s DRM protection eg 'acs4'
|
44
|
+
# @option params [String] :country - eg 'can'
|
45
|
+
# @return [True] if response code is 200
|
46
|
+
# @return [False] if response code is not 200
|
47
|
+
def simulate_a_sale(params)
|
48
|
+
self.cost = params[:cost]
|
49
|
+
self.protection = params[:protection]
|
50
|
+
self.country = params[:country]
|
51
|
+
do_request
|
52
|
+
response.code == 200
|
53
|
+
end
|
54
|
+
|
55
|
+
# sets and returns the response
|
56
|
+
def do_request
|
57
|
+
self.response = get_request(options)
|
58
|
+
end
|
59
|
+
private :do_request
|
60
|
+
|
61
|
+
# @return [String] The full url required for this request
|
62
|
+
def request_url
|
63
|
+
base_url + "/publications/#{isbn}/sales/new"
|
64
|
+
end
|
65
|
+
private :request_url
|
66
|
+
|
67
|
+
# @return [Hash] required parameters not included in the Cantook::Base base_options hash
|
68
|
+
def options
|
69
|
+
{ cost: cost, protection: protection, country: country }
|
70
|
+
end
|
71
|
+
private :options
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/cantook.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cantook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gordon B. Isnor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Cantook gem
|
56
|
+
email:
|
57
|
+
- gordonbisnor@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- cantook.gemspec
|
68
|
+
- lib/cantook.rb
|
69
|
+
- lib/cantook/base.rb
|
70
|
+
- lib/cantook/download_a_publication.rb
|
71
|
+
- lib/cantook/sale_of_a_publication.rb
|
72
|
+
- lib/cantook/simulate_a_sale.rb
|
73
|
+
homepage: http://www.github.com/gordonbisnor/cantook
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Facilitates Ruby and Ruby on Rails interactions with the Cantook API
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|