borrow_direct 0.9.0 → 0.9.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTNmMzNjZTU2NWY3NzJlMThhZmQ0ODExZTZmN2YwNGE2MzJmMDBhOQ==
4
+ NTczYmU1OWU3ZWZkNzkwZTBhZTZmMTU0MWRjMTk1NGVhNTY3YzYxNA==
5
5
  data.tar.gz: !binary |-
6
- NjUxMGE4MTE5YjY3OTcyYTEzOTkzYmRiN2ExYmFiZGQzY2EwZmJmOA==
6
+ OTAwNmQ5OWFhZDJmZTgzM2FiYTE4NzVjOTVhMDIzNDM3MzlmOWM1Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzBmODM3YzUxODBhMTY1ZmI5MTljZWE5N2Q5ODA3YWMzMGQyZWVjNzcwZDA4
10
- NDYzZGZkMDI2ZjYzYjVhNDI2MmYyYzJmOGZkMmYwNDg2NjFlYzFiMzQ2YzRm
11
- ZGE3MzE2MzU0MTdmMGFhODQ1NTI2ZTQ1NGZlYjdkMTdmMmFjNmM=
9
+ ZWJhOTg3Nzk5ODY5ZWU1OGE5ZDIwMjhhYjc5OGYwNmZlODNhZmMxMDMxYTlm
10
+ ZmNiMGQxZTMxNTkzMDdhYWNiYTk2NDg0ODBmYTdkOTY3ZTQ4ZDcwMmQwYmUz
11
+ MzIxYzVmNDBhMGRmNGE3NWNmODkyNTlhYWQ1ZjYwYmJkOGNlZWQ=
12
12
  data.tar.gz: !binary |-
13
- NmZmMzcwZWJiMDEyNGZiZjg2ODYwZjRiYThjNjhhZWNkNmYzNGQ0YTI1MmVm
14
- YmUwOTI2MGI0OTYzZjQ1YjgxMjI0Mzk1OTcxY2I1NTc5MWJjN2QyZTJiYjg2
15
- Yzk4NGJmNzBhMmJiOTc2YmM1MTVkOGY2YmFiNWY4MzVhY2YyMzg=
13
+ YThjMDY3OWFkMzY3YWM4YTBhZGEyOTVhNzliOGM2NzgyY2VlZTMwOTZhM2M0
14
+ NzM5MzViNjk4Y2E0ZTc5NzU2Yzg3NmZhYjRhNmU4YjAxYjM2MzRkYjAzYzFk
15
+ MTRhNTFmMTI4Y2IzNzc4ODVkYjI4M2RlY2JmNjZmNDU2NjlkYmY=
data/README.md CHANGED
@@ -36,7 +36,7 @@ Then you can do things.
36
36
 
37
37
  ~~~ruby
38
38
  # with default generic patron set in config find_item_patron_barcode
39
- response = BorrowDirect::FindItem.new.find?(:isbn => "1212121212")
39
+ response = BorrowDirect::FindItem.new.find(:isbn => "1212121212")
40
40
  # Returns a BorrowDirect::FindItem::Response
41
41
  response.requestable?
42
42
  response.pickup_locations
@@ -32,6 +32,8 @@ module BorrowDirect
32
32
  clauses = []
33
33
 
34
34
  options.each_pair do |field, value|
35
+ next if value.nil?
36
+
35
37
  code = @@fields[field]
36
38
 
37
39
  raise ArgumentError.new("Don't recognize field code `#{field}`") unless code
@@ -57,13 +59,14 @@ module BorrowDirect
57
59
  def query_url_with(options)
58
60
  query = query_with(options)
59
61
 
60
- return self.url_base + '?' + "query=#{CGI.escape query}"
62
+ return add_query_param(self.url_base, "query", query).to_s
63
+
61
64
  end
62
65
 
63
66
  def best_known_item_query_url_with(options)
64
67
  query = best_known_item_query_with(options)
65
68
 
66
- return self.url_base + '?' + "query=#{CGI.escape query}"
69
+ return add_query_param(self.url_base, "query", query).to_s
67
70
  end
68
71
 
69
72
  # We don't really know how to escape, for now
@@ -73,6 +76,20 @@ module BorrowDirect
73
76
  str.gsub(/[")()]/, ' ')
74
77
  end
75
78
 
79
+ def add_query_param(uri, key, value)
80
+ uri = URI.parse(uri) unless uri.kind_of? URI
81
+
82
+ query_param = "#{CGI.escape key}=#{CGI.escape value}"
83
+
84
+ if uri.query
85
+ uri.query += "&" + query_param
86
+ else
87
+ uri.query = query_param
88
+ end
89
+
90
+ return uri
91
+ end
92
+
76
93
 
77
94
  end
78
95
  end
@@ -1,3 +1,3 @@
1
1
  module BorrowDirect
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'test_helper'
1
2
  require 'uri'
2
3
  require 'cgi'
3
4
 
@@ -37,6 +38,27 @@ describe "GenerateQuery" do
37
38
  assert_include parts, 'ti="This is a title"'
38
39
  assert_include parts, 'au="This is an author"'
39
40
  end
41
+
42
+ it "ignores nil arguments" do
43
+ generate_query = BorrowDirect::GenerateQuery.new(@test_base)
44
+
45
+ url = generate_query.query_url_with(:title => "This is a title", :author => nil)
46
+
47
+ parsed_url = URI.parse(url)
48
+ url_query = CGI.parse( parsed_url.query )
49
+
50
+ assert_present url_query
51
+
52
+ assert_length 1, url_query["query"]
53
+
54
+ query_text = url_query["query"].first
55
+
56
+ parts = query_text.split(" and ")
57
+
58
+ assert_length 1, parts
59
+
60
+ assert_include parts, 'ti="This is a title"'
61
+ end
40
62
  end
41
63
 
42
64
  describe "best_known_item_query_url_with" do
@@ -87,5 +109,31 @@ describe "GenerateQuery" do
87
109
  assert_include parts, 'au="This is an author"'
88
110
  end
89
111
 
112
+ it "can handle nil arguments" do
113
+ url = BorrowDirect::GenerateQuery.new(@html_query_base_url).best_known_item_query_url_with(
114
+ :isbn => nil,
115
+ :title => 'the new international economic order',
116
+ :author => nil
117
+ )
118
+
119
+ query = assert_bd_query_url(url)
120
+
121
+ parts = query.split(" and ")
122
+
123
+ assert_include parts, 'ti="the new international economic order"'
124
+ end
125
+
90
126
  end
127
+
128
+ def assert_bd_query_url(url)
129
+ assert_present url
130
+
131
+ parsed_url = URI.parse(url)
132
+ url_query = CGI.parse( parsed_url.query )
133
+ assert_present url_query
134
+ assert_length 1, url_query["query"]
135
+
136
+ return url_query["query"].first
137
+ end
138
+
91
139
  end
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://bdtest.relais-host.com/portal-service/user/authentication/patron
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"AuthenticationInformation":{"LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","PatronId":"DUMMY_BD_PATRON"}}'
9
+ headers:
10
+ User-Agent:
11
+ - ruby borrow_direct gem (0.9.0) https://github.com/jrochkind/borrow_direct
12
+ Accept:
13
+ - ! '*/*'
14
+ Date:
15
+ - Wed, 05 Nov 2014 16:53:04 GMT
16
+ Content-Type:
17
+ - application/json
18
+ Accept-Language:
19
+ - en
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx/1.4.1
27
+ Date:
28
+ - Wed, 05 Nov 2014 16:53:05 GMT
29
+ Content-Type:
30
+ - application/json;charset=UTF-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - visited=yes
37
+ Expires:
38
+ - Thu, 01 Jan 1970 00:00:00 GMT
39
+ - Thu, 01 Jan 1970 00:00:00 GMT
40
+ Content-Language:
41
+ - en
42
+ Pragma:
43
+ - no-cache
44
+ Cache-Control:
45
+ - no-cache, no-store, max-age=0
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"Authentication":{"AuthnUserInfo":{"AId":"hF7U8rjP8Lum43gpZdB1SxScEz8","LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","Iso639_2_LangCode":"ENG","UserLogin":"DUMMY_BD_PATRON","FirstName":"Jonathan","LastName":"Rochkind","AllowLoanAddRequest":true,"AllowCopyAddRequest":false,"AllowSelDelivLoanChange":true,"AllowSelDelivCopyChange":false,"ILSProfile":{"EmailAddress":"jonathan@dnil.net","Telephone":"4105168886","AddressInformation":{"Address1":"Library
49
+ Systems","Address2":"MSE Library\r\nHomewood Campus"}}}}}'
50
+ http_version:
51
+ recorded_at: Wed, 05 Nov 2014 16:53:05 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,91 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://bdtest.relais-host.com/portal-service/user/authentication/patron
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"AuthenticationInformation":{"LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","PatronId":"DUMMY_BD_PATRON"}}'
9
+ headers:
10
+ User-Agent:
11
+ - ruby borrow_direct gem 0.9.0 (HTTPClient 2.5.3.1) https://github.com/jrochkind/borrow_direct
12
+ Accept:
13
+ - ! '*/*'
14
+ Date:
15
+ - Wed, 05 Nov 2014 16:52:54 GMT
16
+ Content-Type:
17
+ - application/json
18
+ Accept-Language:
19
+ - en
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx/1.4.1
27
+ Date:
28
+ - Wed, 05 Nov 2014 16:52:55 GMT
29
+ Content-Type:
30
+ - application/json;charset=UTF-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - visited=yes
37
+ Expires:
38
+ - Thu, 01 Jan 1970 00:00:00 GMT
39
+ - Thu, 01 Jan 1970 00:00:00 GMT
40
+ Content-Language:
41
+ - en
42
+ Pragma:
43
+ - no-cache
44
+ Cache-Control:
45
+ - no-cache, no-store, max-age=0
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"Authentication":{"AuthnUserInfo":{"AId":"r6vckYjDR6PfQzuCiT5w2qT1VP0","LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","Iso639_2_LangCode":"ENG","UserLogin":"DUMMY_BD_PATRON","FirstName":"Jonathan","LastName":"Rochkind","AllowLoanAddRequest":true,"AllowCopyAddRequest":false,"AllowSelDelivLoanChange":true,"AllowSelDelivCopyChange":false,"ILSProfile":{"EmailAddress":"jonathan@dnil.net","Telephone":"4105168886","AddressInformation":{"Address1":"Library
49
+ Systems","Address2":"MSE Library\r\nHomewood Campus"}}}}}'
50
+ http_version:
51
+ recorded_at: Wed, 05 Nov 2014 16:52:55 GMT
52
+ - request:
53
+ method: post
54
+ uri: https://bdtest.relais-host.com/dws/item/add
55
+ body:
56
+ encoding: UTF-8
57
+ string: ! '{"PartnershipId":"BD","AuthorizationId":"r6vckYjDR6PfQzuCiT5w2qT1VP0","PickupLocation":null,"ExactSearch":[{"Type":"ISBN","Value":"1441190090"}]}'
58
+ headers:
59
+ User-Agent:
60
+ - ruby borrow_direct gem 0.9.0 (HTTPClient 2.5.3.1) https://github.com/jrochkind/borrow_direct
61
+ Accept:
62
+ - ! '*/*'
63
+ Date:
64
+ - Wed, 05 Nov 2014 16:52:55 GMT
65
+ Content-Type:
66
+ - application/json
67
+ Accept-Language:
68
+ - en
69
+ response:
70
+ status:
71
+ code: 200
72
+ message: OK
73
+ headers:
74
+ Server:
75
+ - nginx/1.4.1
76
+ Date:
77
+ - Wed, 05 Nov 2014 16:52:58 GMT
78
+ Content-Type:
79
+ - application/json;charset=UTF-8
80
+ Transfer-Encoding:
81
+ - chunked
82
+ Connection:
83
+ - keep-alive
84
+ body:
85
+ encoding: US-ASCII
86
+ string: ! '{"Request":{"RequestLink":{"ButtonLabel":"Request","ButtonLink":"http://findit.library.jhu.edu/resolve?genre=book","RequestMessage":"Borrow
87
+ Direct cannot fill this request at this time. Please request through Interlibrary
88
+ Loan."}}}'
89
+ http_version:
90
+ recorded_at: Wed, 05 Nov 2014 16:52:58 GMT
91
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://bdtest.relais-host.com/portal-service/user/authentication/patron
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"AuthenticationInformation":{"LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","PatronId":"DUMMY_BD_PATRON"}}'
9
+ headers:
10
+ User-Agent:
11
+ - ruby borrow_direct gem 0.9.0 (HTTPClient 2.5.3.1) https://github.com/jrochkind/borrow_direct
12
+ Accept:
13
+ - ! '*/*'
14
+ Date:
15
+ - Wed, 05 Nov 2014 16:52:58 GMT
16
+ Content-Type:
17
+ - application/json
18
+ Accept-Language:
19
+ - en
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx/1.4.1
27
+ Date:
28
+ - Wed, 05 Nov 2014 16:52:59 GMT
29
+ Content-Type:
30
+ - application/json;charset=UTF-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - visited=yes
37
+ Expires:
38
+ - Thu, 01 Jan 1970 00:00:00 GMT
39
+ - Thu, 01 Jan 1970 00:00:00 GMT
40
+ Content-Language:
41
+ - en
42
+ Pragma:
43
+ - no-cache
44
+ Cache-Control:
45
+ - no-cache, no-store, max-age=0
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ! '{"Authentication":{"AuthnUserInfo":{"AId":"fe7zSp7Et_Nw5d5YYmIbR28sBTg","LibrarySymbol":"DUMMY_BD_LIBRARY_SYMBOL","Iso639_2_LangCode":"ENG","UserLogin":"DUMMY_BD_PATRON","FirstName":"Jonathan","LastName":"Rochkind","AllowLoanAddRequest":true,"AllowCopyAddRequest":false,"AllowSelDelivLoanChange":true,"AllowSelDelivCopyChange":false,"ILSProfile":{"EmailAddress":"jonathan@dnil.net","Telephone":"4105168886","AddressInformation":{"Address1":"Library
49
+ Systems","Address2":"MSE Library\r\nHomewood Campus"}}}}}'
50
+ http_version:
51
+ recorded_at: Wed, 05 Nov 2014 16:52:59 GMT
52
+ - request:
53
+ method: post
54
+ uri: https://bdtest.relais-host.com/dws/item/add
55
+ body:
56
+ encoding: UTF-8
57
+ string: ! '{"PartnershipId":"BD","AuthorizationId":"fe7zSp7Et_Nw5d5YYmIbR28sBTg","PickupLocation":null,"ExactSearch":[{"Type":"ISBN","Value":"9797994864"}]}'
58
+ headers:
59
+ User-Agent:
60
+ - ruby borrow_direct gem 0.9.0 (HTTPClient 2.5.3.1) https://github.com/jrochkind/borrow_direct
61
+ Accept:
62
+ - ! '*/*'
63
+ Date:
64
+ - Wed, 05 Nov 2014 16:52:59 GMT
65
+ Content-Type:
66
+ - application/json
67
+ Accept-Language:
68
+ - en
69
+ response:
70
+ status:
71
+ code: 200
72
+ message: OK
73
+ headers:
74
+ Server:
75
+ - nginx/1.4.1
76
+ Date:
77
+ - Wed, 05 Nov 2014 16:53:04 GMT
78
+ Content-Type:
79
+ - application/json;charset=UTF-8
80
+ Transfer-Encoding:
81
+ - chunked
82
+ Connection:
83
+ - keep-alive
84
+ body:
85
+ encoding: US-ASCII
86
+ string: ! '{"Request":{"RequestNumber":"JHU-99000794"}}'
87
+ http_version:
88
+ recorded_at: Wed, 05 Nov 2014 16:53:04 GMT
89
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borrow_direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -145,6 +145,7 @@ files:
145
145
  - test/vcr_cassettes/Authentication/get_auth_id/raises_for_a_bad_patron_barcode.yml
146
146
  - test/vcr_cassettes/Authentication/get_auth_id/returns_an_auth_id_for_a_good_request.yml
147
147
  - test/vcr_cassettes/Authentication/raw_request_to_verify_HTTP_api/.yml
148
+ - test/vcr_cassettes/Authentication/raw_request_to_verify_HTTP_api/works.yml
148
149
  - test/vcr_cassettes/FindItem/_find_item_request/finds_a_locally_available_item.yml
149
150
  - test/vcr_cassettes/FindItem/_find_item_request/finds_a_requestable_item.yml
150
151
  - test/vcr_cassettes/FindItem/_find_item_request/finds_an_item_that_does_not_exist_in_BD.yml
@@ -173,6 +174,8 @@ files:
173
174
  - test/vcr_cassettes/RequestItem/make_request/raises_for_unrequestable.yml
174
175
  - test/vcr_cassettes/RequestItem/make_request/returns_number_for_succesful_request.yml
175
176
  - test/vcr_cassettes/RequestItem/make_request/says_no_for_item_that_BD_returns_PUBRI004.yml
177
+ - test/vcr_cassettes/RequestItem/make_request_/raises_for_unrequestable.yml
178
+ - test/vcr_cassettes/RequestItem/make_request_/returns_number_for_succesful_request.yml
176
179
  - test/vcr_cassettes/RequestItem/raw_requests_an_unrequestable_item.yml
177
180
  - test/vcr_cassettes/RequestItem/uses_manually_set_auth_id.yml
178
181
  - test/vcr_cassettes/RequestItem/with_pickup_location_and_requestable_item/still_works.yml
@@ -223,6 +226,7 @@ test_files:
223
226
  - test/vcr_cassettes/Authentication/get_auth_id/raises_for_a_bad_patron_barcode.yml
224
227
  - test/vcr_cassettes/Authentication/get_auth_id/returns_an_auth_id_for_a_good_request.yml
225
228
  - test/vcr_cassettes/Authentication/raw_request_to_verify_HTTP_api/.yml
229
+ - test/vcr_cassettes/Authentication/raw_request_to_verify_HTTP_api/works.yml
226
230
  - test/vcr_cassettes/FindItem/_find_item_request/finds_a_locally_available_item.yml
227
231
  - test/vcr_cassettes/FindItem/_find_item_request/finds_a_requestable_item.yml
228
232
  - test/vcr_cassettes/FindItem/_find_item_request/finds_an_item_that_does_not_exist_in_BD.yml
@@ -251,6 +255,8 @@ test_files:
251
255
  - test/vcr_cassettes/RequestItem/make_request/raises_for_unrequestable.yml
252
256
  - test/vcr_cassettes/RequestItem/make_request/returns_number_for_succesful_request.yml
253
257
  - test/vcr_cassettes/RequestItem/make_request/says_no_for_item_that_BD_returns_PUBRI004.yml
258
+ - test/vcr_cassettes/RequestItem/make_request_/raises_for_unrequestable.yml
259
+ - test/vcr_cassettes/RequestItem/make_request_/returns_number_for_succesful_request.yml
254
260
  - test/vcr_cassettes/RequestItem/raw_requests_an_unrequestable_item.yml
255
261
  - test/vcr_cassettes/RequestItem/uses_manually_set_auth_id.yml
256
262
  - test/vcr_cassettes/RequestItem/with_pickup_location_and_requestable_item/still_works.yml