nlbsg 0.1.0
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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nlbsg.rb +25 -0
- data/lib/nlbsg/client.rb +54 -0
- data/lib/nlbsg/constants.rb +62 -0
- data/lib/nlbsg/exceptions.rb +0 -0
- data/lib/nlbsg/request.rb +14 -0
- data/lib/nlbsg/request/get_availability_info.rb +59 -0
- data/lib/nlbsg/request/get_title_details.rb +37 -0
- data/lib/nlbsg/request/search.rb +93 -0
- data/lib/nlbsg/response.rb +38 -0
- data/lib/nlbsg/response/get_availability_info.rb +24 -0
- data/lib/nlbsg/response/get_title_details.rb +68 -0
- data/lib/nlbsg/response/search.rb +28 -0
- data/lib/nlbsg/version.rb +3 -0
- data/nlbsg.gemspec +27 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c50e7142ddcb0174c13b1f6fccc7798ec78499e27851efcc8f5b05df8939deb8
|
|
4
|
+
data.tar.gz: 29c8ba38f8be2f6c205a93f5be61f69c22a18c71d4f1c90f5ad211227b669003
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ac78b017f35de63f5364113bc9c34a685eabcd8f6351d1a74da10c7919713b07c8e22e7d4ba38a62b8df9249d567295cdf17af898c694a17c4a2c9a3a82752df
|
|
7
|
+
data.tar.gz: 3a78a09514b55ac1f9fe1a4b2ca79f481ee75031d572eeac9f5e5910d888a4fd7b0a7023b2b6a811b69e8c9e5f16df14049d6d893185fb6de2862d665541ad3b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
nlbsg (0.1.0)
|
|
5
|
+
savon (~> 2.12.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.7.0)
|
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
+
akami (1.3.1)
|
|
13
|
+
gyoku (>= 0.4.0)
|
|
14
|
+
nokogiri
|
|
15
|
+
builder (3.2.4)
|
|
16
|
+
gyoku (1.3.1)
|
|
17
|
+
builder (>= 2.1.2)
|
|
18
|
+
httpi (2.4.5)
|
|
19
|
+
rack
|
|
20
|
+
socksify
|
|
21
|
+
mini_portile2 (2.5.3)
|
|
22
|
+
nokogiri (1.11.7)
|
|
23
|
+
mini_portile2 (~> 2.5.0)
|
|
24
|
+
racc (~> 1.4)
|
|
25
|
+
nori (2.6.0)
|
|
26
|
+
public_suffix (4.0.6)
|
|
27
|
+
racc (1.5.2)
|
|
28
|
+
rack (2.2.3)
|
|
29
|
+
rake (12.3.3)
|
|
30
|
+
savon (2.12.1)
|
|
31
|
+
akami (~> 1.2)
|
|
32
|
+
builder (>= 2.1.2)
|
|
33
|
+
gyoku (~> 1.2)
|
|
34
|
+
httpi (~> 2.3)
|
|
35
|
+
nokogiri (>= 1.8.1)
|
|
36
|
+
nori (~> 2.4)
|
|
37
|
+
wasabi (~> 3.4)
|
|
38
|
+
socksify (1.7.1)
|
|
39
|
+
wasabi (3.6.1)
|
|
40
|
+
addressable
|
|
41
|
+
httpi (~> 2.0)
|
|
42
|
+
nokogiri (>= 1.4.2)
|
|
43
|
+
|
|
44
|
+
PLATFORMS
|
|
45
|
+
ruby
|
|
46
|
+
|
|
47
|
+
DEPENDENCIES
|
|
48
|
+
nlbsg!
|
|
49
|
+
rake (~> 12.0)
|
|
50
|
+
|
|
51
|
+
BUNDLED WITH
|
|
52
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Chethan Anil
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# NLBSG
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nlbsg`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'nlbsg'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install nlbsg
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pest-control/nlbsg.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "nlbsg"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nlbsg.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "nlbsg/constants"
|
|
2
|
+
require "nlbsg/client"
|
|
3
|
+
require "nlbsg/exceptions"
|
|
4
|
+
require "nlbsg/version"
|
|
5
|
+
require "nlbsg/request"
|
|
6
|
+
require "nlbsg/response"
|
|
7
|
+
|
|
8
|
+
require 'savon'
|
|
9
|
+
|
|
10
|
+
module NLBSG
|
|
11
|
+
def self.client(key:, env: :staging)
|
|
12
|
+
@key = key
|
|
13
|
+
@env = env
|
|
14
|
+
|
|
15
|
+
return Client.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.key
|
|
19
|
+
@key
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.env
|
|
23
|
+
@env
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/nlbsg/client.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class Client
|
|
3
|
+
|
|
4
|
+
DEFAULT_CONFIG =
|
|
5
|
+
{
|
|
6
|
+
convert_request_keys_to: :camelcase,
|
|
7
|
+
open_timeout: 300,
|
|
8
|
+
read_timeout: 300
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
def search(options)
|
|
12
|
+
request = SearchRequest.new(options).build
|
|
13
|
+
response = client.call(:search, message: request)
|
|
14
|
+
SearchResponse.new(response)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_title_details(options)
|
|
18
|
+
request = GetTitleDetailsRequest.new(options).build
|
|
19
|
+
response = client.call(:get_title_details, message: request)
|
|
20
|
+
GetTitleDetailsResponse.new(response)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_availability_info(options)
|
|
24
|
+
request = GetAvailabilityInfoRequest.new(options).build
|
|
25
|
+
response = client.call(:get_availability_info, message: request)
|
|
26
|
+
GetAvailabilityInfoResponse.new(response)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def operations
|
|
30
|
+
client.operations
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
alias_method :title, :get_title_details
|
|
34
|
+
alias_method :availability, :get_availability_info
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def client
|
|
39
|
+
@client ||= Savon.client(config)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def config
|
|
43
|
+
DEFAULT_CONFIG.merge(wsdl: wsdl)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def wsdl
|
|
47
|
+
if NLBSG.env == :production
|
|
48
|
+
NLBSG::WSDL[:production]
|
|
49
|
+
elsif NLBSG.env == :staging
|
|
50
|
+
NLBSG::WSDL[:staging]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
WSDL =
|
|
3
|
+
{
|
|
4
|
+
staging: "https://openweb-stg.nlb.gov.sg/OWS/CatalogueService.svc?singleWsdl",
|
|
5
|
+
production: "https://openweb.nlb.gov.sg/OWS/CatalogueService.svc?singleWsdl"
|
|
6
|
+
}
|
|
7
|
+
LANGUAGE =
|
|
8
|
+
{
|
|
9
|
+
}
|
|
10
|
+
MEDIA_CODE =
|
|
11
|
+
{
|
|
12
|
+
books: "BK",
|
|
13
|
+
computer_file: "CF",
|
|
14
|
+
maps: "MP",
|
|
15
|
+
music: "MU",
|
|
16
|
+
mixed_materials: "MX",
|
|
17
|
+
serials: "SE",
|
|
18
|
+
visual_materials: "VM"
|
|
19
|
+
}
|
|
20
|
+
BRANCH =
|
|
21
|
+
{
|
|
22
|
+
"Tampines Regional Library": "TRL",
|
|
23
|
+
"Woodlands Regional Library": "WRL",
|
|
24
|
+
"Clementi Public Library": "CMPL",
|
|
25
|
+
"Lee Kong Chian Reference Library": "LKCRL",
|
|
26
|
+
"Ang Mo Kio Public Library": "AMKPL",
|
|
27
|
+
"Bukit Batok Public Library": "BBPL",
|
|
28
|
+
"Bukit Panjang Public Library": "BPPL",
|
|
29
|
+
"Bukit Merah Public Library": "BMPL",
|
|
30
|
+
"Central Public Library": "CLL",
|
|
31
|
+
"Cheng San Public Library": "CSPL",
|
|
32
|
+
"Choa Chu Kang Public Library": "CCKPL",
|
|
33
|
+
"Geylang East Public Library": "GEPL",
|
|
34
|
+
"Jurong Regional Library": "JRL",
|
|
35
|
+
"Jurong West Public Library": "JWPL",
|
|
36
|
+
"Queenstown Public Library": "QUPL",
|
|
37
|
+
"Toa Payoh Public Library": "TPPL",
|
|
38
|
+
"Yishun Public Library": "YIPL",
|
|
39
|
+
"Library@Orchard": "OCPL",
|
|
40
|
+
"Library@Chinatown": "CNPL",
|
|
41
|
+
"Sembawang Public Library": "SBPL",
|
|
42
|
+
"Library Supply Centre": "LSC",
|
|
43
|
+
"Serangoon Public Library": "SRPL",
|
|
44
|
+
"NL Heritage": "LOLC",
|
|
45
|
+
"Marine Parade Public Library": "MPPL",
|
|
46
|
+
"Bedok Public Library": "BEPL",
|
|
47
|
+
"Sengkang Public Library": "SKPL",
|
|
48
|
+
"Library@Esplanade": "EPPL",
|
|
49
|
+
"Mobile Bus": "MOLLEY",
|
|
50
|
+
"Pasir Ris Public Library": "PRPL",
|
|
51
|
+
"Bishan Public Library": "BIPL",
|
|
52
|
+
"Library Supply Centre for AV": "LSCAV",
|
|
53
|
+
"Lee Kong Chian Reference Library Level 7": "07LKCRL",
|
|
54
|
+
"Lee Kong Chian Reference Library Level 8": "08LKCRL",
|
|
55
|
+
"Lee Kong Chian Reference Library Level 9": "09LKCRL",
|
|
56
|
+
"Lee Kong Chian Reference Library Level 11": "11LKCRL",
|
|
57
|
+
"HarbourFront Public Library": "HBPL"
|
|
58
|
+
}
|
|
59
|
+
STATUS_CODE =
|
|
60
|
+
{
|
|
61
|
+
}
|
|
62
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class RequestBase
|
|
3
|
+
|
|
4
|
+
attr_accessor :options
|
|
5
|
+
|
|
6
|
+
def build(options)
|
|
7
|
+
options.merge(API_key: NLBSG.key)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require_relative "request/search"
|
|
13
|
+
require_relative "request/get_title_details"
|
|
14
|
+
require_relative "request/get_availability_info"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class GetAvailabilityInfoRequest < RequestBase
|
|
3
|
+
REQUIRED_REQUEST_FIELDS =
|
|
4
|
+
[
|
|
5
|
+
:BID,
|
|
6
|
+
:ISBN
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
MODIFIERS =
|
|
10
|
+
[
|
|
11
|
+
:sort_schema,
|
|
12
|
+
:start_record_position,
|
|
13
|
+
:maximum_records,
|
|
14
|
+
:set_id
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
def initialize(hash)
|
|
18
|
+
raise ArgumentError unless hash.is_a?(Hash)
|
|
19
|
+
|
|
20
|
+
@options = hash
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def build
|
|
24
|
+
query = prepare_query.merge(modifiers: prepare_modifiers)
|
|
25
|
+
|
|
26
|
+
super(query)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def prepare_modifiers
|
|
32
|
+
keys = options.keys & MODIFIERS
|
|
33
|
+
|
|
34
|
+
modifiers = {}
|
|
35
|
+
|
|
36
|
+
keys.each do |key|
|
|
37
|
+
modifiers[key] = options[key]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
modifiers
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def prepare_query
|
|
44
|
+
if (options.keys & REQUIRED_REQUEST_FIELDS).empty?
|
|
45
|
+
raise ArgumentError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
keys = options.keys & REQUIRED_REQUEST_FIELDS
|
|
49
|
+
|
|
50
|
+
query = {}
|
|
51
|
+
|
|
52
|
+
keys.each do |key|
|
|
53
|
+
query[key] = options[key]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
query
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class GetTitleDetailsRequest < RequestBase
|
|
3
|
+
REQUIRED_REQUEST_FIELDS =
|
|
4
|
+
[
|
|
5
|
+
:BID,
|
|
6
|
+
:ISBN
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
def initialize(hash)
|
|
10
|
+
raise ArgumentError unless hash.is_a?(Hash)
|
|
11
|
+
|
|
12
|
+
@options = hash
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def build
|
|
16
|
+
super(prepare_query)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def prepare_query
|
|
22
|
+
if (options.keys & REQUIRED_REQUEST_FIELDS).empty?
|
|
23
|
+
raise ArgumentError
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
keys = options.keys & REQUIRED_REQUEST_FIELDS
|
|
27
|
+
|
|
28
|
+
query = {}
|
|
29
|
+
|
|
30
|
+
keys.each do |key|
|
|
31
|
+
query[key] = options[key]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
query
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class SearchRequest < RequestBase
|
|
3
|
+
REQUIRED_SEARCH_FIELDS =
|
|
4
|
+
[
|
|
5
|
+
:keywords,
|
|
6
|
+
:author,
|
|
7
|
+
:subject,
|
|
8
|
+
:title
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
OPTIONAL_SEARCH_FIELDS =
|
|
12
|
+
[
|
|
13
|
+
:branch_ID,
|
|
14
|
+
:media_code,
|
|
15
|
+
:language
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
ALL_SEARCH_FIELDS = REQUIRED_SEARCH_FIELDS + OPTIONAL_SEARCH_FIELDS
|
|
19
|
+
|
|
20
|
+
MODIFIERS =
|
|
21
|
+
[
|
|
22
|
+
:sort_schema,
|
|
23
|
+
:start_record_position,
|
|
24
|
+
:maximum_records,
|
|
25
|
+
:set_id
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
def initialize(string_or_hash)
|
|
29
|
+
if string_or_hash.is_a?(String)
|
|
30
|
+
@options = { keywords: string_or_hash }
|
|
31
|
+
elsif string_or_hash.is_a?(Hash)
|
|
32
|
+
@options = string_or_hash
|
|
33
|
+
else
|
|
34
|
+
raise ArgumentError
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def build
|
|
39
|
+
search_items = prepare_search_items
|
|
40
|
+
modifiers = prepare_modifiers
|
|
41
|
+
query = prepare_query(search_items, modifiers)
|
|
42
|
+
|
|
43
|
+
super(query)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def prepare_search_items
|
|
49
|
+
if (options.keys & REQUIRED_SEARCH_FIELDS).empty?
|
|
50
|
+
raise ArgumentError
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
keys = options.keys & ALL_SEARCH_FIELDS
|
|
54
|
+
|
|
55
|
+
search_items = []
|
|
56
|
+
|
|
57
|
+
keys.each do |key|
|
|
58
|
+
search_items << add_search_item(field: key, terms: options[key])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
search_items
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def prepare_modifiers
|
|
65
|
+
keys = options.keys & MODIFIERS
|
|
66
|
+
|
|
67
|
+
modifiers = {}
|
|
68
|
+
|
|
69
|
+
keys.each do |key|
|
|
70
|
+
modifiers[key] = options[key]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
modifiers
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def prepare_query(search_items, modifiers)
|
|
77
|
+
{
|
|
78
|
+
search_items:
|
|
79
|
+
{
|
|
80
|
+
search_item: search_items
|
|
81
|
+
},
|
|
82
|
+
modifiers: modifiers
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def add_search_item(field:, terms:)
|
|
87
|
+
{
|
|
88
|
+
search_field: field.to_s.split('_').collect(&:capitalize).join,
|
|
89
|
+
search_terms: terms
|
|
90
|
+
}
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class ResponseBase
|
|
3
|
+
|
|
4
|
+
attr_accessor :response
|
|
5
|
+
|
|
6
|
+
def initialize(response)
|
|
7
|
+
@response = response
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def status
|
|
11
|
+
response[:status]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def message
|
|
15
|
+
response[:message]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def error_message
|
|
19
|
+
response[:error_message]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def wrap_in_array(object)
|
|
25
|
+
if object.nil?
|
|
26
|
+
[]
|
|
27
|
+
elsif object.is_a?(Array)
|
|
28
|
+
object
|
|
29
|
+
else
|
|
30
|
+
[object]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
require_relative "response/search"
|
|
37
|
+
require_relative "response/get_title_details"
|
|
38
|
+
require_relative "response/get_availability_info"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class GetAvailabilityInfoResponse < ResponseBase
|
|
3
|
+
|
|
4
|
+
def initialize(response)
|
|
5
|
+
super(response.to_hash[:get_availability_info_response])
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def next_record_position
|
|
9
|
+
@response[:next_record_position]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def set_id
|
|
13
|
+
@response[:set_id]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def items
|
|
17
|
+
wrap_in_array(@response.dig(:items, :item))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fetch_next_records
|
|
21
|
+
p "TODO"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class GetTitleDetailsResponse < ResponseBase
|
|
3
|
+
|
|
4
|
+
def initialize(response)
|
|
5
|
+
super(response.to_hash[:get_title_details_response])
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def title_detail
|
|
9
|
+
response[:title_detail]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def bid
|
|
13
|
+
title_detail[:bid]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def title_name
|
|
17
|
+
title_detail[:title_name]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def author
|
|
21
|
+
title_detail[:author]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def other_authors
|
|
25
|
+
title_detail[:other_authors]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def publisher
|
|
29
|
+
title_detail[:publisher]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def physical_desc
|
|
33
|
+
title_detail[:physical_desc]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def subject
|
|
37
|
+
title_detail[:subject]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def summary
|
|
41
|
+
title_detail[:summary]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def notes
|
|
45
|
+
title_detail[:notes]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def isbn
|
|
49
|
+
title_detail[:isbn]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def issn
|
|
53
|
+
title_detail[:issn]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def n_title_name
|
|
57
|
+
title_detail[:n_title_name]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def n_author_name
|
|
61
|
+
title_detail[:n_author_name]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def n_publisher
|
|
65
|
+
title_detail[:n_publisher]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module NLBSG
|
|
2
|
+
class SearchResponse < ResponseBase
|
|
3
|
+
|
|
4
|
+
def initialize(response)
|
|
5
|
+
super(response.to_hash[:search_response])
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def total_records
|
|
9
|
+
@response[:total_records]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def next_record_position
|
|
13
|
+
@response[:next_record_position]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def set_id
|
|
17
|
+
@response[:set_id]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def titles
|
|
21
|
+
wrap_in_array(@response.dig(:titles, :title))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fetch_next_records
|
|
25
|
+
p "TODO"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/nlbsg.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative 'lib/nlbsg/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "nlbsg"
|
|
5
|
+
spec.version = NLBSG::VERSION
|
|
6
|
+
spec.authors = ["Chethan Anil"]
|
|
7
|
+
spec.email = ["chethan@anil.sg"]
|
|
8
|
+
|
|
9
|
+
spec.summary = %q{A ruby wrapper for the NLB SG API}
|
|
10
|
+
spec.homepage = "https://github.com/pest-control/nlbsg"
|
|
11
|
+
spec.license = "MIT"
|
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
13
|
+
|
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/pest-control/nlbsg"
|
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/pest-control/nlbsg"
|
|
17
|
+
|
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
22
|
+
end
|
|
23
|
+
spec.bindir = "exe"
|
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
25
|
+
spec.require_paths = ["lib"]
|
|
26
|
+
spec.add_dependency "savon", "~> 2.12.0"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nlbsg
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chethan Anil
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-06-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: savon
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.12.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.12.0
|
|
27
|
+
description:
|
|
28
|
+
email:
|
|
29
|
+
- chethan@anil.sg
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- Gemfile
|
|
36
|
+
- Gemfile.lock
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- bin/console
|
|
41
|
+
- bin/setup
|
|
42
|
+
- lib/nlbsg.rb
|
|
43
|
+
- lib/nlbsg/client.rb
|
|
44
|
+
- lib/nlbsg/constants.rb
|
|
45
|
+
- lib/nlbsg/exceptions.rb
|
|
46
|
+
- lib/nlbsg/request.rb
|
|
47
|
+
- lib/nlbsg/request/get_availability_info.rb
|
|
48
|
+
- lib/nlbsg/request/get_title_details.rb
|
|
49
|
+
- lib/nlbsg/request/search.rb
|
|
50
|
+
- lib/nlbsg/response.rb
|
|
51
|
+
- lib/nlbsg/response/get_availability_info.rb
|
|
52
|
+
- lib/nlbsg/response/get_title_details.rb
|
|
53
|
+
- lib/nlbsg/response/search.rb
|
|
54
|
+
- lib/nlbsg/version.rb
|
|
55
|
+
- nlbsg.gemspec
|
|
56
|
+
homepage: https://github.com/pest-control/nlbsg
|
|
57
|
+
licenses:
|
|
58
|
+
- MIT
|
|
59
|
+
metadata:
|
|
60
|
+
homepage_uri: https://github.com/pest-control/nlbsg
|
|
61
|
+
source_code_uri: https://github.com/pest-control/nlbsg
|
|
62
|
+
changelog_uri: https://github.com/pest-control/nlbsg
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: 2.3.0
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 3.0.3
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: A ruby wrapper for the NLB SG API
|
|
82
|
+
test_files: []
|