module BibSonomy
The BibSonomy
REST client for Ruby.
@todo error handling @todo getting more than 1000 posts
@author Robert Jäschke
Changes: 2018-10-09 (rja)
-
migrated URL handling to addressable library
2017-05-31 (rja)
-
refactored get_posts_for_group and get_posts_for_user into get_posts
2017-05-30 (rja)
-
added get_posts_for_group
Generates a list of publication posts from BibSonomy
required parameters:
-
user name
-
api key
optional parameters:
-
user name
-
tags
-
number of posts
-
style
-
directory
-
group
-
altmetric
Changes: 2018-08-09 (rja)
-
shortened DOI URL
2017-07-05 (rja)
-
added support for Altmetric badges
-
adapted options for command line use to support groups
2017-06-06 (rja)
-
added support for DOIs which are actually URLs (i.e., include the resolver)
2017-05-31 (rja)
-
added support to get posts of a group
2017-01-19 (rja)
-
added optional parameter group to control which posts are included based on their viewability for a specific group (not yet activated!)
2015-02-24 (rja)
-
initial version
@todo escape data @todo make sorting, etc. configurable @todo automatically rename files (TODO: CSL
lacks BibTeX key) @todo add intra_hash, user_name, etc. to CSL
(cf. bitbucket.org/bibsonomy/bibsonomy/issue/2411/) @todo integrate AJAX abstract @todo make all options available via command line @todo support filtering of posts by group (viewability)
@author Robert Jäschke
Constants
- VERSION
Public Class Methods
Parse command line options
@param args [Array<String>] command line options @return [String] the rendered posts as HTML
# File lib/bibsonomy/csl.rb, line 336 def self.main(args) # setting default options options = OpenStruct.new options.documents = false options.directory = nil options.tags = [] options.style = "apa.csl" options.viewable_group = "public" options.altmetric = nil options.posts = 1000 opt_parser = OptionParser.new do |opts| opts.banner = "Usage: csl.rb [options] user_name api_key" opts.separator "" opts.separator "Specific options:" # mandatory arguments are handled separately # optional arguments opts.on('-u', '--user USER', 'get posts for USER') { |v| options[:user] = v } opts.on('-g', '--group GROUP', 'get posts for GROUP') { |v| options[:group] = v } opts.on('-t', '--tags TAG,TAG,...', Array, 'return posts with the given tags') { |v| options[:tags] = v } opts.on('-s', '--style STYLE', 'use CSL style STYLE for rendering') { |v| options[:style] = v } opts.on('--viewable-group GROUP', 'include only posts viewable for GROUP') { |v| options[:viewable_group] = v } opts.on('-n', '--number-of-posts [COUNT]', Integer, 'number of posts to download') { |v| options[:posts] = v } opts.on('-d', '--directory DIR', 'target directory', ' (if not given, no documents are downloaed)') { |v| options[:directory] = v } opts.on('-a', '--altmetric TYPE', 'render Altmetric badge with type TYPE') { |v| options[:altmetric] = v } opts.separator "" opts.separator "Common options:" opts.on('-h', '--help', 'show this help message and exit') do puts opts exit end opts.on_tail('-v', "--version", "show version") do puts BibSonomy::VERSION exit end end opt_parser.parse!(args) # handle mandatory arguments begin mandatory = [:user_name, :api_key] missing = [] options[:api_key] = args.pop missing << :api_key unless options[:api_key] options[:user_name] = args.pop missing << :user_name unless options[:user_name] if not missing.empty? puts "Missing options: #{missing.join(', ')}" puts opt_parser exit end rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts $!.to_s puts opt_parser exit end # # do the actual work # csl = BibSonomy::CSL.new(options[:user_name], options[:api_key]) csl.pdf_dir = options[:directory] csl.style = options[:style] csl.group = options[:viewable_group] csl.altmetric_badge_type = options[:altmetric] if options[:group] grouping = "group" name = options[:group] elsif options[:user] grouping = "user" name = options[:user] else # default: API user grouping = "user" name = options[:user_name] end puts "call: #{grouping}, #{name}" html = csl.render(grouping, name, options[:tags], options[:posts]) return html end