Skip to content

Commit

Permalink
changed examples to pull keys from env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Dec 6, 2014
1 parent a65d75d commit 0181ba0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 85 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,24 @@ bundle install

After `bundle install` the `alm` gem is installed and available on the command line or in a Ruby repl.

### Command line
### In Ruby repl

xxx
Get altmetrics by DOI

```
xxxx
```ruby
Alm.alm(ids: '10.1371/journal.pone.0029797', key: '<key>', instance: "crossref")
```

```
xxxx
```ruby
=> "{\"total\":1,\"total_pages\":1,\"page\":1,\"error\":null,\"data\":[{\"doi\":\"10.1371/journal.pone.0029797\",\"title\":\"Ecological Guild Evolution and the Discovery of the World's Smallest Vertebrate\",\"issued\":{\"date-parts\":[[2012,1,11]]},\"canonical_url\":null,\"pmid\":\"22253785\",\"pmcid\":\"3256195\",\"mendeley_uuid\":null,\"viewed\":0,\"saved\":0,\"discussed\":0,\"cited\":0,\"update_date\":\"2014-11-15T20:59:22Z\"}]}"
```

### In Ruby repl
Search for altmetrics

xxx
```ruby

```
xxxx
```

```
xxxx
```
### Command line

_not quite done yet_
Binary file modified alm-0.1.0.gem
Binary file not shown.
99 changes: 30 additions & 69 deletions bin/alm
Original file line number Diff line number Diff line change
@@ -1,89 +1,50 @@
#!/usr/bin/env ruby
# module: citescli


require "thor"

class Alm < Thor
include Thor::Actions
require 'cites'
require 'alm'
require 'launchy'
require 'json'
require 'pp'

desc "match STRING", "Look for matches in free form citations, get a match and DOI"
# method_options :doi => :boolean
def match(tt)
tt = "#{tt}"
tt = tt.to_s.split(',')
out = Alm.match(tt)
puts out
end

desc "search STRING", "Search for articles via query string or DOI"
method_option :doi, :default => nil
desc "search for altmetrics"
method_option :ids, :default => nil
method_option :type, :default => nil
method_option :info, :default => nil
method_option :source, :default => nil
method_option :publisher, :default => nil
method_option :order, :default => nil
method_option :per_page, :default => nil
method_option :page, :default => nil
method_option :rows, :default => nil
method_option :sort, :default => nil
method_option :year, :default => nil
def search(tt)
method_option :instance, :default => nil
method_option :key, :default => nil
method_option :options, :default => nil
def alm(tt)
tt = "#{tt}"
say "Searching with query \'#{tt}\'", :blue
out = Alm.search(tt, options)

# Don't use meta for anything for now
items = out["items"]
# Restrict output to number of rows fetched even if more was returned
rows = options['rows'].to_i - 1
for item in items[0..rows]
puts "\n"
puts " Title: #{item['title']}"
puts " Year: #{item['year']}"
puts " Normalized score: #{item['normalizedScore']}"
puts " DOI: #{item['doi']}"
end
say "Searching with doi \'#{tt}\'", :blue
out = Alm.alm(tt, options)

# puts "#{tt}"
# puts opts["doi"] ? out['doi'] : out
end

desc "get citation", "Get a citation from a DOI"
method_option :format, :default => 'text'
method_option :style, :default => 'apa'
method_option :locale, :default => 'en-US'
method_option :cache, :default => true
def get(tt)
tt = "#{tt}"
# puts tt.to_s
tt = tt.to_s.split(',')
# puts tt
begin
out = Alm.doi2cit(tt, options[:format], options[:style],
options[:locale], options[:cache])
rescue Exception => e
abort(e.message)
end
# begin
# out = Cites.doi2cit(tt, options[:format], options[:style],
# options[:locale], options[:cache])
# rescue Exception => e
# abort(e.message)
# end

say "Found #{out.length} " + (out.length > 1 ? "matches" : "match"), :green
for entry in out
if ['citeproc-json'].include? options['format']
pp entry
else
puts entry
end
end

# for entry in out
# if ['citeproc-json'].include? options['format']
# pp entry
# else
# puts entry
# end
# end
end

desc "launch paper", "Open a paper from a given DOI in your default browser"
method_option :oa, :type => :boolean, :default => 'true'
def launch(doi)
if options[:oa]
url = "http://macrodocs.org/?doi=" + doi
Launchy.open(url)
else
url = "http://dx.doi.org/" + doi
Launchy.open(url)
end
end
end

Alm.start(ARGV)
Expand Down
9 changes: 6 additions & 3 deletions lib/alm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ module Alm
# * options: Options to pass on to HTTParty.get
#
# Usage:
# Alm.alm(ids: '10.1371/journal.pone.0029797', key: 'GKcTr6SrJKYx2KDzywJe', instance: "crossref")
# Alm.alm(ids: '10.4081/audiores.2013.e1', key: '1UwwuvPLZzbYxyrcQ3id', instance: "pkp")
# Alm.alm(ids: '10.1371/journal.pone.0025110', key: 'rkfDr76z75benY3pytM1', instance: "plos")
# Alm.alm(ids: '10.1371/journal.pone.0029797', key: ENV['CROSSREF_API_KEY'], instance: "crossref")
# Alm.alm(ids: '10.4081/audiores.2013.e1', key: ENV['PKP_API_KEY'], instance: "pkp")
# Alm.alm(ids: '10.1371/journal.pone.0025110', key: ENV['PLOS_API_KEY'], instance: "plos")
#
# # Search by source
# Alm.alm(source: 'twitter', key: ENV['PLOS_API_KEY'], instance: "plos")
#
# # get by publisher
# require 'HTTParty'
Expand Down

0 comments on commit 0181ba0

Please sign in to comment.