chemspider 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +1 -0
- data/VERSION +1 -1
- data/lib/chem_spider.rb +45 -49
- data/lib/chem_spider/version.rb +1 -1
- metadata +27 -8
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Mark Borkum <m.i.borkum@soton.ac.uk>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/chem_spider.rb
CHANGED
@@ -4,6 +4,10 @@ require 'date'
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'uri'
|
6
6
|
|
7
|
+
##
|
8
|
+
# ChemSpider.rb: ChemSpider wrapped up with a Ruby bow.
|
9
|
+
#
|
10
|
+
# @see http://www.chemspider.com/AboutServices.aspx
|
7
11
|
module ChemSpider
|
8
12
|
class << self
|
9
13
|
##
|
@@ -38,9 +42,10 @@ module ChemSpider
|
|
38
42
|
# })
|
39
43
|
# #=> 2157
|
40
44
|
#
|
41
|
-
# @param [#
|
42
|
-
# @param [#
|
43
|
-
# @param [Hash] params (Hash.new)
|
45
|
+
# @param [#to_sym] service_name
|
46
|
+
# @param [#to_sym] operation_name
|
47
|
+
# @param [Hash{Symbol => Object}] params (Hash.new)
|
48
|
+
# @param [Hash{Symbol => Object}] options (Hash.new)
|
44
49
|
# @option uri_options [#to_s] :scheme ('http')
|
45
50
|
# @option uri_options [#to_s] :host ('www.chemspider.com')
|
46
51
|
# @option uri_options [#to_s] :port (80)
|
@@ -49,14 +54,10 @@ module ChemSpider
|
|
49
54
|
# @option uri_options [#to_s] :query (nil)
|
50
55
|
# @option uri_options [#to_s] :fragment (nil)
|
51
56
|
# @option options [#to_s] :selector (nil)
|
52
|
-
# @option options [Hash, Class, #__attributes__
|
57
|
+
# @option options [Hash{Symbol => Object}, Class, #__attributes__] :datatype (Hash.new)
|
53
58
|
# @option options [Boolean] :first_child (false)
|
54
|
-
#
|
55
59
|
# @return [Object]
|
56
|
-
#
|
57
|
-
# @see ChemSpider#css
|
58
|
-
# @see ChemSpider#uri_for
|
59
|
-
#
|
60
|
+
# @since 0.0.1
|
60
61
|
def get!(service_name, operation_name, params = {}, uri_options = {}, options = {})
|
61
62
|
# construct the URI...
|
62
63
|
uri = uri_for(service_name, operation_name, params, uri_options)
|
@@ -103,9 +104,10 @@ module ChemSpider
|
|
103
104
|
# })
|
104
105
|
# #=> 2157
|
105
106
|
#
|
106
|
-
# @param [#
|
107
|
-
# @param [#
|
108
|
-
# @param [Hash] params (Hash.new)
|
107
|
+
# @param [#to_sym] service_name
|
108
|
+
# @param [#to_sym] operation_name
|
109
|
+
# @param [Hash{Symbol => Object}] params (Hash.new)
|
110
|
+
# @param [Hash{Symbol => Object}] options (Hash.new)
|
109
111
|
# @option uri_options [#to_s] :scheme ('http')
|
110
112
|
# @option uri_options [#to_s] :host ('www.chemspider.com')
|
111
113
|
# @option uri_options [#to_s] :port (80)
|
@@ -114,14 +116,10 @@ module ChemSpider
|
|
114
116
|
# @option uri_options [#to_s] :query (nil)
|
115
117
|
# @option uri_options [#to_s] :fragment (nil)
|
116
118
|
# @option options [#to_s] :selector (nil)
|
117
|
-
# @option options [Hash, Class, #__attributes__
|
119
|
+
# @option options [Hash{Symbol => Object}, Class, #__attributes__] :datatype (Hash.new)
|
118
120
|
# @option options [Boolean] :first_child (false)
|
119
|
-
#
|
120
121
|
# @return [Object]
|
121
|
-
#
|
122
|
-
# @see ChemSpider#css
|
123
|
-
# @see ChemSpider#uri_for
|
124
|
-
#
|
122
|
+
# @since 0.0.1
|
125
123
|
def post!(service_name, operation_name, params = {}, uri_options = {}, options = {})
|
126
124
|
# construct the URI...
|
127
125
|
uri = uri_for(service_name, operation_name, nil, uri_options)
|
@@ -156,18 +154,15 @@ module ChemSpider
|
|
156
154
|
# m.post!(:inchi_key => 'BSYNRYMUTXBXSQ-UHFFFAOYSA-N')
|
157
155
|
# #=> 2157
|
158
156
|
#
|
159
|
-
# @param [#
|
160
|
-
# @param [#
|
161
|
-
# @param [Array<String>] param_names
|
157
|
+
# @param [#to_sym] service_name
|
158
|
+
# @param [#to_sym] operation_name
|
159
|
+
# @param [Array<String>] param_names (Array.new)
|
160
|
+
# @param [Hash{Symbol => Object}] options (Hash.new)
|
162
161
|
# @option options [#to_s] :selector (nil)
|
163
|
-
# @option options [Hash, Class, #__attributes__
|
162
|
+
# @option options [Hash{Symbol => Object}, Class, #__attributes__] :datatype (Hash.new)
|
164
163
|
# @option options [Boolean] :first_child (false)
|
165
|
-
#
|
166
164
|
# @return [Module]
|
167
|
-
#
|
168
|
-
# @see ChemSpider#get!
|
169
|
-
# @see ChemSpider#post!
|
170
|
-
#
|
165
|
+
# @since 0.0.1
|
171
166
|
def REST(service_name, operation_name, param_names = [], options = {})
|
172
167
|
# find/create the specified module...
|
173
168
|
# #=> "ChemSpider::#{service_name}::#{operation_name}"
|
@@ -182,8 +177,10 @@ module ChemSpider
|
|
182
177
|
# [re]define the methods...
|
183
178
|
%w{get! post!}.each do |method_name|
|
184
179
|
##
|
180
|
+
# @return [Object]
|
185
181
|
# @see ChemSpider#get!
|
186
182
|
# @see ChemSpider#post!
|
183
|
+
# @since 0.0.1
|
187
184
|
mod.send(:define_method, method_name.to_sym) do |*args|
|
188
185
|
# the default `uri_options` argument is an empty Hash
|
189
186
|
uri_options = {}
|
@@ -235,25 +232,29 @@ module ChemSpider
|
|
235
232
|
end
|
236
233
|
|
237
234
|
##
|
238
|
-
# @return [
|
235
|
+
# @return [Symbol]
|
236
|
+
# @since 0.0.2
|
239
237
|
mod.send(:define_method, :chem_spider_service_name) do ||
|
240
|
-
service_name.
|
238
|
+
service_name.to_sym
|
241
239
|
end
|
242
240
|
|
243
241
|
##
|
244
|
-
# @return [
|
242
|
+
# @return [Symbol]
|
243
|
+
# @since 0.0.2
|
245
244
|
mod.send(:define_method, :chem_spider_operation_name) do ||
|
246
|
-
operation_name.
|
245
|
+
operation_name.to_sym
|
247
246
|
end
|
248
247
|
|
249
248
|
##
|
250
249
|
# @return [Array<String>]
|
250
|
+
# @since 0.0.2
|
251
251
|
mod.send(:define_method, :chem_spider_param_names) do ||
|
252
252
|
param_names.collect(&:to_s)
|
253
253
|
end
|
254
254
|
|
255
255
|
##
|
256
|
-
# @return [Hash]
|
256
|
+
# @return [Hash{Symbol => Object}]
|
257
|
+
# @since 0.0.2
|
257
258
|
mod.send(:define_method, :chem_spider_options) do ||
|
258
259
|
options.dup
|
259
260
|
end
|
@@ -268,9 +269,8 @@ module ChemSpider
|
|
268
269
|
# Returns a unary callable that casts the argument to the specified `Class`.
|
269
270
|
#
|
270
271
|
# @param [Class] klass
|
271
|
-
#
|
272
272
|
# @return [#call]
|
273
|
-
#
|
273
|
+
# @since 0.0.1
|
274
274
|
def cast_for(klass)
|
275
275
|
# lazily construct the set of callables...
|
276
276
|
@casts ||= {
|
@@ -293,14 +293,12 @@ module ChemSpider
|
|
293
293
|
# Extracts nodes specified by a CSS selector, and casts the result.
|
294
294
|
#
|
295
295
|
# @param [Nokogiri::XML::Node] doc
|
296
|
+
# @param [Hash{Symbol => Object}] options (Hash.new)
|
296
297
|
# @option options [#to_s] :selector (nil)
|
297
|
-
# @option options [
|
298
|
+
# @option options [Hash{Symbol => Object}, Class, #__attributes__] :datatype (Hash.new)
|
298
299
|
# @option options [Boolean] :first_child (false)
|
299
|
-
#
|
300
300
|
# @return [Object]
|
301
|
-
#
|
302
|
-
# @see ChemSpider#cast_for
|
303
|
-
#
|
301
|
+
# @since 0.0.1
|
304
302
|
def css(doc, options = {})
|
305
303
|
# evaluate the CSS selector...
|
306
304
|
nodes = doc.css(options[:selector].to_s)
|
@@ -359,10 +357,9 @@ module ChemSpider
|
|
359
357
|
# @example Construct a query string with multivalued parameters.
|
360
358
|
# ChemSpider.query_for(:letters => %w{a b c}) #=> 'letters=a&letters=b&letters=c'
|
361
359
|
#
|
362
|
-
# @param [Array
|
363
|
-
#
|
360
|
+
# @param [Array<#to_s>, Hash{Symbol => Object}] pairs
|
364
361
|
# @return [#to_s]
|
365
|
-
#
|
362
|
+
# @since 0.0.1
|
366
363
|
def query_for(pairs)
|
367
364
|
return nil if pairs.nil? || pairs.empty?
|
368
365
|
|
@@ -392,11 +389,12 @@ module ChemSpider
|
|
392
389
|
# :port => 443,
|
393
390
|
# :path_format => '/chemspider/%s/%s',
|
394
391
|
# })
|
395
|
-
# #=> #<URI::
|
392
|
+
# #=> #<URI::HTTPS:0x101990e88 URL:https://www.example.com:443/chemspider/InChI/InChIKeyToCSID?inchi_key=BSYNRYMUTXBXSQ-UHFFFAOYSA-N>
|
396
393
|
#
|
397
|
-
# @param [#
|
398
|
-
# @param [#
|
399
|
-
# @param [Hash] params (Hash.new)
|
394
|
+
# @param [#to_sym] service_name
|
395
|
+
# @param [#to_sym] operation_name
|
396
|
+
# @param [Hash{Symbol => Object}] params (Hash.new)
|
397
|
+
# @param [Hash{Symbol => Object}] options (Hash.new)
|
400
398
|
# @option options [#to_s] :scheme ('http')
|
401
399
|
# @option options [#to_s] :host ('www.chemspider.com')
|
402
400
|
# @option options [#to_s] :port (80)
|
@@ -404,11 +402,9 @@ module ChemSpider
|
|
404
402
|
# @option options [#to_s] :path_format ('/%s.asmx/%s')
|
405
403
|
# @option options [#to_s] :query (nil)
|
406
404
|
# @option options [#to_s] :fragment (nil)
|
407
|
-
#
|
408
405
|
# @return [URI]
|
409
|
-
#
|
410
406
|
# @see ChemSpider#query_for
|
411
|
-
#
|
407
|
+
# @since 0.0.1
|
412
408
|
def uri_for(service_name, operation_name, params = {}, options = {})
|
413
409
|
# initialize the format string for the base URI "scheme://host:port"...
|
414
410
|
format = '%s://%s:%s'
|
data/lib/chem_spider/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chemspider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Borkum
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-23 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -33,7 +33,23 @@ dependencies:
|
|
33
33
|
version: 1.5.0
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
|
-
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 7
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 7
|
48
|
+
- 2
|
49
|
+
version: 0.7.2
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: "ChemSpider.rb: ChemSpider wrapped up with a Ruby bow."
|
37
53
|
email: m.i.borkum@soton.ac.uk
|
38
54
|
executables: []
|
39
55
|
|
@@ -42,6 +58,7 @@ extensions: []
|
|
42
58
|
extra_rdoc_files: []
|
43
59
|
|
44
60
|
files:
|
61
|
+
- AUTHORS
|
45
62
|
- README
|
46
63
|
- UNLICENSE
|
47
64
|
- VERSION
|
@@ -66,10 +83,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
83
|
requirements:
|
67
84
|
- - ">="
|
68
85
|
- !ruby/object:Gem::Version
|
69
|
-
hash:
|
86
|
+
hash: 57
|
70
87
|
segments:
|
71
|
-
-
|
72
|
-
|
88
|
+
- 1
|
89
|
+
- 8
|
90
|
+
- 7
|
91
|
+
version: 1.8.7
|
73
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
93
|
none: false
|
75
94
|
requirements:
|