sentofu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 32c5cc4788ad456cd8121cb497ec1edd2646414cc2006466d18cef63c14d3d12
4
+ data.tar.gz: d681e4a0b6c3d95a3ad2bf6e3a50da249c3876503fb1cd057bd5e94fe94f2e58
5
+ SHA512:
6
+ metadata.gz: 67f28338c633693c0d2bff8157beab313be3d9a07c6b9ecacd7652710ff3282d3fac42a11f3e6e1973374486f1fb6fa13d4ce1472ca958ae2e2fb3cb3a683823
7
+ data.tar.gz: e895b60701e76e2f2a50791b3727caa611d6da06bc84e05ef7be7c222531994b25ad3ae48c9c94d38eddfcf2d2a00124ab734166f9ad1bc49d3998c42d05b006
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ # CHANGELOG.md
3
+
4
+
5
+ ## sentofu 0.0.1 released 2019-05-19
6
+
7
+ * initial empty release
8
+
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,44 @@
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
+ .PHONY: count_lines scan gemspec_validate name cw build push spec
44
+
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+
2
+ # sentofu
3
+
4
+ A Ruby client to some of the 1.0.0 Sentifi.com APIs.
5
+
6
+ ## license
7
+
8
+ MIT, see [LICENSE.txt](LICENSE.txt)
9
+
@@ -0,0 +1,121 @@
1
+
2
+ module Sentofu
3
+
4
+ class Resource
5
+
6
+ attr_reader :parent, :segment
7
+
8
+ def initialize(parent, segment)
9
+
10
+ @parent = parent
11
+ @segment = segment
12
+ @children = {}
13
+ end
14
+
15
+ def add_segment(segment)
16
+
17
+ m = segment.match(/\A\{([^}]+)\}\z/)
18
+ mth = m ? :[] : segment
19
+
20
+ return @children[mth] if @children[mth]
21
+
22
+ if mth == :[]
23
+ @children[:[]] = res = Sentofu::Resource.new(self, m[1])
24
+ define_singleton_method(:[]) { |i| res.index = i; res }
25
+ res
26
+ else
27
+ @children[mth] = res = Sentofu::Resource.new(self, segment)
28
+ define_singleton_method(mth) { res }
29
+ res
30
+ end
31
+ end
32
+
33
+ def add_leaf_segment(segment, point)
34
+
35
+ if m = segment.match(/\A\{([^}]+)\}\z/)
36
+ define_singleton_method(:[]) { |index, query={}|
37
+ fetch(segment, point, index, query) }
38
+ else
39
+ define_singleton_method(segment) { |query={}|
40
+ fetch(segment, point, nil, query) }
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def fetch(segment, point, index, query)
47
+
48
+ p [ :fetch, segment, '(point)', index, query ]
49
+ p path(segment)
50
+ #pp point
51
+ self.index = index if index
52
+
53
+ validate_query_parameters(point, query)
54
+
55
+ nil
56
+ end
57
+
58
+ def path(segment=nil)
59
+
60
+ segment ||= self.segment
61
+ segment = segment.gsub(/_/, '-')
62
+
63
+ if parent
64
+ File.join(parent.send(:path), segment)
65
+ else
66
+ '/' + segment
67
+ end
68
+ end
69
+
70
+ def validate_query_parameters(point, query)
71
+
72
+ point['get']['parameters'].select { |pa| pa['in'] == 'query' }
73
+ .each { |pa|
74
+ k = (pa[:key] ||= pa['name'].gsub(/-/, '_').to_sym)
75
+ fail ArgumentError.new("missing query parameter #{k.inspect}") \
76
+ if pa['required'] == true && !query.has_key?(k) }
77
+ pp params
78
+ end
79
+ end
80
+
81
+ class Api < Resource
82
+
83
+ attr_reader :spec
84
+
85
+ def initialize(spec, name)
86
+
87
+ super(nil, nil)
88
+
89
+ @spec = spec
90
+ @name = name
91
+
92
+ #puts "================== #{name}"
93
+ spec['paths'].each do |path, point|
94
+
95
+ #p path
96
+ re = self
97
+ pas = path.split('/').collect { |s| s.gsub(/-/, '_') }
98
+ pas.shift if pas.first == ''
99
+ pas[0..-2].each do |pa|
100
+ re = re.add_segment(pa)
101
+ end
102
+ re.add_leaf_segment(pas.last, point)
103
+ end
104
+ end
105
+
106
+ class << self
107
+
108
+ def make(api_spec)
109
+
110
+ name =
111
+ api_spec['info']['title'].split(' - ').last[0..-4].strip
112
+ .gsub(/([a-z])([A-Z])/) { |_| $1 + '_' + $2.downcase }
113
+ .gsub(/([A-Z])/) { |c| c.downcase }
114
+
115
+ api = Sentofu::Api.new(api_spec, name)
116
+ (class << Sentofu; self; end).define_method(name) { api }
117
+ end
118
+ end
119
+ end
120
+ end
121
+
@@ -0,0 +1,59 @@
1
+
2
+ module Sentofu
3
+
4
+ module Http
5
+
6
+ HOST = 'apis.sentifi.com'
7
+
8
+ class << self
9
+
10
+ def fetch_token(credentials=nil)
11
+
12
+ cs = narrow_credentials(credentials)
13
+
14
+ a = Base64.encode64("#{cs.id}:#{cs.secret}").strip
15
+ #p a
16
+
17
+ req = Net::HTTP::Post.new('/v1/oauth/token')
18
+ req.add_field('Content-Type', 'application/json')
19
+ req.add_field('Authorization', a)
20
+
21
+ req.body = JSON.dump(
22
+ grant_type: 'password', username: cs.user, password: cs.pass)
23
+
24
+ res = request(req)
25
+ #pp res
26
+
27
+ OpenStruct.new(JSON.parse(res.body))
28
+ end
29
+
30
+ protected
31
+
32
+ def request(req)
33
+
34
+ t = Net::HTTP.new(HOST, 443)
35
+ t.use_ssl = true
36
+ #t.verify_mode = OpenSSL::SSL::VERIFY_NONE # avoid
37
+
38
+ t.request(req)
39
+ end
40
+
41
+ def narrow_credentials(o)
42
+
43
+ case o
44
+ when OpenStruct then o
45
+ when Hash then OpenStruct.new(o)
46
+ when NilClass then load_credentials
47
+ when String then load_credentials(o)
48
+ else fail ArgumentError.new( "no credentials in a #{o.class}")
49
+ end
50
+ end
51
+
52
+ def load_credentials(fname='.sentifi-credentials.yaml')
53
+
54
+ OpenStruct.new(YAML.load(File.read(fname)))
55
+ end
56
+ end
57
+ end
58
+ end
59
+
data/lib/sentofu.rb ADDED
@@ -0,0 +1,37 @@
1
+
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'base64'
5
+ require 'ostruct'
6
+ require 'net/http'
7
+
8
+ require 'sentofu/http'
9
+ require 'sentofu/api'
10
+
11
+
12
+ module Sentofu
13
+
14
+ VERSION = '0.0.1'
15
+
16
+ Dir[File.join(__dir__, 'sentofu/sentifi-*.yaml')].each do |fpath|
17
+
18
+ Sentofu::Api.make(YAML.load(File.read(fpath)))
19
+ end
20
+ end
21
+
22
+
23
+ if $0 == __FILE__
24
+
25
+ #p Time.now
26
+ #t = Sentofu::Http.fetch_token
27
+ #pp t.to_h
28
+ #p [ t.expires_in / 3600 / 24, :days ]
29
+
30
+ #y = YAML.load(File.read(File.join(File.dirname(__FILE__), 'sentifi/sentifi-api-docs-sentifi-intelligence_company_api-1.0.0-swagger.yaml')))
31
+ #pp y['paths'].keys
32
+
33
+ #p Sentofu.company.class
34
+ p Sentofu.company.topic_search
35
+ #pp Sentofu.markets
36
+ end
37
+
data/sentofu.gemspec ADDED
@@ -0,0 +1,47 @@
1
+
2
+ Gem::Specification.new do |s|
3
+
4
+ s.name = 'sentofu'
5
+
6
+ s.version = File.read(
7
+ File.expand_path('../lib/sentofu.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/sentofu'
14
+ s.license = 'MIT'
15
+ s.summary = 'A Ruby client to some of the 1.0.0 Sentifi.com APIs'
16
+
17
+ s.description = %{
18
+ A Ruby client to some of the 1.0.0 Sentifi.com APIs
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
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentofu
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-05-18 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 some of the 1.0.0 Sentifi.com APIs
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
+ - lib/sentofu.rb
39
+ - lib/sentofu/api.rb
40
+ - lib/sentofu/http.rb
41
+ - sentofu.gemspec
42
+ homepage: http://github.com/jmettraux/sentofu
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ changelog_uri: http://github.com/jmettraux/sentofu/blob/master/CHANGELOG.md
47
+ documentation_uri: http://github.com/jmettraux/sentofu
48
+ bug_tracker_uri: http://github.com/jmettraux/sentofu/issues
49
+ homepage_uri: http://github.com/jmettraux/sentofu
50
+ source_code_uri: http://github.com/jmettraux/sentofu
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.6
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A Ruby client to some of the 1.0.0 Sentifi.com APIs
71
+ test_files: []