titlepage 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/titlepage.rb +3 -4
- metadata +4 -5
- data/lib/titlepage/rest.rb +0 -89
data/Rakefile
CHANGED
data/lib/titlepage.rb
CHANGED
@@ -38,7 +38,6 @@ module TitlePage
|
|
38
38
|
class NotLoggedInError < RuntimeError;end;
|
39
39
|
end
|
40
40
|
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require File.dirname(__FILE__) + '/titlepage/rest'
|
41
|
+
require 'titlepage/driver'
|
42
|
+
require 'titlepage/utils'
|
43
|
+
require 'titlepage/client'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titlepage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 1
|
10
|
+
version: 1.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Healy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-05 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- examples/titlepage.rb
|
93
93
|
- lib/titlepage.rb
|
94
94
|
- lib/titlepage/utils.rb
|
95
|
-
- lib/titlepage/rest.rb
|
96
95
|
- lib/titlepage/client.rb
|
97
96
|
- lib/titlepage/driver.rb
|
98
97
|
- Rakefile
|
data/lib/titlepage/rest.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
###################################################################
|
4
|
-
# A proxy REST web service for the titlepage SOAP API.
|
5
|
-
#
|
6
|
-
# Requires no state and exists to serialise requests to the authoritive
|
7
|
-
# API so that an organisation can avoid exceeding the API usage limits.
|
8
|
-
#
|
9
|
-
# To use this REST wrapper, run the following:
|
10
|
-
#
|
11
|
-
# thin -R config.ru -p 4567 start
|
12
|
-
#
|
13
|
-
# This make the following request:
|
14
|
-
#
|
15
|
-
# curl http://127.0.0.1:4567/username/password/ean
|
16
|
-
#
|
17
|
-
# Returns 400 if the requested EAN is invalid
|
18
|
-
# Returns 401 if the titlepage API returned an error, often an authentication issue
|
19
|
-
# Returns 404 if the requested EAN wasn't found on titlepage
|
20
|
-
# Returns 408 if the titlepage API didn't respond in time
|
21
|
-
# Returns 200 and a YAML serialised hash of results if the query was successful
|
22
|
-
#
|
23
|
-
###################################################################
|
24
|
-
|
25
|
-
require 'rubygems'
|
26
|
-
require 'sinatra/base'
|
27
|
-
require 'ean13'
|
28
|
-
require 'yaml'
|
29
|
-
require 'timeout'
|
30
|
-
|
31
|
-
module TitlePage
|
32
|
-
class Rest < Sinatra::Base
|
33
|
-
|
34
|
-
TIMESTAMP_FILE = "/tmp/titlepage.dat"
|
35
|
-
|
36
|
-
# We only respond to 1 URI
|
37
|
-
get '/:username/:password/:ean' do |username, password, ean|
|
38
|
-
status(400) and return unless EAN13.valid?(ean)
|
39
|
-
|
40
|
-
while (!update_file)
|
41
|
-
sleep 0.5
|
42
|
-
end
|
43
|
-
|
44
|
-
result = nil
|
45
|
-
|
46
|
-
begin
|
47
|
-
TitlePage::Client.open(username, password) do |tp|
|
48
|
-
Timeout::timeout(6) do
|
49
|
-
result = tp.first(ean)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
rescue Timeout::Error
|
53
|
-
status(408) and return
|
54
|
-
rescue Handsoap::Fault
|
55
|
-
status(401) and return
|
56
|
-
end
|
57
|
-
|
58
|
-
if result
|
59
|
-
YAML.dump(result.to_hash)
|
60
|
-
else
|
61
|
-
status(404)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
# update a lock file that we use to track when the last query was proxied
|
68
|
-
# through to the authoritive Titlepage API.
|
69
|
-
#
|
70
|
-
# Updates the file and returns true if no query was made in the previous 3
|
71
|
-
# seconds, otherwise doesn't update the file and returns false.
|
72
|
-
#
|
73
|
-
# Used to ensure we don't exceed the query limit.
|
74
|
-
#
|
75
|
-
def update_file
|
76
|
-
if File.file?(TIMESTAMP_FILE)
|
77
|
-
if Time.now.to_i - File.mtime(TIMESTAMP_FILE).to_i > 3
|
78
|
-
File.open(TIMESTAMP_FILE, "w") { |of| of.write "titlepage timestamp"}
|
79
|
-
true
|
80
|
-
else
|
81
|
-
false
|
82
|
-
end
|
83
|
-
else
|
84
|
-
File.open(TIMESTAMP_FILE, "w") { |of| of.write "titlepage timestamp"}
|
85
|
-
true
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|