figa 0.0.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +24 -0
- data/Makefile +47 -0
- data/README.md +13 -0
- data/figa.gemspec +47 -0
- data/lib/figa.rb +131 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0730264f5ad57b4adcf105062fa9aa2396710067
|
4
|
+
data.tar.gz: 882c6230a5d0b42cf50874f78904259f5ba5e820
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab01ea02cff6dc17a967b4b59e1ee1869b94b419df57ca0fb4090d9df7f3dc787bc66119a62c56726a536e4feec8b956a95388d26591f53345e06685b0ddad19
|
7
|
+
data.tar.gz: 625d7b5399b4cdf8ee8cabac46990ad147532a634ef8773c4f470c82bd1352b1ff79ee3efde46c01a25ba429f0257e750f98b01fc02d0ce5ba679410bbcea655
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2019-2019, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Made in Japan
|
24
|
+
|
data/Makefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
## gem tasks ##
|
3
|
+
|
4
|
+
NAME = \
|
5
|
+
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
|
6
|
+
VERSION = \
|
7
|
+
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
|
8
|
+
|
9
|
+
count_lines:
|
10
|
+
find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
|
11
|
+
find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
|
12
|
+
cl: count_lines
|
13
|
+
|
14
|
+
scan:
|
15
|
+
scan lib/**/*.rb
|
16
|
+
|
17
|
+
gemspec_validate:
|
18
|
+
@echo "---"
|
19
|
+
ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
|
20
|
+
@echo "---"
|
21
|
+
|
22
|
+
name: gemspec_validate
|
23
|
+
@echo "$(NAME) $(VERSION)"
|
24
|
+
|
25
|
+
cw:
|
26
|
+
find lib -name "*.rb" -exec ruby -cw {} \;
|
27
|
+
|
28
|
+
build: gemspec_validate
|
29
|
+
gem build $(NAME).gemspec
|
30
|
+
mkdir -p pkg
|
31
|
+
mv $(NAME)-$(VERSION).gem pkg/
|
32
|
+
|
33
|
+
push: build
|
34
|
+
gem push pkg/$(NAME)-$(VERSION).gem
|
35
|
+
|
36
|
+
spec:
|
37
|
+
bundle exec rspec
|
38
|
+
test: spec
|
39
|
+
|
40
|
+
|
41
|
+
## specific to project ##
|
42
|
+
|
43
|
+
|
44
|
+
## done ##
|
45
|
+
|
46
|
+
.PHONY: count_lines scan gemspec_validate name cw build push spec
|
47
|
+
|
data/README.md
ADDED
data/figa.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
|
4
|
+
s.name = 'figa'
|
5
|
+
|
6
|
+
s.version = File.read(
|
7
|
+
File.expand_path('../lib/figa.rb', __FILE__)
|
8
|
+
).match(/ VERSION *= *['"]([^'"]+)/)[1]
|
9
|
+
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = [ 'John Mettraux' ]
|
12
|
+
s.email = [ 'jmettraux@gmail.com' ]
|
13
|
+
s.homepage = 'http://github.com/jmettraux/figa'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.summary = 'A Ruby client to the OpenFIGI API v2'
|
16
|
+
|
17
|
+
s.description = %{
|
18
|
+
A Ruby client to the OpenFIGI API v2.
|
19
|
+
}.strip
|
20
|
+
|
21
|
+
s.metadata = {
|
22
|
+
'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
|
23
|
+
'documentation_uri' => s.homepage,
|
24
|
+
'bug_tracker_uri' => s.homepage + '/issues',
|
25
|
+
#'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
|
26
|
+
'homepage_uri' => s.homepage,
|
27
|
+
'source_code_uri' => s.homepage,
|
28
|
+
#'wiki_uri' => s.homepage + '/wiki',
|
29
|
+
}
|
30
|
+
|
31
|
+
#s.files = `git ls-files`.split("\n")
|
32
|
+
s.files = Dir[
|
33
|
+
'README.{md,txt}',
|
34
|
+
'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
|
35
|
+
'Makefile',
|
36
|
+
'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
|
37
|
+
"#{s.name}.gemspec",
|
38
|
+
]
|
39
|
+
|
40
|
+
#s.add_runtime_dependency 'raabro', '~> 1.1'
|
41
|
+
#s.add_runtime_dependency 'et-orbi', '~> 1.1', '>= 1.1.8'
|
42
|
+
|
43
|
+
s.add_development_dependency 'rspec', '~> 3.8'
|
44
|
+
|
45
|
+
s.require_path = 'lib'
|
46
|
+
end
|
47
|
+
|
data/lib/figa.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
|
6
|
+
module Figa
|
7
|
+
|
8
|
+
VERSION = '0.0.1'
|
9
|
+
|
10
|
+
USER_AGENT = "Figa - https://github.com/jmettraux/figa - #{VERSION}"
|
11
|
+
API_ROOT_URI = 'https://api.openfigi.com/v2'
|
12
|
+
|
13
|
+
class Client
|
14
|
+
|
15
|
+
def initialize(api_key=nil)
|
16
|
+
|
17
|
+
@api_key = api_key
|
18
|
+
@enum_values = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def map(h)
|
22
|
+
|
23
|
+
k0 = h.is_a?(Hash) ? h.keys.first.to_s : nil
|
24
|
+
|
25
|
+
if k0 && h.size == 1 && enum_values('idType').include?(k0)
|
26
|
+
|
27
|
+
h = { idType: h.keys.first, idValue: h.values.first }
|
28
|
+
end
|
29
|
+
|
30
|
+
validate(h)
|
31
|
+
|
32
|
+
fail ArgumentError.new("parameter 'idType' is missing"
|
33
|
+
) unless h[:idType] || h['idType']
|
34
|
+
fail ArgumentError.new("parameter 'idValue' is missing"
|
35
|
+
) unless h[:idValue] || h['idValue']
|
36
|
+
|
37
|
+
post('/mapping', h)
|
38
|
+
end
|
39
|
+
|
40
|
+
def search(h)
|
41
|
+
|
42
|
+
h = { query: h } unless h.is_a?(Hash)
|
43
|
+
|
44
|
+
validate(h)
|
45
|
+
|
46
|
+
fail ArgumentError.new("parameter 'query' is missing"
|
47
|
+
) unless h[:query] || h['query']
|
48
|
+
|
49
|
+
post('/search', h)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
ENUM_KEYS = %w[
|
55
|
+
idType exchCode micCode currency marketSecDes securityType securityType2 ]
|
56
|
+
|
57
|
+
def list_enum_values(key)
|
58
|
+
|
59
|
+
#fail ArgumentError.new(
|
60
|
+
# "key #{key.inspect} not included in #{KEYS.inspect}"
|
61
|
+
#) unless KEYS.include?(key)
|
62
|
+
|
63
|
+
get('/mapping/values/' + key)
|
64
|
+
end
|
65
|
+
|
66
|
+
def enum_values(key)
|
67
|
+
|
68
|
+
@enum_values[key] ||= list_enum_values(key)
|
69
|
+
end
|
70
|
+
|
71
|
+
def validate(h)
|
72
|
+
|
73
|
+
h.each do |k, v|
|
74
|
+
|
75
|
+
sk = k.to_s
|
76
|
+
next unless ENUM_KEYS.include?(sk)
|
77
|
+
|
78
|
+
vs = (@enum_values[sk] ||= list_enum_values(key))
|
79
|
+
|
80
|
+
fail ArgumentError.new(
|
81
|
+
"value #{v.inspect} is not a valid value for key #{k.inspect}"
|
82
|
+
) unless enum_values(keys).include?(v)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def get(uri); request(:get, uri); end
|
87
|
+
def post(uri, data); request(:post, uri, data); end
|
88
|
+
|
89
|
+
def request(method, uri, data=nil)
|
90
|
+
|
91
|
+
uri = API_ROOT_URI + uri
|
92
|
+
|
93
|
+
req = (method == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri)
|
94
|
+
req.instance_eval { @header.clear }
|
95
|
+
def req.set_header(k, v); @header[k] = [ v ]; end
|
96
|
+
|
97
|
+
if data
|
98
|
+
req.body = JSON.dump(data)
|
99
|
+
req.content_type = 'application/json'
|
100
|
+
end
|
101
|
+
|
102
|
+
req.set_header('User-Agent', USER_AGENT)
|
103
|
+
req.set_header('Accept', 'application/json')
|
104
|
+
# TODO api key
|
105
|
+
|
106
|
+
u = URI(uri)
|
107
|
+
|
108
|
+
t0 = monow
|
109
|
+
|
110
|
+
t = Net::HTTP.new(u.host, u.port)
|
111
|
+
t.use_ssl = (u.scheme == 'https')
|
112
|
+
#t.set_debug_output($stdout)
|
113
|
+
#t.set_debug_output($stdout) if u.to_s.match(/search/)
|
114
|
+
|
115
|
+
res = t.request(req)
|
116
|
+
|
117
|
+
#class << res; attr_accessor :_elapsed; end
|
118
|
+
#res._elapsed = monow - t0
|
119
|
+
|
120
|
+
j = JSON.parse(res.body)
|
121
|
+
def j._response; res; end
|
122
|
+
j['_elapsed'] = monow - t0
|
123
|
+
# TODO j['next']
|
124
|
+
|
125
|
+
j
|
126
|
+
end
|
127
|
+
|
128
|
+
def monow; Process.clock_gettime(Process::CLOCK_MONOTONIC); end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: figa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Mettraux
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.8'
|
27
|
+
description: A Ruby client to the OpenFIGI API v2.
|
28
|
+
email:
|
29
|
+
- jmettraux@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE.txt
|
36
|
+
- Makefile
|
37
|
+
- README.md
|
38
|
+
- figa.gemspec
|
39
|
+
- lib/figa.rb
|
40
|
+
homepage: http://github.com/jmettraux/figa
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
changelog_uri: http://github.com/jmettraux/figa/blob/master/CHANGELOG.md
|
45
|
+
documentation_uri: http://github.com/jmettraux/figa
|
46
|
+
bug_tracker_uri: http://github.com/jmettraux/figa/issues
|
47
|
+
homepage_uri: http://github.com/jmettraux/figa
|
48
|
+
source_code_uri: http://github.com/jmettraux/figa
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.5.2.3
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A Ruby client to the OpenFIGI API v2
|
69
|
+
test_files: []
|