Module: Lagotto

Defined in:
lib/lagotto-rb.rb,
lib/lagotto-rb/req.rb,
lib/lagotto-rb/request.rb,
lib/lagotto-rb/version.rb

Overview

Lagotto::Request

Defined Under Namespace

Classes: BasicRequest, Request

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.docs(id: nil, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/docs` route request

Examples:

Lagotto.docs()
Lagotto.docs(instance: 'crossref')
Lagotto.docs(id: 'counter', instance: 'crossref')

Parameters:

  • id (Fixnum) (defaults to: nil)

    Document id

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



255
256
257
258
259
260
261
# File 'lib/lagotto-rb.rb', line 255

def self.docs(id: nil, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/docs'
  if !id.nil?
    url = url + '/' + id.to_s
  end
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.events(ids: nil, type: nil, source: nil, publisher: nil, order: nil, per_page: 50, page: 1, instance: 'plos', key: nil, options: nil, verbose: false) ⇒ Hash

Make a ‘/events` route request

Examples:

# Get events by DOI
## swap out the key and instance to change provider
Lagotto.events(ids: '10.1371/journal.pone.0029797', instance: "crossref")
Lagotto.events(ids: ['10.1371/journal.pone.0029797','10.1016/j.dsr2.2010.10.029'], instance: "crossref")
Lagotto.events(ids: '10.4081/audiores.2013.e1', instance: "pkp")
Lagotto.events(ids: "10.1371/journal.pone.0029797")
ids = ["10.1371/journal.pone.0029797","10.1371/journal.pone.0029798"]
Lagotto.events(ids: ids)

# Search by source
Lagotto.events(source: 'twitter', instance: "crossref")
Lagotto.events(instance: "crossref", per_page: 5)

# Get data by publisher
ids = Faraday.new(:url => "http://api.crossref.org/members").get
json = MultiJson.load(ids.body)
ids = json['message']['items'].collect { |p| p['id'] }
Lagotto.events(publisher: ids[0])

Parameters:

  • ids (String) (defaults to: nil)

    one or more work identifier

  • type (String) (defaults to: nil)

    One of doi, pmid, pmcid, or mendeley_uuid

  • source (String) (defaults to: nil)

    One source. To get many sources, make many calls.

  • publisher (String) (defaults to: nil)

    Filter articles to a given publisher, using a crossref_id.

  • order (String) (defaults to: nil)

    Results are sorted by descending event count when given the source name, e.g. ‘&order=wikipedia`. Otherwise (the default) results are sorted by date descending. When using `&source=x`, we can only sort by data or that source, not a different source.

  • per_page (String) (defaults to: 50)

    Items per page

  • page (String) (defaults to: 1)

    Page to retrieve

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • key (String) (defaults to: nil)

    API key

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/lagotto-rb.rb', line 138

def self.events(ids: nil, type: nil, source: nil, publisher: nil,
  order: nil, per_page: 50, page: 1, instance: 'plos', key: nil,
  options: nil, verbose: false)

  test_length(source)
  type_check(page, Fixnum)
  type_check(per_page, Fixnum)
  url = pick_url(instance)
  ids = join_ids(ids)
  Request.new(url, 'events', ids, type, source,
    publisher, order, per_page, page, key, options, verbose).perform
end

.groups(id: nil, page: 1, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/groups` route request

Examples:

Lagotto.groups()
Lagotto.groups(instance: 'crossref')
Lagotto.groups(id: 'recommended', instance: 'crossref')

Parameters:

  • id (Fixnum) (defaults to: nil)

    Group id

  • page (String) (defaults to: 1)

    Page to retrieve

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



187
188
189
190
191
192
193
# File 'lib/lagotto-rb.rb', line 187

def self.groups(id: nil, page: 1, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/groups'
  if !id.nil?
    url = url + '/' + id.to_s
  end
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.publishers(id: nil, page: 1, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/publishers` route request

Examples:

Lagotto.publishers()
Lagotto.publishers(id: 340)
Lagotto.publishers(instance: 'crossref')

Parameters:

  • id (Fixnum) (defaults to: nil)

    Publisher id

  • page (String) (defaults to: 1)

    Page to retrieve

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



165
166
167
168
169
170
171
# File 'lib/lagotto-rb.rb', line 165

def self.publishers(id: nil, page: 1, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/publishers'
  if !id.nil?
    url = url + '/' + id.to_s
  end
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.recommendations(id:, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/recommendations` route request

Examples:

Lagotto.recommendations(id: '10.1371/journal.ppat.1005123')
Lagotto.recommendations(id: '10.1371/journal.pgen.1005625')

Parameters:

  • id (Fixnum)

    A work id

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



317
318
319
320
# File 'lib/lagotto-rb.rb', line 317

def self.recommendations(id:, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/works/' + id.to_s + '/recommendations'
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.references(work_id: nil, work_ids: nil, q: nil, relation_type_id: nil, source_id: nil, page: 1, per_page: 1000, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/references` route request

Returns list of references for a particular work, source and/or relation_type

Examples:

Lagotto.references(per_page: 5, instance: 'crossref')
Lagotto.references(work_id: 'http://doi.org/10.6084/M9.FIGSHARE.1598061', instance: 'crossref')

Parameters:

  • work_id (String) (defaults to: nil)

    Work ID

  • work_ids (String) (defaults to: nil)

    Work IDs

  • q (String) (defaults to: nil)

    Query for ids

  • relation_type_id (String) (defaults to: nil)

    Relation_type ID

  • source_id (String) (defaults to: nil)

    Source ID

  • page (String) (defaults to: 1)

    Page number

  • per_page (String) (defaults to: 1000)

    Results per page (0-1000), Default: 1000

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



215
216
217
218
219
220
221
222
223
224
# File 'lib/lagotto-rb.rb', line 215

def self.references(work_id: nil, work_ids: nil, q: nil, relation_type_id: nil,
  source_id: nil, page: 1, per_page: 1000,
  instance: 'plos', options: nil, verbose: false)

  url = pick_url(instance)
  args = { work_id: work_id, work_ids: work_ids, q: q,
    relation_type_id: relation_type_id, source_id: source_id,
    page: page, per_page: per_page }
  BasicRequest.new(url, 'references', nil, options, verbose, args).perform
end

.relation_types(id: nil, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/relation_types` route request

Examples:

Lagotto.relation_types()
Lagotto.relation_types(instance: 'crossref')
Lagotto.relation_types(id: 'corrects', instance: 'crossref')

Parameters:

  • id (Fixnum) (defaults to: nil)

    Relation type id

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



276
277
278
279
280
281
282
# File 'lib/lagotto-rb.rb', line 276

def self.relation_types(id: nil, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/relation_types'
  if !id.nil?
    url = url + '/' + id.to_s
  end
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.sources(id: nil, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/sources` route request

Examples:

Lagotto.sources(instance: 'datacite')
Lagotto.sources(instance: 'crossref')
Lagotto.sources(id: 'reddit', instance: 'crossref')

Parameters:

  • id (Fixnum) (defaults to: nil)

    Source id

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



297
298
299
300
301
302
303
# File 'lib/lagotto-rb.rb', line 297

def self.sources(id: nil, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance) + '/sources'
  if !id.nil?
    url = url + '/' + id.to_s
  end
  BasicRequest.new(url, '', nil, options, verbose, {}).perform
end

.status(key: nil, instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/status` route request

Examples:

require 'lagotto-rb'
Lagotto.status(key: ENV['PLOS_API_KEY'])
Lagotto.status(key: ENV['PLOS_API_KEY'])

Parameters:

  • key (String) (defaults to: nil)

    API key

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



335
336
337
338
# File 'lib/lagotto-rb.rb', line 335

def self.status(key: nil, instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance)
  BasicRequest.new(url, 'status', key, options, verbose, {}).perform
end

.work_types(instance: 'plos', options: nil, verbose: false) ⇒ Hash

Make a ‘/work_types` route request

Examples:

Lagotto.work_types()
Lagotto.work_types(instance: 'crossref')

Parameters:

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



237
238
239
240
# File 'lib/lagotto-rb.rb', line 237

def self.work_types(instance: 'plos', options: nil, verbose: false)
  url = pick_url(instance)
  BasicRequest.new(url, 'work_types', nil, options, verbose, {}).perform
end

.works(ids: nil, type: nil, source: nil, publisher: nil, order: nil, per_page: 50, page: 1, instance: 'plos', key: nil, options: nil, verbose: false) ⇒ Hash

Make a ‘/works` route request

Examples:

require 'lagotto-rb'
Lagotto.works(ids: 'http://doi.org/10.15468/DL.SQNY5P', instance: "crossref")
Lagotto.works(ids: ['http://doi.org/10.1371/journal.pone.0029797','http://doi.org/10.1016/j.dsr2.2010.10.029'], instance: "crossref")
Lagotto.works(ids: 'http://doi.org/10.1371/journal.pone.0025110', instance: "plos")
ids = ["http://doi.org/10.1371/journal.pone.0029797","http://doi.org/10.1371/journal.pone.0029798"]
Lagotto.works(ids: ids, instance: "plos")
Lagotto.works(ids: '10.4081/audiores.2013.e1', key: ENV['PKP_API_KEY'], instance: "pkp")

# Search by source
Lagotto.works(source: 'twitter', instance: "crossref")
Lagotto.works(instance: "crossref", per_page: 5)

# get by publisher
Lagotto.works(publisher: 311)

Parameters:

  • ids (String) (defaults to: nil)

    one or more work identifier

  • type (String) (defaults to: nil)

    One of doi, pmid, pmcid, or mendeley_uuid

  • source (String) (defaults to: nil)

    One source. To get many sources, make many calls.

  • publisher (String) (defaults to: nil)

    Filter articles to a given publisher, using a crossref_id.

  • order (String) (defaults to: nil)

    Results are sorted by descending event count when given the source name, e.g. ‘&order=wikipedia`. Otherwise (the default) results are sorted by date descending. When using `&source=x`, we can only sort by data or that source, not a different source.

  • per_page (String) (defaults to: 50)

    Items per page

  • page (String) (defaults to: 1)

    Page to retrieve

  • instance (String) (defaults to: 'plos')

    One of plos, crossref, pkp, elife, copernicus, pensoft

  • key (String) (defaults to: nil)

    API key

  • verbose (Boolean) (defaults to: false)

    Print request headers to stdout. Default: false

  • options (Hash) (defaults to: nil)

    Hash of options for configuring the request, passed on to Faraday.new :timeout - [Fixnum] open/read timeout Integer in seconds :open_timeout - [Fixnum] read timeout Integer in seconds :proxy - [Hash] hash of proxy options

    :uri - [String] Proxy Server URI
    :user - [String] Proxy server username
    :password - [String] Proxy server password
    

    :params_encoder - [Hash] not sure what this is :bind - [Hash] A hash with host and port values :boundary - [String] of the boundary value :oauth - [Hash] A hash with OAuth details

Returns:

  • (Hash)

    A hash



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lagotto-rb.rb', line 67

def self.works(ids: nil, type: nil, source: nil, publisher: nil,
          order: nil, per_page: 50, page: 1, instance: 'plos', key: nil,
          options: nil, verbose: false)

  test_length(source)
  type_check(page, Fixnum)
  type_check(per_page, Fixnum)
  # test_values('id_type', id_type, ['doi','pmid','pmcid','mendeley_uuid'])
  # test_values('instance', instance, ['plos','crossref','copernicus','elife','pensoft','pkp'])

  url = pick_url(instance)
  ids = join_ids(ids)
  Request.new(url, 'works', ids, type, source,
    publisher, order, per_page, page, key, options, verbose).perform
end

.works_sources(source: nil, per_page: 50, page: 1, instance: 'plos', key: nil, options: nil, verbose: false) ⇒ Object

# many sources

sources = ['facebook','twitter','mendeley']
sources.collect { |x| Lagotto.works_sources(source: x, per_page: 1) }


104
105
106
107
108
109
110
# File 'lib/lagotto-rb.rb', line 104

def self.works_sources(source: nil, per_page: 50, page: 1, instance: 'plos', key: nil,
  options: nil, verbose: false)

  url = pick_url(instance)
  Request.new(url, 'works', nil, nil, source,
    nil, nil, per_page, page, key, options, verbose).perform
end