gbifrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80db03aa9e1bc8aeb7287ce125be05e703f0f735
4
+ data.tar.gz: ee90262c1180b85ae3d9e6fa8378ea8875460b69
5
+ SHA512:
6
+ metadata.gz: 19d373b5885fddfb769ac23ba4840ea33023b7cf9c3ed398082baea9d06a0365e8ba31f41f3052cd8df3a9b2ff275741e5950b865b08cb66410c749c56566c91
7
+ data.tar.gz: 894d983444649536bfeec0995c32525be08c28e3773f17c6506a604941f87b346caa18d1cf4db3b1b4bf0d4bbc2216b81919af5c31e4a844b3a969ebe4a88b90
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ #Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ cache/
37
+
38
+ lib/serrano/response.rb
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.4.1
7
+ script:
8
+ bundle exec rake test TESTOPTS="-v"
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2017-09-07)
2
+
3
+ * First version.
@@ -0,0 +1,25 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who
4
+ contribute through reporting issues, posting feature requests, updating documentation,
5
+ submitting pull requests or patches, and other activities.
6
+
7
+ We are committed to making participation in this project a harassment-free experience for
8
+ everyone, regardless of level of experience, gender, gender identity and expression,
9
+ sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
10
+
11
+ Examples of unacceptable behavior by participants include the use of sexual language or
12
+ imagery, derogatory comments or personal attacks, trolling, public or private harassment,
13
+ insults, or other unprofessional conduct.
14
+
15
+ Project maintainers have the right and responsibility to remove, edit, or reject comments,
16
+ commits, code, wiki edits, issues, and other contributions that are not aligned to this
17
+ Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
18
+ from the project team.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
21
+ opening an issue or contacting one or more of the project maintainers.
22
+
23
+ This Code of Conduct is adapted from the Contributor Covenant
24
+ (http:contributor-covenant.org), version 1.0.0, available at
25
+ http://contributor-covenant.org/version/1/0/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gbifrb (0.1.0)
5
+ faraday (~> 0.12.0.1)
6
+ faraday_middleware (~> 0.11.0.1)
7
+ multi_json (~> 1.12, >= 1.12.1)
8
+ thor (~> 0.19.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.5.0)
14
+ public_suffix (~> 2.0, >= 2.0.2)
15
+ codecov (0.1.10)
16
+ json
17
+ simplecov
18
+ url
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ docile (1.1.5)
22
+ faraday (0.12.0.1)
23
+ multipart-post (>= 1.2, < 3)
24
+ faraday_middleware (0.11.0.1)
25
+ faraday (>= 0.7.4, < 1.0)
26
+ hashdiff (0.3.2)
27
+ json (2.0.3)
28
+ multi_json (1.12.1)
29
+ multipart-post (2.0.0)
30
+ power_assert (0.3.1)
31
+ public_suffix (2.0.5)
32
+ rake (12.0.0)
33
+ safe_yaml (1.0.4)
34
+ simplecov (0.14.1)
35
+ docile (~> 1.1.0)
36
+ json (>= 1.8, < 3)
37
+ simplecov-html (~> 0.10.0)
38
+ simplecov-html (0.10.0)
39
+ test-unit (3.2.1)
40
+ power_assert
41
+ thor (0.19.4)
42
+ url (0.3.2)
43
+ vcr (3.0.3)
44
+ webmock (2.3.2)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.14, >= 1.14.6)
54
+ codecov (~> 0.1.10)
55
+ gbifrb!
56
+ json (~> 2.0, >= 2.0.3)
57
+ rake (~> 12.0, >= 12.0.0)
58
+ simplecov (~> 0.14.1)
59
+ test-unit (~> 3.2, >= 3.2.1)
60
+ vcr (~> 3.0, >= 3.0.3)
61
+ webmock (~> 2.3, >= 2.3.2)
62
+
63
+ BUNDLED WITH
64
+ 1.15.3
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2017 Scott Chamberlain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,127 @@
1
+ gbifrb
2
+ ======
3
+
4
+ [![gem version](https://img.shields.io/gem/v/gbifrb.svg)](https://rubygems.org/gems/gbifrb)
5
+ [![Build Status](https://travis-ci.org/sckott/gbifrb.svg?branch=master)](https://travis-ci.org/sckott/gbifrb)
6
+ [![codecov.io](http://codecov.io/github/sckott/gbifrb/coverage.svg?branch=master)](http://codecov.io/github/sckott/gbifrb?branch=master)
7
+
8
+ `gbifrb` is a low level client for the GBIF API
9
+
10
+ Other GBIF API clients:
11
+
12
+ - Python: [pygbif](https://github.com/sckott/pygbif)
13
+ - R: [rgbif](https://github.com/ropensci/rgbif)
14
+
15
+ ## Changes
16
+
17
+ For changes see the [Changelog][changelog]
18
+
19
+ ## API
20
+
21
+ Methods in relation to [GBIF API][gbifapi] routes
22
+
23
+ registry
24
+
25
+ * `/node` - `Gbif::Registry.nodes`
26
+ * `/network` - `Gbif::Registry.networks`
27
+ * `/installations` - `Gbif::Registry.installations`
28
+ * `/organizations` - `Gbif::Registry.organizations`
29
+ * `/dataset_metrics` - `Gbif::Registry.dataset_metrics`
30
+ * `/datasets` - `Gbif::Registry.datasets`
31
+ * `/dataset_suggest` - `Gbif::Registry.dataset_suggest`
32
+ * `/dataset_search` - `Gbif::Registry.dataset_search`
33
+
34
+ species
35
+
36
+ * `/species/match` - `Gbif::Species.name_backbone`
37
+ * `/species/suggest` - `Gbif::Species.name_suggest`
38
+ * `/species/search` - `Gbif::Species.name_lookup`
39
+ * `/species` - `Gbif::Species.name_usage`
40
+
41
+ occurrences
42
+
43
+ * `/search` - `Gbif::Occurrences.search`
44
+ * `/get` - `Gbif::Occurrences.get`
45
+ * `/get_verbatim` - `Gbif::Occurrences.get_verbatim`
46
+ * `/get_fragment` - `Gbif::Occurrences.get_fragment`
47
+
48
+
49
+ ## Install
50
+
51
+ ### Release version
52
+
53
+ ```
54
+ gem install gbifrb
55
+ ```
56
+
57
+ ### Development version
58
+
59
+ ```
60
+ git clone git@github.com:sckott/gbifrb.git
61
+ cd gbifrb
62
+ rake install
63
+ ```
64
+
65
+ ## Examples, in Ruby repl
66
+
67
+ ### Registry module
68
+
69
+ Nodes
70
+
71
+ ```ruby
72
+ require 'gbifrb'
73
+ registry = Gbif::Registry
74
+ registry.nodes(limit: 5)
75
+ ```
76
+
77
+ Networks
78
+
79
+ ```ruby
80
+ registry.networks(uuid: '16ab5405-6c94-4189-ac71-16ca3b753df7')
81
+ ```
82
+
83
+ ### Species module
84
+
85
+ GBIF backbone
86
+
87
+ ```ruby
88
+ species = Gbif::Species
89
+ species.name_backbone(name: "Helianthus")
90
+ ```
91
+
92
+ Suggester
93
+
94
+ ```ruby
95
+ species.name_suggest("Helianthus")
96
+ ```
97
+
98
+ ### Occurrences
99
+
100
+ ```ruby
101
+ occ = Gbif::Occurrences
102
+ occ.search(taxonKey: 3329049)
103
+ occ.search(taxonKey: 3329049, limit: 2)
104
+ occ.search(scientificName: 'Ursus americanus')
105
+ ```
106
+
107
+ ### curl options
108
+
109
+ ```ruby
110
+ species = Gbif::Species
111
+ species.name_backbone("Helianthus", verbose: true)
112
+ ```
113
+
114
+ ### Todo
115
+
116
+ * CLI interface
117
+ * occurrence metrics methods
118
+ * occurrence downloads methods
119
+ * OAI-PMH interface
120
+
121
+ ## Meta
122
+
123
+ * Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
124
+ * License: MIT
125
+
126
+ [gbifapi]: https://www.gbif.org/developer/summary
127
+ [changelog]: https://github.com/sckott/gbifrb/blob/master/CHANGELOG.md
@@ -0,0 +1,41 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test-*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :test
12
+
13
+ desc "Build gbifrb docs"
14
+ task :docs do
15
+ system "yardoc"
16
+ end
17
+
18
+ desc "bundle install"
19
+ task :bundle do
20
+ system "bundle install"
21
+ end
22
+
23
+ desc "clean out builds"
24
+ task :clean do
25
+ system "ls | grep [0-9].gem | xargs rm"
26
+ end
27
+
28
+ desc "Build gbifrb"
29
+ task :build do
30
+ system "gem build gbifrb.gemspec"
31
+ end
32
+
33
+ desc "Install gbifrb"
34
+ task :install => [:bundle, :build] do
35
+ system "gem install gbifrb-#{Gbif::VERSION}.gem"
36
+ end
37
+
38
+ desc "Release to Rubygems"
39
+ task :release => :build do
40
+ system "gem push gbifrb-#{Gbif::VERSION}.gem"
41
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gbifrb/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'gbifrb'
8
+ s.version = Gbif::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.required_ruby_version = '>= 2.0'
11
+ s.date = '2017-09-07'
12
+ s.summary = "GBIF Client"
13
+ s.description = "Low Level Ruby Client for the GBIF API"
14
+ s.authors = "Scott Chamberlain"
15
+ s.email = 'myrmecocystus@gmail.com'
16
+ s.homepage = 'https://github.com/sckott/gbifrb'
17
+ s.licenses = 'MIT'
18
+
19
+ s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'bundler', '~> 1.14', '>= 1.14.6'
23
+ s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
24
+ s.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.1'
25
+ s.add_development_dependency 'simplecov', '~> 0.14.1'
26
+ s.add_development_dependency 'codecov', '~> 0.1.10'
27
+ s.add_development_dependency 'json', '~> 2.0', '>= 2.0.3'
28
+ s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
29
+ s.add_development_dependency 'webmock', '~> 2.3', '>= 2.3.2'
30
+
31
+ s.add_runtime_dependency 'faraday', '~> 0.12.0.1'
32
+ s.add_runtime_dependency 'faraday_middleware', '~> 0.11.0.1'
33
+ s.add_runtime_dependency 'thor', '~> 0.19.4'
34
+ s.add_runtime_dependency 'multi_json', '~> 1.12', '>= 1.12.1'
35
+ end
@@ -0,0 +1,48 @@
1
+ require "gbifrb/version"
2
+ require "gbifrb/request"
3
+ require "gbifrb/Species"
4
+ require "gbifrb/Registry"
5
+ require "gbifrb/Occurrences"
6
+
7
+ # @!macro gbif_params
8
+ # @param offset [Fixnum] Number of record to start at, any non-negative integer up to 10,000
9
+ # @param limit [Fixnum] Number of results to return. Not relavant when searching with specific dois.
10
+ # Default: 20. Max: 1000
11
+ # @param sample [Fixnum] Number of random results to return. when you use the sample parameter,
12
+ # the limit and offset parameters are ignored. This parameter only used when works requested.
13
+ # Max: 100.
14
+ # @param sort [String] Field to sort on, one of score, relevance,
15
+ # updated (date of most recent change to metadata - currently the same as deposited),
16
+ # deposited (time of most recent deposit), indexed (time of most recent index), or
17
+ # published (publication date). Note: If the API call includes a query, then the sort
18
+ # order will be by the relevance score. If no query is included, then the sort order
19
+ # will be by DOI update date.
20
+ # @param order [String] Sort order, one of 'asc' or 'desc'
21
+ # @param facet [Boolean/String] Include facet results OR a query (e.g., `license:*`) to facet by
22
+ # license. Default: false
23
+ # @param verbose [Boolean] Print request headers to stdout. Default: false
24
+
25
+ # @!macro gbif_options
26
+ # @param options [Hash] Hash of options for configuring the request, passed on to Faraday.new
27
+ # - timeout [Fixnum] open/read timeout Integer in seconds
28
+ # - open_timeout [Fixnum] read timeout Integer in seconds
29
+ # - proxy [Hash] hash of proxy options
30
+ # - uri [String] Proxy Server URI
31
+ # - user [String] Proxy server username
32
+ # - password [String] Proxy server password
33
+ # - params_encoder [Hash] not sure what this is
34
+ # - bind [Hash] A hash with host and port values
35
+ # - boundary [String] of the boundary value
36
+ # - oauth [Hash] A hash with OAuth details
37
+
38
+ ##
39
+ # gbif - The top level module for using methods to access the GBIF API
40
+
41
+ module Gbif
42
+ extend Configuration
43
+
44
+ define_setting :user_name
45
+ define_setting :pwd
46
+ define_setting :base_url, "https://api.gbif.org/v1"
47
+
48
+ end
@@ -0,0 +1,399 @@
1
+ require "faraday"
2
+ require 'faraday_middleware'
3
+ require "multi_json"
4
+ require "gbifrb/error"
5
+ require "gbifrb/request"
6
+ require "gbifrb/constants"
7
+ require 'gbifrb/helpers/configuration'
8
+ require 'gbifrb/faraday'
9
+ require 'gbifrb/utils'
10
+
11
+ ##
12
+ # Gbif::Occurrences
13
+ module Gbif
14
+ module Occurrences
15
+ ##
16
+ # Search GBIF occurrences
17
+ #
18
+ # @param taxonKey [int] A GBIF occurrence identifier
19
+ # @param q [String] Simple search parameter. The value for this parameter can be a simple word or a phrase.
20
+ # @param spellCheck [bool] If 'true' ask GBIF to check your spelling of the value passed to the 'search' parameter.
21
+ # IMPORTANT: This only checks the input to the 'search' parameter, and no others. Default: 'false'
22
+ # @param repatriated [String] Searches for records whose publishing country is different to the country where the record was recorded in
23
+ # @param kingdomKey [int] Kingdom classification key
24
+ # @param phylumKey [int] Phylum classification key
25
+ # @param classKey [int] Class classification key
26
+ # @param orderKey [int] Order classification key
27
+ # @param familyKey [int] Family classification key
28
+ # @param genusKey [int] Genus classification key
29
+ # @param subgenusKey [int] Subgenus classification key
30
+ # @param scientificName [String] A scientific name from the GBIF backbone. All included and synonym taxa are included in the search.
31
+ # @param datasetKey [String] The occurrence dataset key (a uuid)
32
+ # @param catalogNumber [String] An identifier of any form assigned by the source within a physical collection or digital dataset for the record which may not unique, but should be fairly unique in combination with the institution and collection code.
33
+ # @param recordedBy [String] The person who recorded the occurrence.
34
+ # @param collectionCode [String] An identifier of any form assigned by the source to identify the physical collection or digital dataset uniquely within the text of an institution.
35
+ # @param institutionCode [String] An identifier of any form assigned by the source to identify the institution the record belongs to. Not guaranteed to be que.
36
+ # @param country [String] The 2-letter country code (as per ISO-3166-1) of the country in which the occurrence was recorded. See here http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
37
+ # @param basisOfRecord [String] Basis of record, as defined in our BasisOfRecord enum here http://gbif.github.io/gbif-api/apidocs/org/gbifrb/api/vocabulary/BasisOfRecord.html Acceptable values are:
38
+ # - 'FOSSIL_SPECIMEN' An occurrence record describing a fossilized specimen.
39
+ # - 'HUMAN_OBSERVATION' An occurrence record describing an observation made by one or more people.
40
+ # - 'LITERATURE' An occurrence record based on literature alone.
41
+ # - 'LIVING_SPECIMEN' An occurrence record describing a living specimen, e.g.
42
+ # - 'MACHINE_OBSERVATION' An occurrence record describing an observation made by a machine.
43
+ # - 'OBSERVATION' An occurrence record describing an observation.
44
+ # - 'PRESERVED_SPECIMEN' An occurrence record describing a preserved specimen.
45
+ # - 'UNKNOWN' Unknown basis for the record.
46
+ ## @param eventDate [date] Occurrence date in ISO 8601 format: yyyy, yyyy-MM, yyyy-MM-dd, or
47
+ # MM-dd. Supports range queries, smaller,larger (e.g., '1990,1991', whereas '1991,1990'
48
+ # wouldn't work)
49
+ # @param year [int] The 4 digit year. A year of 98 will be interpreted as AD 98. Supports range queries,
50
+ # smaller,larger (e.g., '1990,1991', whereas '1991,1990' wouldn't work)
51
+ # @param month [int] The month of the year, starting with 1 for January. Supports range queries,
52
+ # smaller,larger (e.g., '1,2', whereas '2,1' wouldn't work)
53
+ # @param decimalLatitude [float] Latitude in decimals between -90 and 90 based on WGS 84.
54
+ # Supports range queries, smaller,larger (e.g., '25,30', whereas '30,25' wouldn't work)
55
+ # @param decimalLongitude [float] Longitude in decimals between -180 and 180 based on WGS 84.
56
+ # Supports range queries (e.g., '-0.4,-0.2', whereas '-0.2,-0.4' wouldn't work).
57
+ # @param publishingCountry [String] The 2-letter country code (as per ISO-3166-1) of the
58
+ # country in which the occurrence was recorded.
59
+ # @param elevation [int/str] Elevation in meters above sea level. Supports range queries, smaller,larger
60
+ # (e.g., '5,30', whereas '30,5' wouldn't work)
61
+ # @param depth [int/str] Depth in meters relative to elevation. For example 10 meters below a
62
+ # lake surface with given elevation. Supports range queries, smaller,larger (e.g., '5,30',
63
+ # whereas '30,5' wouldn't work)
64
+ # @param geometry [String] Searches for occurrences inside a polygon described in Well Known
65
+ # Text (WKT) format. A WKT shape written as either POINT, LINESTRING, LINEARRING
66
+ # POLYGON, or MULTIPOLYGON. Example of a polygon: '((30.1 10.1, 20, 20 40, 40 40, 30.1 10.1))' would be queried as http://bit.ly/1BzNwDq.
67
+ # @param hasGeospatialIssue [bool] Includes/excludes occurrence records which contain spatial
68
+ # issues (as determined in our record interpretation), i.e. 'hasGeospatialIssue=TRUE'
69
+ # returns only those records with spatial issues while 'hasGeospatialIssue=FALSE' includes
70
+ # only records without spatial issues. The absence of this parameter returns any
71
+ # record with or without spatial issues.
72
+ # @param issue [String] One or more of many possible issues with each occurrence record. See
73
+ # Details. Issues passed to this parameter filter results by the issue.
74
+ # @param hasCoordinate [bool] Return only occurence records with lat/long data ('true') or
75
+ # all records ('false', default).
76
+ # @param typeStatus [String] Type status of the specimen. One of many options. See ?typestatus
77
+ # @param recordNumber [int] Number recorded by collector of the data, different from GBIF record
78
+ # number. See http://rs.tdwg.org/dwc/terms/#recordNumber} for more info
79
+ # @param lastInterpreted [date] Date the record was last modified in GBIF, in ISO 8601 format:
80
+ # yyyy, yyyy-MM, yyyy-MM-dd, or MM-dd. Supports range queries, smaller,larger (e.g.,
81
+ # '1990,1991', whereas '1991,1990' wouldn't work)
82
+ # @param continent [String] Continent. One of 'africa', 'antarctica', 'asia', 'europe', 'north_america'
83
+ # (North America includes the Caribbean and reachies down and includes Panama), 'oceania',
84
+ # or 'south_america'
85
+ # @param mediatype [String] Media type. Default is 'NULL', so no filtering on mediatype. Options:
86
+ # 'NULL', 'MovingImage', 'Sound', and 'StillImage'
87
+ # @param limit [int] Number of results to return. Default: '300'
88
+ # @param offset [int] Record to start at. Default: '0'
89
+ # @param verbose [Boolean] Print request headers to stdout. Default: false
90
+ # @param facet [String] a character vector of length 1 or greater
91
+ # @param establishmentMeans [String] EstablishmentMeans, possible values include: INTRODUCED,
92
+ # INVASIVE, MANAGED, NATIVE, NATURALISED, UNCERTAIN
93
+ # @param facetMincount [int] minimum number of records to be included in the faceting results
94
+ # @param facetMultiselect [bool] Set to 'true' to still return counts for values that are not currently
95
+ # filtered. See examples. Default: 'false'
96
+ # @!macro gbif_options
97
+ #
98
+ # @return [Hash] A hash
99
+ #
100
+ # @example
101
+ # require 'gbifrb'
102
+ # occ = Gbif::Occurrences
103
+ #
104
+ # occ.search(taxonKey: 3329049)
105
+ #
106
+ # # Return 2 results, this is the default by the way
107
+ # occ.search(taxonKey: 3329049, limit: 2)
108
+ #
109
+ # # Instead of getting a taxon key first, you can search for a name directly
110
+ # # However, note that using this approach (with `scientificName="..."`)
111
+ # # you are getting synonyms too. The results for using `scientifcName` and
112
+ # # `taxonKey` parameters are the same in this case, but I wouldn't be surprised if for some
113
+ # # names they return different results
114
+ # occ.search(scientificName: 'Ursus americanus')
115
+ # species = Gbif::Species
116
+ # key = species.name_backbone(name: 'Ursus americanus', rank: 'species')['usageKey']
117
+ # occ.search(taxonKey: key)
118
+ #
119
+ # # Search by dataset key
120
+ # occ.search(datasetKey: '7b5d6a48-f762-11e1-a439-00145eb45e9a', limit: 20)
121
+ #
122
+ # # Search by catalog number
123
+ # occ.search(catalogNumber: "49366", limit: 20)
124
+ # occ.search(catalogNumber: ["49366","Bird.27847588"], limit: 20)
125
+ #
126
+ # # Use paging parameters (limit and offset) to page. Note the different results
127
+ # # for the two queries below.
128
+ # occ.search(datasetKey: '7b5d6a48-f762-11e1-a439-00145eb45e9a', offset: 10, limit: 5)
129
+ # occ.search(datasetKey: '7b5d6a48-f762-11e1-a439-00145eb45e9a', offset: 20, limit: 5)
130
+ #
131
+ # # Many dataset keys
132
+ # # occ.search(datasetKey: ["50c9509d-22c7-4a22-a47d-8c48425ef4a7", "7b5d6a48-f762-11e1-a439-00145eb45e9a"], limit: 20)
133
+ # # Search by collector name
134
+ # occ.search(recordedBy: "smith", limit: 20)
135
+ #
136
+ # # Many collector names
137
+ # occ.search(recordedBy: ["smith","BJ Stacey"], limit: 20)
138
+ #
139
+ # # Search for many species
140
+ # species = Gbif::Species
141
+ # splist = ['Cyanocitta stelleri', 'Junco hyemalis', 'Aix sponsa']
142
+ # keys = splist.map { |x| species.name_suggest(q: x)[0]['key'] }
143
+ # out = keys.map { |z| occ.search(taxonKey: z, limit: 1) }
144
+ # out.collect{ |b| b['results'][0]['speciesKey'] }
145
+ #
146
+ # # Search - q parameter
147
+ # occ.search(q: "kingfisher", limit: 20)
148
+ #
149
+ # ## spell check - only works with the `search` parameter
150
+ # ### spelled correctly - same result as above call
151
+ # occ.search(q: "kingfisher", limit: 20, spellCheck: true)
152
+ # ### spelled incorrectly - stops with suggested spelling
153
+ # occ.search(q: "kajsdkla", limit: 20, spellCheck: true)
154
+ # ### spelled incorrectly - stops with many suggested spellings
155
+ # ### and number of results for each
156
+ # occ.search(q: "helir", limit: 20, spellCheck: true)
157
+ #
158
+ # # Search on latitidue and longitude
159
+ # occ.search(decimalLatitude: 50, decimalLongitude: 10, limit: 2)
160
+ #
161
+ # # Search on a bounding box
162
+ # ## in well known text format
163
+ # occ.search(geometry: 'POLYGON((30.1 10.1, 10 20, 20 40, 40 40, 30.1 10.1))', limit: 20)
164
+ # species = Gbif::Species
165
+ # key = species.name_suggest(q: 'Aesculus hippocastanum')[0]['key']
166
+ # occ.search(taxonKey: key, geometry: 'POLYGON((30.1 10.1, 10 20, 20 40, 40 40, 30.1 10.1))', limit: 20)
167
+ #
168
+ # ## multipolygon
169
+ # wkt = 'MULTIPOLYGON(((-123 38, -123 43, -116 43, -116 38, -123 38)),((-97 41, -97 45, -93 45, -93 41, -97 41)))'
170
+ # occ.search(geometry: wkt, limit: 20)
171
+ #
172
+ # # Search on country
173
+ # occ.search(country: 'US', limit: 20)
174
+ # occ.search(country: 'FR', limit: 20)
175
+ # occ.search(country: 'DE', limit: 20)
176
+ #
177
+ # # Get only occurrences with lat/long data
178
+ # occ.search(taxonKey: key, hasCoordinate: true, limit: 20)
179
+ #
180
+ # # Get only occurrences that were recorded as living specimens
181
+ # occ.search(taxonKey: key, basisOfRecord: "LIVING_SPECIMEN", hasCoordinate: true, limit: 20)
182
+ #
183
+ # # Get occurrences for a particular eventDate
184
+ # occ.search(taxonKey: key, eventDate: "2013", limit: 20)
185
+ # occ.search(taxonKey: key, year: "2013", limit: 20)
186
+ # occ.search(taxonKey: key, month: "6", limit: 20)
187
+ #
188
+ # # Get occurrences based on depth
189
+ # key = species.name_backbone(name: 'Salmo salar', kingdom: 'animals')['usageKey']
190
+ # occ.search(taxonKey: key, depth: "5", limit: 20)
191
+ #
192
+ # # Get occurrences based on elevation
193
+ # key = species.name_backbone(name: 'Puma concolor', kingdom: 'animals')['usageKey']
194
+ # occ.search(taxonKey: key, elevation: 50, hasCoordinate: true, limit: 20)
195
+ #
196
+ # # Get occurrences based on institutionCode
197
+ # occ.search(institutionCode: "TLMF", limit: 20)
198
+ #
199
+ # # Get occurrences based on collectionCode
200
+ # occ.search(collectionCode: "Floristic Databases MV - Higher Plants", limit: 20)
201
+ #
202
+ # # Get only those occurrences with spatial issues
203
+ # occ.search(taxonKey: key, hasGeospatialIssue: true, limit: 20)
204
+ #
205
+ # # Search using a query string
206
+ # occ.search(q: "kingfisher", limit: 20)
207
+ #
208
+ # # Range queries
209
+ # ## See Detail for parameters that support range queries
210
+ # ### this is a range depth, with lower/upper limits in character string
211
+ # occ.search(depth: '50,100')
212
+ #
213
+ # ## Range search with year
214
+ # occ.search(year: '1999,2000', limit: 20)
215
+ #
216
+ # ## Range search with latitude
217
+ # occ.search(decimalLatitude: '29.59,29.6')
218
+ #
219
+ # # Search by specimen type status
220
+ # ## Look for possible values of the typeStatus parameter looking at the typestatus dataset
221
+ # occ.search(typeStatus: 'allotype')
222
+ #
223
+ # # Search by specimen record number
224
+ # ## This is the record number of the person/group that submitted the data, not GBIF's numbers
225
+ # ## You can see that many different groups have record number 1, so not super helpful
226
+ # occ.search(recordNumber: 1)
227
+ #
228
+ # # Search by last time interpreted: Date the record was last modified in GBIF
229
+ # ## The lastInterpreted parameter accepts ISO 8601 format dates, including
230
+ # ## yyyy, yyyy-MM, yyyy-MM-dd, or MM-dd. Range queries are accepted for lastInterpreted
231
+ # occ.search(lastInterpreted: '2014-04-01')
232
+ #
233
+ # # Search by continent
234
+ # ## One of africa, antarctica, asia, europe, north_america, oceania, or south_america
235
+ # occ.search(continent: 'south_america')
236
+ # occ.search(continent: 'africa')
237
+ # occ.search(continent: 'oceania')
238
+ # occ.search(continent: 'antarctica')
239
+ #
240
+ # # Search for occurrences with images
241
+ # occ.search(mediatype: 'StillImage')
242
+ # occ.search(mediatype: 'MovingImage')
243
+ # occ.search(mediatype: 'Sound')
244
+ #
245
+ # # Query based on issues
246
+ # occ.search(taxonKey: 1, issue: 'DEPTH_UNLIKELY')
247
+ # occ.search(taxonKey: 1, issue: ['DEPTH_UNLIKELY','COORDINATE_ROUNDED'])
248
+ # # Show all records in the Arizona State Lichen Collection that cant be matched to the GBIF
249
+ # # backbone properly:
250
+ # occ.search(datasetKey: '84c0e1a0-f762-11e1-a439-00145eb45e9a', issue: ['TAXON_MATCH_nil','TAXON_MATCH_HIGHERRANK'])
251
+ #
252
+ # # If you pass in an invalid polygon you get hopefully informative errors
253
+ # ### the WKT string is fine, but GBIF says bad polygon
254
+ # wkt = 'POLYGON((-178.59375 64.83258989321493,-165.9375 59.24622380205539,
255
+ # -147.3046875 59.065977905449806,-130.78125 51.04484764446178,-125.859375 36.70806354647625,
256
+ # -112.1484375 23.367471303759686,-105.1171875 16.093320185359257,-86.8359375 9.23767076398516,
257
+ # -82.96875 2.9485268155066175,-82.6171875 -14.812060061226388,-74.8828125 -18.849111862023985,
258
+ # -77.34375 -47.661687803329166,-84.375 -49.975955187343295,174.7265625 -50.649460483096114,
259
+ # 179.296875 -42.19189902447192,-176.8359375 -35.634976650677295,176.8359375 -31.835565983656227,
260
+ # 163.4765625 -6.528187613695323,152.578125 1.894796132058301,135.703125 4.702353722559447,
261
+ # 127.96875 15.077427674847987,127.96875 23.689804541429606,139.921875 32.06861069132688,
262
+ # 149.4140625 42.65416193033991,159.2578125 48.3160811030533,168.3984375 57.019804336633165,
263
+ # 178.2421875 59.95776046458139,-179.6484375 61.16708631440347,-178.59375 64.83258989321493))'
264
+ # occ.search(geometry: wkt)
265
+ #
266
+ # # Faceting
267
+ # ## return no occurrence records with limit: 0
268
+ # x = occ.search(facet: "country", limit: 0)
269
+ # x['facets']
270
+ #
271
+ # ## also return occurrence records
272
+ # x = occ.search(facet: "establishmentMeans", limit: 10)
273
+ # x['facets']
274
+ # x['results']
275
+ #
276
+ # ## multiple facet variables
277
+ # x = occ.search(facet: ["country", "basisOfRecord"], limit: 10)
278
+ # x['results']
279
+ # x['facets']
280
+ # x['facets']['country']
281
+ # x['facets']['basisOfRecord']
282
+ # x['facets']['basisOfRecord']['count']
283
+ #
284
+ # ## set a minimum facet count
285
+ # x = occ.search(facet: "country", facetMincount: 30000000L, limit: 0)
286
+ # x['facets']
287
+ #
288
+ # ## paging per each faceted variable
289
+ # ### do so by passing in variables like "country" + "_facetLimit" = "country_facetLimit"
290
+ # ### or "country" + "_facetOffset" = "country_facetOffset"
291
+ # x = occ.search(
292
+ # facet: ["country", "basisOfRecord", "hasCoordinate"],
293
+ # country_facetLimit: 3,
294
+ # basisOfRecord_facetLimit: 6,
295
+ # limit: 0
296
+ # )
297
+ # x['facets']
298
+ #
299
+ # # requests package options
300
+ # ## There's an acceptable set of requests options (['timeout', 'cookies', 'auth',
301
+ # ## 'allow_redirects', 'proxies', 'verify', 'stream', 'cert']) you can pass
302
+ # ## in via **kwargs, e.g., set a timeout
303
+ # x = occ.search(timeout: 1)
304
+
305
+ def self.search(taxonKey: nil, repatriated: nil,
306
+ kingdomKey: nil, phylumKey: nil, classKey: nil, orderKey: nil,
307
+ familyKey: nil, genusKey: nil, subgenusKey: nil, scientificName: nil,
308
+ country: nil, publishingCountry: nil, hasCoordinate: nil, typeStatus: nil,
309
+ recordNumber: nil, lastInterpreted: nil, continent: nil,
310
+ geometry: nil, recordedBy: nil, basisOfRecord: nil, datasetKey: nil,
311
+ eventDate: nil, catalogNumber: nil, year: nil, month: nil,
312
+ decimalLatitude: nil, decimalLongitude: nil, elevation: nil,
313
+ depth: nil, institutionCode: nil, collectionCode: nil,
314
+ hasGeospatialIssue: nil, issue: nil, q: nil, spellCheck: nil, mediatype: nil,
315
+ limit: 300, offset: 0, establishmentMeans: nil,
316
+ facet: nil, facetMincount: nil, facetMultiselect: nil,
317
+ verbose: nil, options: nil)
318
+
319
+ arguments = { taxonKey: taxonKey, repatriated: repatriated,
320
+ kingdomKey: kingdomKey, phylumKey: phylumKey, classKey: classKey,
321
+ orderKey: orderKey, familyKey: familyKey, genusKey: genusKey,
322
+ subgenusKey: subgenusKey, scientificName: scientificName,
323
+ country: country, publishingCountry: publishingCountry,
324
+ hasCoordinate: hasCoordinate, typeStatus: typeStatus,
325
+ recordNumber: recordNumber, lastInterpreted: lastInterpreted,
326
+ continent: continent, geometry: geometry, recordedBy: recordedBy,
327
+ basisOfRecord: basisOfRecord, datasetKey: datasetKey, eventDate: eventDate,
328
+ catalogNumber: catalogNumber, year: year, month: month,
329
+ decimalLatitude: decimalLatitude, decimalLongitude: decimalLongitude,
330
+ elevation: elevation, depth: depth, institutionCode: institutionCode,
331
+ collectionCode: collectionCode, hasGeospatialIssue: hasGeospatialIssue,
332
+ issue: issue, q: q, spellCheck: spellCheck, mediatype: mediatype,
333
+ limit: limit, offset: offset, establishmentMeans: establishmentMeans,
334
+ facetMincount: facetMincount, facet: facet,
335
+ facetMultiselect: facetMultiselect}.tostrings
336
+ opts = arguments.delete_if { |k, v| v.nil? }
337
+ return Request.new('occurrence/search', opts, verbose, options).perform
338
+ end
339
+
340
+ ##
341
+ # Gets details for a single, interpreted occurrence
342
+ #
343
+ # @param key [int] A GBIF occurrence key
344
+ #
345
+ # @return [hash]
346
+ #
347
+ # @example
348
+ #
349
+ # require 'gbifrb'
350
+ #
351
+ # occ = Gbif::Occurrences
352
+ # occ.get(key: 1258202889)
353
+ # occ.get(key: 1227768771)
354
+ def self.get(key:, verbose: nil, options: nil)
355
+ url = 'occurrence/' + key.to_s
356
+ Request.new(url, {}, verbose, options).perform
357
+ end
358
+
359
+ ##
360
+ # Gets a verbatim occurrence record without any interpretation
361
+ #
362
+ # @param key [int] A GBIF occurrence key
363
+ #
364
+ # @return [hash]
365
+ #
366
+ # @example
367
+ #
368
+ # require 'gbifrb'
369
+ #
370
+ # occ = Gbif::Occurrences
371
+ # occ.get_verbatim(key: 1258202889)
372
+ # occ.get_verbatim(key: 1227768771)
373
+ def self.get_verbatim(key:, verbose: nil, options: nil)
374
+ url = 'occurrence/' + key.to_s + '/verbatim'
375
+ Request.new(url, {}, verbose, options).perform
376
+ end
377
+
378
+ ##
379
+ # Get a single occurrence fragment in its raw form (xml or json)
380
+ #
381
+ # @param key [int] A GBIF occurrence key
382
+ #
383
+ # @return: [hash]
384
+ #
385
+ # @example
386
+ #
387
+ # require 'gbifrb'
388
+ #
389
+ # occ = Gbif::Occurrences
390
+ # occ.get_fragment(key: 1052909293)
391
+ # occ.get_fragment(key: 1227768771)
392
+ # occ.get_fragment(key: 1227769518)
393
+ def self.get_fragment(key:, verbose: nil, options: nil)
394
+ url = 'occurrence/' + key.to_s + '/fragment'
395
+ Request.new(url, {}, verbose, options).perform
396
+ end
397
+
398
+ end
399
+ end