Module: BibSonomy

Defined in:
lib/bibsonomy/api.rb,
lib/bibsonomy.rb,
lib/bibsonomy/csl.rb,
lib/bibsonomy/post.rb,
lib/bibsonomy/version.rb

Overview

Generates a list of publication posts from BibSonomy

required parameters:

  • user name

  • api key

optional parameters:

  • user name

  • tags

  • number of posts

  • style

  • directory

Changes: 2015-02-24

  • initial version

TODO:

  • escape data

  • make sorting, etc. configurable

  • automatically rename files (TODO: CSL lacks BibTeX key)

  • add intra_hash, user_name, etc. to CSL (cf. bitbucket.org/bibsonomy/bibsonomy/issue/2411/)

  • integrate AJAX abstract

  • make all options available via command line

Defined Under Namespace

Classes: API, CSL, Post

Constant Summary collapse

VERSION =
"0.4.2"

Class Method Summary collapse

Class Method Details

.main(args) ⇒ Object

parse command line options



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/bibsonomy/csl.rb', line 274

def self.main(args)

  # setting default options
  options = OpenStruct.new
  options.documents = false
  options.directory = nil
  options.tags = []
  options.style = "apa.csl"
  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', 'return posts for USER instead of user') { |v| options[:user] = 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('-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.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

  # set defaults for optional arguments
  options[:user] = options[:user_name] unless options[:user]

  #
  # do the actual work
  #
  csl = BibSonomy::CSL.new(options[:user_name], options[:api_key])
  csl.pdf_dir = options[:directory]
  csl.style = options[:style]

  html = csl.render(options[:user], options[:tags], options[:posts])

  return html

end