gbifrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # taken from: https://viget.com/extend/easy-gem-configuration-variables-with-defaults
2
+ module Configuration
3
+
4
+ def configuration
5
+ yield self
6
+ end
7
+
8
+ def define_setting(name, default = nil)
9
+ class_variable_set("@@#{name}", default)
10
+ define_class_method "#{name}=" do |value|
11
+ class_variable_set("@@#{name}", value)
12
+ end
13
+ define_class_method name do
14
+ class_variable_get("@@#{name}")
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def define_class_method(name, &block)
21
+ (class << self; self; end).instance_eval do
22
+ define_method name, &block
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,51 @@
1
+ require "faraday"
2
+ require "multi_json"
3
+ require "gbifrb/error"
4
+ require "gbifrb/constants"
5
+ require 'gbifrb/utils'
6
+ require 'gbifrb/helpers/configuration'
7
+
8
+ ##
9
+ # Gbif::Request
10
+ #
11
+ # Class to perform HTTP requests to the Crossref API
12
+ module Gbif
13
+ class Request #:nodoc:
14
+
15
+ attr_accessor :endpt
16
+ attr_accessor :args
17
+ attr_accessor :verbose
18
+ attr_accessor :options
19
+
20
+ def initialize(endpt, args, verbose, options)
21
+ self.endpt = endpt
22
+ self.args = args
23
+ self.verbose = verbose
24
+ self.options = options
25
+ end
26
+
27
+ def perform
28
+ if verbose
29
+ conn = Faraday.new(:url => Gbif.base_url, :request => self.options || []) do |f|
30
+ f.response :logger
31
+ f.use FaradayMiddleware::RaiseHttpException
32
+ f.options.params_encoder = Faraday::FlatParamsEncoder
33
+ f.adapter Faraday.default_adapter
34
+ end
35
+ else
36
+ conn = Faraday.new(:url => Gbif.base_url, :request => self.options || []) do |f|
37
+ f.use FaradayMiddleware::RaiseHttpException
38
+ f.options.params_encoder = Faraday::FlatParamsEncoder
39
+ f.adapter Faraday.default_adapter
40
+ end
41
+ end
42
+
43
+ conn.headers[:user_agent] = make_ua
44
+ conn.headers["X-USER-AGENT"] = make_ua
45
+
46
+ res = conn.get self.endpt, self.args
47
+ return MultiJson.load(res.body)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ ##
2
+ # Gbif::Response
3
+ #
4
+ # Class to give back response
5
+ module Gbif
6
+ class Response #:nodoc:
7
+ attr_reader :ids, :response
8
+
9
+ def initialize(ids, res)
10
+ @ids = ids
11
+ @res = res
12
+ end
13
+
14
+ def raw_body
15
+ # @res
16
+ @res.collect { |x| x.body }
17
+ end
18
+
19
+ def parsed
20
+ # JSON.parse(@res.body)
21
+ @res.collect { |x| JSON.parse(x.body) }
22
+ end
23
+
24
+ def links
25
+ # @res['message']['link']
26
+ @res.collect { |x| x['message']['link'] }
27
+ end
28
+
29
+ def pdf
30
+ tmp = links
31
+ if !tmp.nil?
32
+ tmp.collect { |z|
33
+ z.select{ |x| x['content-type'] == "application/pdf" }[0]['URL']
34
+ }
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ def make_ua
2
+ requa = 'Faraday/v' + Faraday::VERSION
3
+ habua = 'Gbif/v' + Gbif::VERSION
4
+ return requa + ' ' + habua
5
+ end
6
+
7
+ class Hash
8
+ def tostrings
9
+ Hash[self.map{|(k,v)| [k.to_s,v]}]
10
+ end
11
+ end
12
+
13
+ class Hash
14
+ def tosymbols
15
+ Hash[self.map{|(k,v)| [k.to_sym,v]}]
16
+ end
17
+ end
18
+
19
+ def check_data(x, y)
20
+ if len2(x) == 1
21
+ testdata = [x]
22
+ else
23
+ testdata = x
24
+ end
25
+
26
+ for z in testdata
27
+ if !y.include? z
28
+ raise z + ' is not one of the choices'
29
+ end
30
+ end
31
+ end
32
+
33
+ def len2(x)
34
+ if x.class == String
35
+ return [x].length
36
+ else
37
+ return x.length
38
+ end
39
+ end
40
+
41
+ def stop(x)
42
+ raise ArgumentError, x
43
+ end
44
+
45
+ # def get_meta(x)
46
+ # if has_meta(x)
47
+ # return { z: x[z] for z in ['offset','limit','endOfRecords'] }
48
+ # else
49
+ # return nil
50
+ # end
51
+ # end
52
+
53
+ # def has_meta(x)
54
+ # if x.__class__ != dict
55
+ # return false
56
+ # else
57
+ # tmp = [y in x.keys() for y in ['offset','limit','endOfRecords']]
58
+ # return True in tmp
59
+ # end
60
+ # end
@@ -0,0 +1,3 @@
1
+ module Gbif
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,276 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gbifrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Chamberlain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.14.6
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.14'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.14.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 12.0.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '12.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 12.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: test-unit
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.2.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.2.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: simplecov
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.14.1
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.14.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: codecov
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.1.10
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.1.10
101
+ - !ruby/object:Gem::Dependency
102
+ name: json
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.0'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.3
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.0.3
121
+ - !ruby/object:Gem::Dependency
122
+ name: vcr
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '3.0'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 3.0.3
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.0'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 3.0.3
141
+ - !ruby/object:Gem::Dependency
142
+ name: webmock
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '2.3'
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 2.3.2
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '2.3'
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.3.2
161
+ - !ruby/object:Gem::Dependency
162
+ name: faraday
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: 0.12.0.1
168
+ type: :runtime
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: 0.12.0.1
175
+ - !ruby/object:Gem::Dependency
176
+ name: faraday_middleware
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: 0.11.0.1
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: 0.11.0.1
189
+ - !ruby/object:Gem::Dependency
190
+ name: thor
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: 0.19.4
196
+ type: :runtime
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: 0.19.4
203
+ - !ruby/object:Gem::Dependency
204
+ name: multi_json
205
+ requirement: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: '1.12'
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: 1.12.1
213
+ type: :runtime
214
+ prerelease: false
215
+ version_requirements: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - "~>"
218
+ - !ruby/object:Gem::Version
219
+ version: '1.12'
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 1.12.1
223
+ description: Low Level Ruby Client for the GBIF API
224
+ email: myrmecocystus@gmail.com
225
+ executables: []
226
+ extensions: []
227
+ extra_rdoc_files: []
228
+ files:
229
+ - ".gitignore"
230
+ - ".travis.yml"
231
+ - CHANGELOG.md
232
+ - CONDUCT.md
233
+ - Gemfile
234
+ - Gemfile.lock
235
+ - LICENSE
236
+ - README.md
237
+ - Rakefile
238
+ - gbifrb.gemspec
239
+ - lib/gbifrb.rb
240
+ - lib/gbifrb/Occurrences.rb
241
+ - lib/gbifrb/Registry.rb
242
+ - lib/gbifrb/Species.rb
243
+ - lib/gbifrb/constants.rb
244
+ - lib/gbifrb/error.rb
245
+ - lib/gbifrb/faraday.rb
246
+ - lib/gbifrb/get_data.rb
247
+ - lib/gbifrb/helpers/configuration.rb
248
+ - lib/gbifrb/request.rb
249
+ - lib/gbifrb/response.rb
250
+ - lib/gbifrb/utils.rb
251
+ - lib/gbifrb/version.rb
252
+ homepage: https://github.com/sckott/gbifrb
253
+ licenses:
254
+ - MIT
255
+ metadata: {}
256
+ post_install_message:
257
+ rdoc_options: []
258
+ require_paths:
259
+ - lib
260
+ required_ruby_version: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '2.0'
265
+ required_rubygems_version: !ruby/object:Gem::Requirement
266
+ requirements:
267
+ - - ">="
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
270
+ requirements: []
271
+ rubyforge_project:
272
+ rubygems_version: 2.6.12
273
+ signing_key:
274
+ specification_version: 4
275
+ summary: GBIF Client
276
+ test_files: []