umlaut 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,19 @@
1
1
  require 'aws_product_sign'
2
+ require 'httpclient'
2
3
 
3
4
  #
4
- # As of Aug 15 2009, Amazon API calls will require a secret key from Amazon.
5
- # If you are unable to get such an account/key, this service can still be used
6
- # for certain functions by setting 'make_aws_call' to false, and configuring
7
- # 'service_types' to only include one or more of: ["search_inside",
8
- # "highlighted_link", "excerpts"]
9
- # Other services, such as enhance_referent and cover_image require api access.
5
+ # AWS API account is required. NOTE: You may want to the API Terms of Service
6
+ # and make sure you feel comfortable with them.
10
7
  #
11
8
  # More about registering for and finding your AWS access key and secret key
12
9
  # can be found here:
13
10
  # http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/AWSCredentials.html
14
11
  # http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/ViewingCredentials.html
15
12
  #
13
+ # NOTE: Discovery of :search_inside and :excerpts links requires screen-scraping
14
+ # an Amazon back-end endpoint. If you are uncomfortable with this mode of
15
+ # access, disable those service types, or do not use this adapter.
16
+ #
16
17
  #
17
18
  # services.yml params:
18
19
  # api_key: required. AWS "access key".
@@ -42,6 +43,7 @@ class Amazon < Service
42
43
 
43
44
  include MetadataHelper
44
45
  include ActionView::Helpers::SanitizeHelper
46
+ include UmlautHttp
45
47
 
46
48
  required_config_params :url, :api_key, :associate_tag
47
49
  attr_reader :url
@@ -50,8 +52,6 @@ class Amazon < Service
50
52
  # defaults
51
53
  @url = 'http://webservices.amazon.com/onca/xml'
52
54
  @reader_base_url = 'http://www.amazon.com/gp/reader/'
53
- # Old version non-lightboxed, whcih doesn't work very well anymore.
54
- # @reader_base_url = 'http://www.amazon.com/gp/sitbv3/reader/'
55
55
  @display_name = "Amazon.com"
56
56
  @display_text = "Amazon's page"
57
57
  @service_types = ["abstract", "highlighted_link", "cover_image", "search_inside", "referent_enhance", "excerpts"]
@@ -75,8 +75,8 @@ class Amazon < Service
75
75
 
76
76
  # Only a few service types can get by without an aws call
77
77
  if (! @make_aws_call &&
78
- @service_types.find {|type| ! ["search_inside", "highlighted_link", "excerpts"].include?(type) } )
79
- raise Exception.new("You can only set make_aws_call == false on the definition of an Amazon service adaptor when the adaptor is also set to generate no service responses other than highlighted_link, search_inside, and excerpts")
78
+ @service_types.find {|type| ! ["search_inside", "highlighted_link", "excerpts"].include?(type)} )
79
+ raise Exception.new("You can only set make_aws_call == false on the definition of an Amazon service adaptor when the adaptor is also set to generate no service responses other than highlighted_link, search_inside, and excerpts")
80
80
  end
81
81
  end
82
82
 
@@ -309,30 +309,39 @@ class Amazon < Service
309
309
  # need it for.
310
310
  if ( @service_types.include?("highlighted_link") ||
311
311
  @service_types.include?("search_inside"))
312
- inside_base = @reader_base_url + asin
313
- # lame screen-scrape for search inside availability. We need to
314
- # distinguish between no results, "look inside", and "search inside".
315
- response = open(inside_base).read
316
-
317
- # This regexp only suitable for screen-scraping the old-style "sitbv3"
318
- # reader page screen
319
- if (response.include?("<div class='sitb-pop-search'>"))
320
- # then we have search_inside. I think this always includes 'look', but
321
- # we'll test seperate for that.
322
- search_inside= true
323
- end
324
312
 
325
- if (response.include?('<a href="/gp/reader/'))
326
- # then we have look inside, not neccesarily search.
327
- look_inside = true
313
+
314
+ # Checking an Amazon JSON url endpoint which can tell us whether
315
+ # we have search-inside or look-inside
316
+ client = HTTPClient.new()
317
+ client.transparent_gzip_decompression = true
318
+ client.connect_timeout = 3
319
+ client.send_timeout = 3
320
+ client.receive_timeout = 3
321
+
322
+ service_url = "http://www.amazon.com/gp/search-inside/service-data"
323
+ form_vars = {"method" => "getBookData", "asin" => asin}
324
+ headers = proxy_like_headers(request).merge("Accept" => "application/json, text/javascript, */*; q=0.01")
325
+
326
+ response = client.post service_url, form_vars, headers
327
+ hash = JSON.parse(response.body)
328
+
329
+ if hash["searchable"].to_s == "true"
330
+ search_inside= true
328
331
  end
332
+
333
+ if hash["litbPages"].kind_of?(Array) && hash["litbPages"].length > 0
334
+ look_inside = true
335
+ end
329
336
  end
330
337
 
338
+ reader_url = @reader_base_url + asin
339
+
331
340
  if ( @service_types.include?("search_inside") && search_inside )
332
341
  request.add_service_response(
333
342
  :service => self,
334
343
  :display_text=>@display_name,
335
- :url=> inside_base,
344
+ :url=> reader_url,
336
345
  :service_type_value => :search_inside
337
346
  )
338
347
  end
@@ -346,7 +355,7 @@ class Amazon < Service
346
355
 
347
356
  request.add_service_response(
348
357
  :service=>self,
349
- :url => inside_base,
358
+ :url => reader_url,
350
359
  :asin=>asin,
351
360
  :display_text => @display_name,
352
361
  :service_type_value => 'excerpts')
@@ -22,6 +22,7 @@ require 'openurl'
22
22
  #
23
23
  # illiad:
24
24
  # type: Illiad
25
+ # base_url: http://ill.university.edu/site/illiad.dll/OpenURL
25
26
  # priority: 4
26
27
  # preempted_by:
27
28
  # existing_type: fulltext
@@ -31,6 +32,7 @@ require 'openurl'
31
32
  #
32
33
  # illiad:
33
34
  # type: Illiad
35
+ # base_url: http://ill.university.edu/site/illiad.dll/OpenURL
34
36
  # priority: 4
35
37
  # preempted_by:
36
38
  # existing_service: SFX
@@ -1,3 +1,3 @@
1
1
  module Umlaut
2
- VERSION = "3.3.0"
2
+ VERSION = "3.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umlaut
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-30 00:00:00.000000000 Z
12
+ date: 2014-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.5.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: httpclient
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.4'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.4'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: marc
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -675,7 +691,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
675
691
  version: '0'
676
692
  segments:
677
693
  - 0
678
- hash: 1193680988527448261
694
+ hash: -2681065323364276573
679
695
  required_rubygems_version: !ruby/object:Gem::Requirement
680
696
  none: false
681
697
  requirements:
@@ -684,7 +700,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
684
700
  version: '0'
685
701
  segments:
686
702
  - 0
687
- hash: 1193680988527448261
703
+ hash: -2681065323364276573
688
704
  requirements: []
689
705
  rubyforge_project:
690
706
  rubygems_version: 1.8.23