zotero 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/zotero.rb +8 -0
- data/lib/zotero/api.rb +16 -0
- data/lib/zotero/entities/collection.rb +59 -0
- data/lib/zotero/entities/creator.rb +29 -0
- data/lib/zotero/entities/entry.rb +77 -0
- data/lib/zotero/library.rb +19 -0
- data/lib/zotero/version.rb +3 -0
- data/zotero.gemspec +37 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cecbf49d8b9d2c207c4c2342f2f1ba9da6e26fe4
|
4
|
+
data.tar.gz: 24855d1fe43c8bd4255f202642fec4d8d68881ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ef858cda6d9df3644b9eed223347b2493e0f42ba56527273f96b30bcbb2109e1bfef5c18b72a9dd4a7c9ae591bb4b8568d240ceb0b685e05fa14076ac1d3ab4
|
7
|
+
data.tar.gz: d0af586f213c4832eead6122bea6a462bbea102d289343bf431ec6dccbfb7bbed5e8cfdb0b640e730a81e3837f70de1f56f061f098fa3b5ea8e1e2b412795d44
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Joshua Mostafa
|
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,39 @@
|
|
1
|
+
# Zotero
|
2
|
+
|
3
|
+
Provide easy Ruby access to Zotero, for e.g. generating online bibliographies
|
4
|
+
and reading lists.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'zotero'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install zotero
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
29
|
+
|
30
|
+
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).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zotero.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zotero"
|
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
|
data/bin/setup
ADDED
data/lib/zotero.rb
ADDED
data/lib/zotero/api.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Zotero::Api
|
5
|
+
def initialize(user_id, key)
|
6
|
+
@user_id = user_id
|
7
|
+
@key = key
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(path_fragment)
|
11
|
+
::JSON.parse(RestClient.get("https://api.zotero.org/users/#{@user_id}/#{path_fragment}", {
|
12
|
+
'Zotero-API-Version' => 3,
|
13
|
+
'Zotero-API-Key' => @key
|
14
|
+
}).body)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Zotero::Entities::Collection
|
2
|
+
attr_reader :name
|
3
|
+
|
4
|
+
def initialize(api, data)
|
5
|
+
@api = api
|
6
|
+
|
7
|
+
@key = data['key']
|
8
|
+
@no_entries = 0 == data['meta']['numItems']
|
9
|
+
@no_collections = 0 == data['meta']['numCollections']
|
10
|
+
@name = data['data']['name']
|
11
|
+
end
|
12
|
+
|
13
|
+
def collections
|
14
|
+
@collections ||= get_collections
|
15
|
+
end
|
16
|
+
|
17
|
+
def entries
|
18
|
+
@entries ||= get_entries
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_h
|
22
|
+
{
|
23
|
+
name: name,
|
24
|
+
collections: collections.collect(&:to_h),
|
25
|
+
entries: entries.collect(&:to_h)
|
26
|
+
}.symbolize_keys
|
27
|
+
end
|
28
|
+
|
29
|
+
# Eager-load all entries and child collections
|
30
|
+
def preload
|
31
|
+
entries
|
32
|
+
collections.each &:preload
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get_collections
|
39
|
+
return [] if @no_collections
|
40
|
+
|
41
|
+
@api.get("collections/#{@key}/collections").collect {|data|
|
42
|
+
::Zotero::Entities::Collection.new @api, data
|
43
|
+
}.sort {|a, b|
|
44
|
+
a.name <=> b.name
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_entries
|
49
|
+
return [] if @no_entries
|
50
|
+
|
51
|
+
@api.get("collections/#{@key}/items").select {|data|
|
52
|
+
'attachment' != data['data']['itemType']
|
53
|
+
}.collect { |data|
|
54
|
+
::Zotero::Entities::Entry.new data
|
55
|
+
}.sort {|a, b|
|
56
|
+
a.creator_sort_string <=> b.creator_sort_string
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Zotero::Entities::Creator
|
2
|
+
attr_reader :last_name, :first_name, :kind
|
3
|
+
|
4
|
+
def initialize(data)
|
5
|
+
@last_name = data['lastName']
|
6
|
+
@first_name = data['firstName']
|
7
|
+
@kind = data['creatorType']
|
8
|
+
end
|
9
|
+
|
10
|
+
def author?
|
11
|
+
'author' == kind
|
12
|
+
end
|
13
|
+
|
14
|
+
def editor?
|
15
|
+
'editor' == kind
|
16
|
+
end
|
17
|
+
|
18
|
+
def translator?
|
19
|
+
'translator' == kind
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
{
|
24
|
+
first_name: first_name,
|
25
|
+
last_name: last_name,
|
26
|
+
kind: kind
|
27
|
+
}.symbolize_keys
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
#TODO: rationalise these, find list of Zotero item types & attributes
|
4
|
+
ENTRY_ATTS = %w(
|
5
|
+
access_date
|
6
|
+
blog_title
|
7
|
+
book_title
|
8
|
+
date
|
9
|
+
edition
|
10
|
+
issue
|
11
|
+
number_of_volumes
|
12
|
+
pages
|
13
|
+
place
|
14
|
+
publication_title
|
15
|
+
publisher
|
16
|
+
running_time
|
17
|
+
series
|
18
|
+
series_number
|
19
|
+
studio
|
20
|
+
title
|
21
|
+
university
|
22
|
+
url
|
23
|
+
volume
|
24
|
+
website_title
|
25
|
+
)
|
26
|
+
|
27
|
+
class Zotero::Entities::Entry
|
28
|
+
attr_reader :creators, :kind, *ENTRY_ATTS
|
29
|
+
|
30
|
+
def initialize(data)
|
31
|
+
@key = data['key']
|
32
|
+
@kind = data['data']['itemType'].underscore
|
33
|
+
@creators = generate_creators data['data']['creators']
|
34
|
+
|
35
|
+
ENTRY_ATTS.each do |att|
|
36
|
+
instance_variable_set "@#{att}", data['data'][att.camelize(:lower)]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def authors
|
41
|
+
creators.select &:author?
|
42
|
+
end
|
43
|
+
|
44
|
+
def editors
|
45
|
+
creators.select &:editor?
|
46
|
+
end
|
47
|
+
|
48
|
+
def translators
|
49
|
+
creators.select &:translator?
|
50
|
+
end
|
51
|
+
|
52
|
+
def creator_sort_string
|
53
|
+
@creator_sort_string ||= generate_creator_sort_string
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_h
|
57
|
+
((ENTRY_ATTS + [:kind]).collect {|att|
|
58
|
+
[att, send(att.to_sym)]
|
59
|
+
} + [[:creators, creators.collect(&:to_h)]]).to_h.symbolize_keys
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def generate_creators(data)
|
65
|
+
return [] unless data
|
66
|
+
|
67
|
+
data.collect do |creator_data|
|
68
|
+
::Zotero::Entities::Creator.new creator_data
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def generate_creator_sort_string
|
73
|
+
creators.collect {|creator|
|
74
|
+
"#{creator.last_name} #{creator.first_name}"
|
75
|
+
}.join(' ')
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Zotero::Library
|
2
|
+
attr_reader :collections
|
3
|
+
|
4
|
+
def initialize(user_id, key)
|
5
|
+
@api = ::Zotero::Api.new(user_id, key)
|
6
|
+
end
|
7
|
+
|
8
|
+
def collections
|
9
|
+
@collections ||= get_collections
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_collections
|
15
|
+
@api.get('/collections/top').collect do |data|
|
16
|
+
::Zotero::Entities::Collection.new @api, data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/zotero.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zotero/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'zotero'
|
8
|
+
spec.version = Zotero::VERSION
|
9
|
+
spec.authors = ['Joshua Mostafa']
|
10
|
+
spec.email = ['micapam@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Access reference lists from Zotero with Ruby'
|
13
|
+
spec.description = 'Provide easy Ruby access to Zotero, for e.g. generating online bibliographies and reading lists.'
|
14
|
+
spec.homepage = 'https://github.com/micapam/zotero'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
|
34
|
+
spec.add_dependency 'rest-client', '>= 2'
|
35
|
+
spec.add_dependency 'activesupport', '>= 4.2.7'
|
36
|
+
spec.add_dependency 'json', '>= 1'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zotero
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Mostafa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.2.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.2.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
97
|
+
description: Provide easy Ruby access to Zotero, for e.g. generating online bibliographies
|
98
|
+
and reading lists.
|
99
|
+
email:
|
100
|
+
- micapam@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/zotero.rb
|
115
|
+
- lib/zotero/api.rb
|
116
|
+
- lib/zotero/entities/collection.rb
|
117
|
+
- lib/zotero/entities/creator.rb
|
118
|
+
- lib/zotero/entities/entry.rb
|
119
|
+
- lib/zotero/library.rb
|
120
|
+
- lib/zotero/version.rb
|
121
|
+
- zotero.gemspec
|
122
|
+
homepage: https://github.com/micapam/zotero
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Access reference lists from Zotero with Ruby
|
147
|
+
test_files: []
|