orcid_album_cover 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +17 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/bin/orcid_album_cover +132 -0
- data/images/example.png +0 -0
- data/lib/orcid_album_cover/version.rb +3 -0
- data/orcid_album_cover.gemspec +31 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 764155abcf4d3db4813e940bcbd7ce03f37dc883
|
4
|
+
data.tar.gz: e26d6ccd3947e124187f6136b2af3c628dec1c9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c793bc7c3a08311554465c54ed00a525a36e167a9679482e1692d1974790d605cd1cf5871334f64b5fbcc636823db339a0afa4fca1f8b9688442fe8b72256f3
|
7
|
+
data.tar.gz: 27686925b4f2fb84dc2055905f1515a0c78d0f03cf99a52cdfe2e33174533ca2130423157d9f1aaa2cf6e7105ceffff434ea86fbcfb8485e9e5fb3c97579d166
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
##########################################################################
|
2
|
+
#
|
3
|
+
# Copyright 2014 University of Notre Dame
|
4
|
+
#
|
5
|
+
# Additional copyright may be held by others, as reflected in the commit log
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Orcid Album Cover
|
2
|
+
|
3
|
+
Generate an album cover for your favorite [ORCiD](https://orcid.org).
|
4
|
+
|
5
|
+
Don't just talk about your life's work, *show it*!
|
6
|
+
|
7
|
+
[![Example Image of Album Cover with much Rock and Roll](./images/example.png)](./images/example.png)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install orcid_album_cover
|
12
|
+
|
13
|
+
## Running (OS X only?)
|
14
|
+
|
15
|
+
$ orcid_album_cover <an_orcid>
|
16
|
+
|
17
|
+
```console
|
18
|
+
$ orcid_album_cover
|
19
|
+
Include a valid ORCiD:
|
20
|
+
$ orcid_album_cover DDDD-DDDD-DDDD-DDDD
|
21
|
+
|
22
|
+
If you don't have one, consider using 0000-0002-9952-7800
|
23
|
+
```
|
24
|
+
|
25
|
+
### Non-Ruby Dependencies
|
26
|
+
|
27
|
+
Install [ImageMagick](http://imagemagick.org/).
|
28
|
+
On OS X, you can use [Homebrew](http://http://brew.sh//): `$ brew install imagemagick`.
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( http://github.com/<my-github-username>/orcid_spray_bottle/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rest_client'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'capybara'
|
5
|
+
require 'capybara/rspec'
|
6
|
+
require 'uri'
|
7
|
+
require 'capybara-webkit'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
module Orcid
|
11
|
+
class AlbumCover
|
12
|
+
include Capybara::DSL
|
13
|
+
attr_reader :orcid_profile_id, :host, :person_name
|
14
|
+
def initialize(orcid_profile_id, options = {})
|
15
|
+
@orcid_profile_id = orcid_profile_id
|
16
|
+
@host = options.fetch(:host) { 'http://pub.orcid.org/' }
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
FileUtils.rm_rf(directory)
|
21
|
+
FileUtils.mkdir_p(directory)
|
22
|
+
find_person_name
|
23
|
+
find_dois
|
24
|
+
guard_for_no_dois
|
25
|
+
find_locations_from_dois
|
26
|
+
screenscrap_locations
|
27
|
+
generate_final_file
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_final_file
|
33
|
+
Dir["#{File.join(directory, '*.png')}"].each do |filename|
|
34
|
+
cropped_filename = File.join(directory, "cropped-#{File.basename(filename)}")
|
35
|
+
`convert #{filename} -thumbnail 300x300^ -gravity north -extent 300x300 #{cropped_filename}`
|
36
|
+
end
|
37
|
+
files = Dir["#{File.join(directory, 'cropped-*.png')}"]
|
38
|
+
output_filename = "#{directory}.png"
|
39
|
+
final_filename = "#{File.dirname(directory)}/final-#{File.basename(directory)}.png"
|
40
|
+
`cd #{@directory} && montage #{files.join(' ')} -geometry 300x300+2+2 #{output_filename}`
|
41
|
+
width = `identify -format %w #{output_filename}`.strip
|
42
|
+
height = `identify -format %h #{output_filename}`.strip
|
43
|
+
`convert -background '#0008' -fill white -gravity center -size #{width}x#{(height.to_i * 0.2).to_i} caption:"#{person_name} #{orcid_profile_id}" #{output_filename} +swap -gravity north -composite #{final_filename}`
|
44
|
+
`open #{final_filename}`
|
45
|
+
end
|
46
|
+
|
47
|
+
def directory
|
48
|
+
@directory ||= File.expand_path("../../tmp/#{orcid_profile_id}", __FILE__)
|
49
|
+
end
|
50
|
+
|
51
|
+
def profile_works_uri
|
52
|
+
File.join(host, "v1.1/#{orcid_profile_id}/orcid-works")
|
53
|
+
end
|
54
|
+
|
55
|
+
def profile_uri
|
56
|
+
File.join(host, "v1.1/#{orcid_profile_id}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def find_person_name
|
60
|
+
response = RestClient.get(profile_uri, accept: :xml)
|
61
|
+
document = Nokogiri::XML(response)
|
62
|
+
personal_details = document.css('personal-details')
|
63
|
+
@person_name = ''
|
64
|
+
if credit_name = personal_details.css('credit-name')
|
65
|
+
@person_name = credit_name.text
|
66
|
+
else
|
67
|
+
if given_name = personal_details.css('given-names')
|
68
|
+
@person_name += " #{given_name.text}"
|
69
|
+
end
|
70
|
+
if family_name = personal_details.css('family-name')
|
71
|
+
@person_name += " #{family_name.text}"
|
72
|
+
end
|
73
|
+
@person_name.strip
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_dois
|
78
|
+
response = RestClient.get(profile_works_uri, accept: :xml)
|
79
|
+
document = Nokogiri::XML(response)
|
80
|
+
@dois = []
|
81
|
+
document.css('work-external-identifier').each_with_object(@dois) do |node, dois|
|
82
|
+
if node.css('work-external-identifier-type').text =~ /^doi$/i
|
83
|
+
dois << node.css('work-external-identifier-id').text
|
84
|
+
end
|
85
|
+
dois
|
86
|
+
end
|
87
|
+
@dois.uniq!
|
88
|
+
@dois
|
89
|
+
end
|
90
|
+
|
91
|
+
def guard_for_no_dois
|
92
|
+
if @dois.empty?
|
93
|
+
STDERR.puts "No public DOIs found for ORCID: #{orcid_profile_id}."
|
94
|
+
exit(-1)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def find_locations_from_dois
|
99
|
+
@locations = []
|
100
|
+
@dois.each_with_object(@locations) do |doi, mem|
|
101
|
+
response = RestClient.get("http://dx.doi.org/#{doi}", accept: :html) { |resp, request, result| resp }
|
102
|
+
@locations << response.headers.fetch(:location)
|
103
|
+
end
|
104
|
+
@locations
|
105
|
+
end
|
106
|
+
|
107
|
+
def screenscrap_locations
|
108
|
+
Capybara.current_driver = :webkit
|
109
|
+
Capybara.run_server = false
|
110
|
+
@locations.each do |location|
|
111
|
+
uri = URI.parse(location)
|
112
|
+
Capybara.app_host = "#{uri.scheme}://#{uri.host}"
|
113
|
+
visit(uri.path)
|
114
|
+
filename = "#{location.hash}.png"
|
115
|
+
page.save_screenshot(File.join(directory, filename))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
if ARGV[0].to_s =~ /^\d{4}-\d{4}-\d{4}-\d{4}$/
|
123
|
+
orcid_profile_id = ARGV[0]
|
124
|
+
album_cover = Orcid::AlbumCover.new(orcid_profile_id)
|
125
|
+
album_cover.call
|
126
|
+
else
|
127
|
+
# Thank you Erik Lease Morgan for having lots of DOIs
|
128
|
+
STDERR.puts "Include a valid ORCiD:"
|
129
|
+
STDERR.puts "$ #{File.basename(__FILE__)} DDDD-DDDD-DDDD-DDDD"
|
130
|
+
STDERR.puts "\n\tIf you don't have one, consider using 0000-0002-9952-7800"
|
131
|
+
exit!(-1)
|
132
|
+
end
|
data/images/example.png
ADDED
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'orcid_album_cover/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'orcid_album_cover'
|
8
|
+
spec.version = OrcidAlbumCover::VERSION
|
9
|
+
spec.authors = [
|
10
|
+
'Jeremy Friesen'
|
11
|
+
]
|
12
|
+
spec.email = [
|
13
|
+
'jeremy.n.friesen@gmail.com'
|
14
|
+
]
|
15
|
+
spec.summary = %q{ORCID Album Cover}
|
16
|
+
spec.description = %q{ORCID Album Cover - This is Your Life}
|
17
|
+
spec.homepage = "https://github.com/jeremyf/orcid_album_cover"
|
18
|
+
spec.license = "APACHE2"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency 'nokogiri'
|
26
|
+
spec.add_dependency 'capybara'
|
27
|
+
spec.add_dependency 'capybara-webkit'
|
28
|
+
spec.add_dependency 'rest_client'
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: orcid_album_cover
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Friesen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara-webkit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ORCID Album Cover - This is Your Life
|
98
|
+
email:
|
99
|
+
- jeremy.n.friesen@gmail.com
|
100
|
+
executables:
|
101
|
+
- orcid_album_cover
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/orcid_album_cover
|
111
|
+
- images/example.png
|
112
|
+
- lib/orcid_album_cover/version.rb
|
113
|
+
- orcid_album_cover.gemspec
|
114
|
+
homepage: https://github.com/jeremyf/orcid_album_cover
|
115
|
+
licenses:
|
116
|
+
- APACHE2
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.0.14
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: ORCID Album Cover
|
138
|
+
test_files: []
|