Top Level Namespace

Defined Under Namespace

Modules: Lagotto

Instance Method Summary collapse

Instance Method Details

#getuserinfo(x: nil, y: nil) ⇒ Object



74
75
76
77
78
# File 'lib/lagotto-rb/helpers.rb', line 74

def getuserinfo(x: nil, y: nil)
  usr = ifnot(x, ENV["PLOS_ALERTS_USER"])
  pwd = ifnot(y, ENV["PLOS_ALERTS_PWD"])
  return { "key" => usr, "pwd" => pwd }
end

#ifnot(x, y) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/lagotto-rb/helpers.rb', line 80

def ifnot(x, y)
  if x == nil
    return y
  else
    return x
  end
end

#join_ids(x) ⇒ Object

def test_values(name, input, values)

if input.class == String:
  input = input.split(' ')
if type(input) != None:
  if len(input) > 1: raise TypeError('Parameter "%s" must be length 1' % name)
  if input[0] not in values: raise TypeError('Parameter "%s" must be one of %s' % (name, values))

end



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lagotto-rb/helpers.rb', line 43

def join_ids(x)
  if x.class != NilClass
    if x.class != String
      x.join(',')
    else
      x
    end
  else
    x
  end
end

#pick_url(x) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lagotto-rb/helpers.rb', line 55

def pick_url(x)
  urls = {
    "plos" => "http://alm.plos.org/api",
    "crossref" => "http://det.labs.crossref.org/api",
    "datacite" => "http://dlm.datacite.org/api",
    "datacite_profiles" => "https://profiles.labs.datacite.org/api",
    "elife" => "http://alm.svr.elifesciences.org/api/v5",
    "pkp" => "http://pkp-alm.lib.sfu.ca/api/v5",
    "copernicus" => "http://metricus.copernicus.org/api/v5",
    "pensoft" => "http://alm.pensoft.net:81//api/v5"
  }
  url = urls[x]
  if url == nil
    raise TypeError('instance must be one of plos, elife, crossref, pkp, copernicus, or pensoft')
  else
    return url
  end
end

#pick_url_alerts(x) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/lagotto-rb/helpers.rb', line 88

def pick_url_alerts(x)
  urls = {
    "plos" => "http://alm.plos.org/api/alerts",
    "elife" => "http://lagotto.svr.elifesciences.org/api/v4/alerts",
    "crossref" => "http://det.labs.crossref.org/api/v4/alerts",
    "pkp" => "http://pkp-alm.lib.sfu.ca/api/v4/alerts",
    "copernicus" => "http://metricus.copernicus.org/api/v4/alerts",
    "pensoft" => "http://alm.pensoft.net:81//api/v4/alerts"
  }
  url = urls[x]
  if url == nil
    raise TypeError('instance must be one of plos, elife, crossref, pkp, copernicus, or pensoft')
  else
    return url
  end
end

#response_ok(code) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/lagotto-rb/helpers.rb', line 1

def response_ok(code)
  # See CrossCite documentation http://crosscite.org/cn/
  case code
    when 200
      return true
    when 204
      raise "The request was OK but there was no metadata available (response code: #{code})"
    when 404
      raise "The DOI requested doesn't exist (response code: #{code})"
    when 406
      raise "Can't serve any requested content type (response code: #{code})"
    when 500...600
      raise "ZOMG ERROR #{code}"
    end
end

#str_length(x) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/lagotto-rb/helpers.rb', line 27

def str_length(x)
  if x.is_a? String
    1
  else
    x.length
  end
end

#test_length(input) ⇒ Object



21
22
23
24
25
# File 'lib/lagotto-rb/helpers.rb', line 21

def test_length(input)
    if !input.is_a? NilClass and str_length(input) > 1
      raise TypeError('Parameter "source" must be either nil or length 1')
    end
end

#type_check(arg, type = String) ⇒ Object

Raises:

  • (TypeError)


17
18
19
# File 'lib/lagotto-rb/helpers.rb', line 17

def type_check(arg, type=String)
  raise TypeError unless arg.is_a? type
end