montague 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +4 -0
- data/README.md +138 -0
- data/Rakefile +2 -0
- data/lib/montague.rb +9 -0
- data/lib/montague/api/api.rb +12 -0
- data/lib/montague/api/base.rb +27 -0
- data/lib/montague/api/client.rb +27 -0
- data/lib/montague/api/journal.rb +52 -0
- data/lib/montague/api/publisher.rb +52 -0
- data/lib/montague/model/archiving.rb +26 -0
- data/lib/montague/model/copyright_link.rb +26 -0
- data/lib/montague/model/funder.rb +26 -0
- data/lib/montague/model/header.rb +22 -0
- data/lib/montague/model/journal.rb +26 -0
- data/lib/montague/model/journal_report.rb +15 -0
- data/lib/montague/model/journals_report.rb +15 -0
- data/lib/montague/model/mandate.rb +44 -0
- data/lib/montague/model/model.rb +22 -0
- data/lib/montague/model/paid_access.rb +34 -0
- data/lib/montague/model/publisher.rb +46 -0
- data/lib/montague/model/publisher_report.rb +12 -0
- data/lib/montague/model/publishers_report.rb +14 -0
- data/lib/montague/model/report_header_mixin.rb +12 -0
- data/lib/montague/model/report_http_response_mixin.rb +12 -0
- data/lib/montague/model/report_publisher_mixin.rb +12 -0
- data/lib/montague/model/structure.rb +18 -0
- data/lib/montague/reporter/journal.rb +26 -0
- data/lib/montague/reporter/journals.rb +26 -0
- data/lib/montague/reporter/publisher.rb +24 -0
- data/lib/montague/reporter/publishers.rb +24 -0
- data/lib/montague/reporter/reporter.rb +11 -0
- data/lib/montague/version.rb +5 -0
- data/lib/montague/xml_extractor/base.rb +58 -0
- data/lib/montague/xml_extractor/header.rb +43 -0
- data/lib/montague/xml_extractor/journal.rb +31 -0
- data/lib/montague/xml_extractor/publisher.rb +164 -0
- data/lib/montague/xml_extractor/xml_extractor.rb +13 -0
- data/montague.gemspec +22 -0
- data/test/test_helper.rb +102 -0
- data/test/test_search_by_journal.rb +90 -0
- data/test/test_search_by_publisher_api.rb +36 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5226c19f5fadffaa16d55605546efceb1a8c20ad
|
4
|
+
data.tar.gz: e17f0ad06b2dee8460b17c30d15209ec2d35d611
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbc04e1e3037e14f53f481c9e8cfacbe99daeb03282e2d3731fc7df6269bec12ebd7498e126d5e2d05408f857d90be9a60f20348ee1374990cddbaec1cb32d14
|
7
|
+
data.tar.gz: 88e6fc0cd58ad35adb326549b84ad34faf2c0b3834cc001a4f03d09b3f22497a830adff0b34df30bcf875d32712c6498c9c6637d03537cb6619c8599cf38bbbf
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
## 0.2.0 - 2018-02-09
|
6
|
+
### Removed
|
7
|
+
- Language support.
|
8
|
+
|
9
|
+
## 0.1.1 - 2018-02-07
|
10
|
+
### Changed
|
11
|
+
- Language support - string keyword argument replaced by symbol.
|
12
|
+
|
13
|
+
## 0.1.0 - 2018-02-06
|
14
|
+
### Added
|
15
|
+
- For SHERPA/RoMEO API v2.9.
|
16
|
+
- Find publisher indirectly using journal search by ISSN, search by title.
|
17
|
+
- Find publisher directly using publisher search by name, search by ID.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# Montague
|
2
|
+
|
3
|
+
Wrapper for the SHERPA/RoMEO API.
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/montague.svg)](https://badge.fury.io/rb/montague)
|
8
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/73f9d8be3f61882a8ec6/maintainability)](https://codeclimate.com/github/lulibrary/montague/maintainability)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'montague'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install montague
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Discover a publisher's copyright and archiving policies by searching for a publisher directly or by searching for a publisher indirectly via a journal.
|
29
|
+
|
30
|
+
<a href="http://www.sherpa.ac.uk/romeo.php"><img src="http://www.sherpa.ac.uk/images/romeosmall.jpg" width="100" height="54" alt="SHERPA/RoMEO Database" border="0"></a>
|
31
|
+
|
32
|
+
### Journal search
|
33
|
+
```ruby
|
34
|
+
# without API key
|
35
|
+
journals = Montague::API::Journal.new
|
36
|
+
# with API key
|
37
|
+
journals = Montague::API::Journal.new api_key: 'YOUR_API_KEY'
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Find by journal ISSN
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
report = journals.find_by_issn '1550-7998'
|
44
|
+
#=> #<Montague::Model::JournalReport:0x00c0ffee ...>
|
45
|
+
report.journal
|
46
|
+
#=> #<Montague::Model::Journal:0x00c0ffee @title="Physical Review D - Particles, Fields, Gravitation and Cosmology", @issn="1550-7998">
|
47
|
+
report.publisher
|
48
|
+
#=> #<Montague::Model::Publisher:0x00c0ffee ...>
|
49
|
+
report.publisher.name
|
50
|
+
#=> "American Physical Society"
|
51
|
+
report.publisher.conditions
|
52
|
+
#=> ["On author's personal website, employer's website or institutional repository", ...]
|
53
|
+
report.publisher.pre_prints
|
54
|
+
#=> #<Montague::Model::Archiving:0x00c0ffee @permission="can", @restrictions=[]>
|
55
|
+
report.publisher.romeo_colour
|
56
|
+
#=> "green"
|
57
|
+
report.publisher.mandates
|
58
|
+
#=> [#<Montague::Model::Mandate:0x00c0ffee @funder=#<Montague::Model::Funder:0x00c0ffee @name="Australian Research Council", @acronym="ARC">, @publisher_complies="yes", @compliance_type="Compliant", @selected_titles="no">, ...]
|
59
|
+
```
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# alternative numbers for a journal, typically ESSN and ISSN
|
63
|
+
report = journals.find_by_issn '1552-3535,0013-1245'
|
64
|
+
report.journal
|
65
|
+
#=> #<Montague::Model::Journal:0xb3969e8 @title="Education and Urban Society", @issn="0013-1245">
|
66
|
+
report.publisher
|
67
|
+
#=> #<Montague::Model::Publisher:0x00c0ffee ...>
|
68
|
+
```
|
69
|
+
|
70
|
+
#### Find by journal title
|
71
|
+
```ruby
|
72
|
+
report = journals.find_by_title text: 'modern language', filter: :contains
|
73
|
+
#=> #<Montague::Model::JournalsReport:0x00c0ffee ...>
|
74
|
+
report.journals.size
|
75
|
+
#=> 13
|
76
|
+
report.journals
|
77
|
+
#=> [#<Montague::Model::Journal:0xacf4aa4 @title="Canadian Modern Language Review / Revue canadian des langues vivantes", @issn="0008-4506">, ...]
|
78
|
+
report.publisher
|
79
|
+
#=> nil
|
80
|
+
```
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# example of when the publisher is not available for a journal
|
84
|
+
report = journals.find_by_title text: 'Man', filter: :exact
|
85
|
+
#=> #<Montague::Model::JournalsReport:0x00c0ffee ...>
|
86
|
+
report.journals.size
|
87
|
+
#=> 1
|
88
|
+
report.publisher
|
89
|
+
#=> nil
|
90
|
+
```
|
91
|
+
|
92
|
+
### Publisher search
|
93
|
+
```ruby
|
94
|
+
# without API key
|
95
|
+
publishers = Montague::API::Publisher.new
|
96
|
+
# with API key
|
97
|
+
publishers = Montague::API::Publisher.new api_key: 'YOUR_API_KEY'
|
98
|
+
```
|
99
|
+
|
100
|
+
#### Find by publisher name
|
101
|
+
```ruby
|
102
|
+
report = publishers.find_by_name text: 'institute', filter: :exact
|
103
|
+
#=> #<Montague::Model::PublishersReport:0x00c0ffee ...>
|
104
|
+
report.publishers.size
|
105
|
+
#=> 122
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Find by publisher ID (RoMEO)
|
109
|
+
```ruby
|
110
|
+
report = publishers.find_by_id 10
|
111
|
+
#=> #<Montague::Model::PublisherReport:0x00c0ffee ...>
|
112
|
+
report.publisher
|
113
|
+
#=> #<Montague::Model::Publisher:0x00c0ffee ...>
|
114
|
+
```
|
115
|
+
|
116
|
+
### Search client
|
117
|
+
```ruby
|
118
|
+
# without API key
|
119
|
+
client = Montague::API::Client.new
|
120
|
+
# with API key
|
121
|
+
client = Montague::API::Client.new api_key: 'YOUR_API_KEY'
|
122
|
+
```
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
report = client.journals.find_by_issn '1550-7998'
|
126
|
+
#=> #<Montague::Model::JournalReport:0x00c0ffee ...>
|
127
|
+
report.publisher
|
128
|
+
#=> #<Montague::Model::Publisher:0x00c0ffee ...>
|
129
|
+
```
|
130
|
+
|
131
|
+
### Inspecting reports
|
132
|
+
```ruby
|
133
|
+
report.header
|
134
|
+
#=> #<Montague::Model::Header:0x00c0ffee @api_control="journal", @hits=1, @message=nil, @outcome="singleJournal">
|
135
|
+
report.http_response
|
136
|
+
#=> #<HTTP::Response/1.1 200 OK {"Date"=>"Fri, 02 Feb 2018 11:34:38 GMT", "Server"=>"Apache/2.4.7 (Ubuntu)", "X-Powered-By"=>"PHP/5.5.9-1ubuntu4.22", "Access-Control-Allow-Origin"=>"*", "Vary"=>"Accept-Encoding", "Content-Length"=>"5056", "Connection"=>"close", "Content-Type"=>"text/xml"}>
|
137
|
+
```
|
138
|
+
|
data/Rakefile
ADDED
data/lib/montague.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Montague
|
2
|
+
|
3
|
+
module API
|
4
|
+
|
5
|
+
# Base API
|
6
|
+
#
|
7
|
+
class Base
|
8
|
+
|
9
|
+
# @param config [Hash]
|
10
|
+
# @option config [String] :api_url URL of the SHERPA/RoMEO service (if it changes)
|
11
|
+
# @option config [String] :api_key API key of the SHERPA/RoMEO service user
|
12
|
+
def initialize(config = {})
|
13
|
+
@config = config
|
14
|
+
@config[:api_url] = 'http://www.sherpa.ac.uk/romeo/api29.php' unless config[:api_url]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def common_parameters
|
20
|
+
"&showfunder=all&ak=#{@config[:api_key]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Montague
|
2
|
+
|
3
|
+
module API
|
4
|
+
|
5
|
+
# API client
|
6
|
+
#
|
7
|
+
class Client < Montague::API::Base
|
8
|
+
# (see Montague::API::Base#initialize)
|
9
|
+
def initialize(config = {})
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Montague::API::Journal]
|
14
|
+
def journals
|
15
|
+
Montague::API::Journal.new @config
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Montague::API::Publisher]
|
19
|
+
def publishers
|
20
|
+
Montague::API::Publisher.new @config
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Montague
|
2
|
+
|
3
|
+
module API
|
4
|
+
|
5
|
+
# Journal API
|
6
|
+
#
|
7
|
+
class Journal < Montague::API::Base
|
8
|
+
|
9
|
+
# (see Montague::API::Base#initialize)
|
10
|
+
def initialize(config = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param issn [String] International Standard Serial Number e.g. 1234-5678.
|
15
|
+
# @return (see #journal_report)
|
16
|
+
def find_by_issn(issn)
|
17
|
+
url = "#{@config[:api_url]}?issn=#{issn}#{common_parameters}"
|
18
|
+
response = HTTP.get URI.encode(url)
|
19
|
+
journal_report response
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param text [String] Multiple words treated as a single string. Case insensitive.
|
23
|
+
# @param filter [Symbol]
|
24
|
+
# * :exact - Verbatim e.g. 'Journal of Geology'
|
25
|
+
# * :starts - Starts with e.g. 'machine'
|
26
|
+
# * :contains - Contains e.g. 'modern language'
|
27
|
+
# @return (see #journals_report)
|
28
|
+
def find_by_title(text:, filter: :exact)
|
29
|
+
url = "#{@config[:api_url]}?jtitle=#{text}&qtype=#{filter}#{common_parameters}"
|
30
|
+
response = HTTP.get URI.encode(url)
|
31
|
+
journals_report response
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# @return [Montague::Model::JournalReport]
|
37
|
+
def journal_report(response)
|
38
|
+
reporter = Montague::Reporter::Journal.new response
|
39
|
+
reporter.report
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Montague::Model::JournalsReport]
|
43
|
+
def journals_report(response)
|
44
|
+
reporter = Montague::Reporter::Journals.new response
|
45
|
+
reporter.report
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Montague
|
2
|
+
|
3
|
+
module API
|
4
|
+
|
5
|
+
# Publisher API
|
6
|
+
#
|
7
|
+
class Publisher < Montague::API::Base
|
8
|
+
|
9
|
+
# (see Montague::API::Base#initialize)
|
10
|
+
def initialize(config = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param id [Fixnum] RoMEO persistent ID
|
15
|
+
# @return (see #publisher_report)
|
16
|
+
def find_by_id(id)
|
17
|
+
url = "#{@config[:api_url]}?id=#{id}#{common_parameters}"
|
18
|
+
response = HTTP.get URI.encode(url)
|
19
|
+
publisher_report response
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param text [String] e.g. 'optical society'
|
23
|
+
# @param filter [Symbol]
|
24
|
+
# * :all - All words present but in any order or location
|
25
|
+
# * :any - At least one of the words present
|
26
|
+
# * :exact - Intact phrase somewhere e.g. 'tute of'
|
27
|
+
# @return (see #publishers_report)
|
28
|
+
def find_by_name(text:, filter: :all)
|
29
|
+
url = "#{@config[:api_url]}?pub=#{text}&qtype=#{filter}#{common_parameters}"
|
30
|
+
response = HTTP.get URI.encode(url)
|
31
|
+
publishers_report response
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# @return [Montague::Model::PublishersReport]
|
37
|
+
def publishers_report(response)
|
38
|
+
reporter = Montague::Reporter::Publishers.new response
|
39
|
+
reporter.report
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Montague::Model::PublisherReport]
|
43
|
+
def publisher_report(response)
|
44
|
+
reporter = Montague::Reporter::Publisher.new response
|
45
|
+
reporter.report
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Montague
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# Archiving
|
5
|
+
#
|
6
|
+
class Archiving < Montague::Model::Structure
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :permission
|
10
|
+
|
11
|
+
# @return [Array<String>]
|
12
|
+
attr_reader :restrictions
|
13
|
+
|
14
|
+
# @param v [String]
|
15
|
+
def permission=(v)
|
16
|
+
@permission = v if v && !v.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param v [Array]
|
20
|
+
def restrictions=(v)
|
21
|
+
@restrictions = v if v
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Montague
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# Copyright link
|
5
|
+
#
|
6
|
+
class CopyrightLink < Montague::Model::Structure
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :text
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :url
|
13
|
+
|
14
|
+
# @param v [String]
|
15
|
+
def text=(v)
|
16
|
+
@text = v if v && !v.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param v [String]
|
20
|
+
def url=(v)
|
21
|
+
@url = v if v && !v.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Montague
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# Funder
|
5
|
+
#
|
6
|
+
class Funder < Montague::Model::Structure
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :acronym
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
# @param v [String]
|
15
|
+
def acronym=(v)
|
16
|
+
@acronym = v if v && !v.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param v [String]
|
20
|
+
def name=(v)
|
21
|
+
@name = v if v && !v.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|