datagun 0.1.0
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/.gitignore +2 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/datagun.gemspec +33 -0
- data/lib/datagun.rb +22 -0
- data/lib/datagun/api/base.rb +42 -0
- data/lib/datagun/api/community_detection/client.rb +29 -0
- data/lib/datagun/api/image_hash/client.rb +29 -0
- data/lib/datagun/api/keywords_extractor/client.rb +92 -0
- data/lib/datagun/concerns/http_wrapper.rb +40 -0
- data/lib/datagun/configuration.rb +28 -0
- data/lib/datagun/version.rb +3 -0
- data/lib/generators/datagun_generator.rb +19 -0
- data/lib/generators/templates/initializer.rb +6 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b4ac265206ad2704dcf0da532304b78bbd7c54e698a5dacafb479a73fc994c25
|
4
|
+
data.tar.gz: ecd9c1eab8dc5c381666bcce2b9f544391f713f4941fd906b83147a8720370bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60694b67a8035293064a8c75226a4d1e9d3980ba2ef1e3d167c53365cef34fd976a912a3388a87e1ffc3aef9fc7e478e3a1601290ac3fb389f2719696e3d0808
|
7
|
+
data.tar.gz: ca0220d10670169929fa5e2406f2b3ff260ee545e911285dcb862b60ec3f7f029f144a3cb9e349637a3b1bacd3ea56df227dad9913abe37ac21ec4ebf2cab6dd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
datagun (0.1.0)
|
5
|
+
rest-client (~> 2.1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
byebug (11.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
domain_name (0.5.20190701)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-accept (1.7.0)
|
16
|
+
http-cookie (1.0.3)
|
17
|
+
domain_name (~> 0.5)
|
18
|
+
jaro_winkler (1.5.4)
|
19
|
+
mime-types (3.3.1)
|
20
|
+
mime-types-data (~> 3.2015)
|
21
|
+
mime-types-data (3.2019.1009)
|
22
|
+
netrc (0.11.0)
|
23
|
+
parallel (1.19.1)
|
24
|
+
parser (2.7.1.1)
|
25
|
+
ast (~> 2.4.0)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (12.3.3)
|
28
|
+
rest-client (2.1.0)
|
29
|
+
http-accept (>= 1.7.0, < 2.0)
|
30
|
+
http-cookie (>= 1.0.2, < 2.0)
|
31
|
+
mime-types (>= 1.16, < 4.0)
|
32
|
+
netrc (~> 0.8)
|
33
|
+
rexml (3.2.4)
|
34
|
+
rspec (3.9.0)
|
35
|
+
rspec-core (~> 3.9.0)
|
36
|
+
rspec-expectations (~> 3.9.0)
|
37
|
+
rspec-mocks (~> 3.9.0)
|
38
|
+
rspec-core (3.9.1)
|
39
|
+
rspec-support (~> 3.9.1)
|
40
|
+
rspec-expectations (3.9.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-mocks (3.9.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.9.0)
|
46
|
+
rspec-support (3.9.2)
|
47
|
+
rubocop (0.82.0)
|
48
|
+
jaro_winkler (~> 1.5.1)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 2.7.0.1)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
rexml
|
53
|
+
ruby-progressbar (~> 1.7)
|
54
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
55
|
+
ruby-progressbar (1.10.1)
|
56
|
+
unf (0.1.4)
|
57
|
+
unf_ext
|
58
|
+
unf_ext (0.0.7.7)
|
59
|
+
unicode-display_width (1.7.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
byebug (~> 11.1.2)
|
66
|
+
datagun!
|
67
|
+
rake (~> 12.0)
|
68
|
+
rspec (~> 3.0)
|
69
|
+
rubocop (~> 0.82.0)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Duccio Giovannelli
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Datagun
|
2
|
+
|
3
|
+
[](https://travis-ci.org/4forges/datagun)
|
4
|
+
|
5
|
+
A Ruby interface to the Datagun API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'datagun'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install datagun
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Datagun.configure do |config|
|
27
|
+
config.api_key = 'token'
|
28
|
+
config.api_version = 'v1'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### Top keywords
|
33
|
+
|
34
|
+
Define a client and you gen upload your corpus. You can list your models, check a single model status, delete a model and analyze your text.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
client = Datagun::Api::KeywordsExtractor::Client.new
|
38
|
+
|
39
|
+
client.save_model(name: 'italian', file: File.open('/Users/giovannelli/Desktop/models/it.csv'))
|
40
|
+
# list models
|
41
|
+
client.models
|
42
|
+
|
43
|
+
# Get model status
|
44
|
+
# model statuse: processin, ready, failed
|
45
|
+
client.status(model_id: "model id")
|
46
|
+
|
47
|
+
# Delete a model
|
48
|
+
client.delete(model_id: "model id")
|
49
|
+
|
50
|
+
# analyze your text getting keywords with scores
|
51
|
+
client.analyze(text: "lorem ispum dolor sic amet", model_id: "model id")
|
52
|
+
```
|
53
|
+
|
54
|
+
### Community Detection
|
55
|
+
|
56
|
+
Define a client call detect
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
client = Datagun::Api::KeywordsExtractor::Client.new
|
60
|
+
|
61
|
+
# Return a list of communities
|
62
|
+
client.detect(graph: 'json')
|
63
|
+
```
|
64
|
+
|
65
|
+
### Image hash
|
66
|
+
|
67
|
+
Define a client and call perceptual
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
client = Datagun::Api::KeywordsExtractor::Client.new
|
71
|
+
|
72
|
+
# Return a list of communities
|
73
|
+
client.perceptual(url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Ruby_logo.svg/360px-Ruby_logo.svg.png')
|
74
|
+
```
|
75
|
+
|
76
|
+
# TODO
|
77
|
+
- Add tests to all clients methods
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/datagun.
|
82
|
+
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "datagun"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/datagun.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/datagun/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'datagun'
|
7
|
+
spec.version = Datagun::VERSION
|
8
|
+
spec.authors = ['Duccio Giovannelli']
|
9
|
+
spec.email = ['giovannelli@extendi.it']
|
10
|
+
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.description = 'A Ruby interface to the Datagun API.'
|
13
|
+
spec.homepage = 'https://github.com/4forges/datagun'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/4forges/datagun/blob/master/CHANGELOG.md'
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.1.0'
|
33
|
+
end
|
data/lib/datagun.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require 'datagun/version'
|
6
|
+
require 'datagun/configuration'
|
7
|
+
require 'datagun/concerns/http_wrapper'
|
8
|
+
|
9
|
+
require 'datagun/api/base'
|
10
|
+
require 'datagun/api/keywords_extractor/client'
|
11
|
+
|
12
|
+
module Datagun
|
13
|
+
class Error < StandardError; end
|
14
|
+
class << self
|
15
|
+
attr_accessor :config
|
16
|
+
|
17
|
+
def configure
|
18
|
+
self.config = Datagun::Configuration.new
|
19
|
+
yield(config)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagun
|
4
|
+
module Api
|
5
|
+
#
|
6
|
+
# Base class for Datagun
|
7
|
+
#
|
8
|
+
class Base
|
9
|
+
attr_reader :client, :logger
|
10
|
+
|
11
|
+
#
|
12
|
+
# Initialize Datagun::Base
|
13
|
+
#
|
14
|
+
# @param [Logger] default_logger
|
15
|
+
# i.e. nil || Logger.new
|
16
|
+
#
|
17
|
+
def initialize(default_logger: nil, version:)
|
18
|
+
@logger = default_logger || self.class.set_logger
|
19
|
+
@api_url = Datagun.config.api_url || 'https://api.datagun.ai'
|
20
|
+
@version = version
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Log to datagun.log file if Rails defined.
|
25
|
+
#
|
26
|
+
# @return [Logger]
|
27
|
+
#
|
28
|
+
def self.set_logger
|
29
|
+
@log_to ||= if defined?(::Rails)
|
30
|
+
shift_age = 2
|
31
|
+
shift_size = 50 * 1024 * 1024
|
32
|
+
::Logger.new("#{::Rails.root}/log/datagun.log", shift_age, shift_size)
|
33
|
+
else
|
34
|
+
::Logger.new(STDOUT)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Debug level on IRB or if logger_level is present on Thread.current
|
38
|
+
@log_to.level = defined?(IRB) ? Logger::DEBUG : Thread.current[:logger_level] || Logger::INFO
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagun
|
4
|
+
module Api
|
5
|
+
#
|
6
|
+
# Base class for Datagun
|
7
|
+
#
|
8
|
+
module CommunityDetection
|
9
|
+
#
|
10
|
+
# Client provide an HttpWrapper object that let
|
11
|
+
#
|
12
|
+
class Client < Datagun::Base
|
13
|
+
def initialize(default_logger: nil, version: Datagun.config.api_version)
|
14
|
+
super(default_logger: default_logger, version: version)
|
15
|
+
base_url = "#{@api_url}/api/#{@version}/community_detection"
|
16
|
+
@client = HttpWrapper.new(base_url: base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def detect(graph:)
|
20
|
+
client.endpoint = 'lpa'
|
21
|
+
client.payload = {
|
22
|
+
graph: graph
|
23
|
+
}
|
24
|
+
client.post.map{transform_keys(&:to_sym)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagun
|
4
|
+
module Api
|
5
|
+
#
|
6
|
+
# Base class for Datagun
|
7
|
+
#
|
8
|
+
module ImageHash
|
9
|
+
#
|
10
|
+
# Client provide an HttpWrapper object that let
|
11
|
+
#
|
12
|
+
class Client < Datagun::Base
|
13
|
+
def initialize(default_logger: nil, version: Datagun.config.api_version)
|
14
|
+
super(default_logger: default_logger, version: version)
|
15
|
+
base_url = "#{@api_url}/api/#{@version}/image_hash"
|
16
|
+
@client = HttpWrapper.new(base_url: base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def perceptual(url:)
|
20
|
+
client.endpoint = 'perceptual'
|
21
|
+
client.payload = {
|
22
|
+
url: url
|
23
|
+
}
|
24
|
+
client.get.transform_keys(&:to_sym)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagun
|
4
|
+
module Api
|
5
|
+
#
|
6
|
+
# Base class for Datagun
|
7
|
+
#
|
8
|
+
module KeywordsExtractor
|
9
|
+
#
|
10
|
+
# Client provides methods to interact with keywords_extractor endpoint
|
11
|
+
#
|
12
|
+
class Client < Base
|
13
|
+
def initialize(default_logger: nil, version: Datagun.config.api_version)
|
14
|
+
super(default_logger: default_logger, version: version)
|
15
|
+
base_url = "#{@api_url}/api/#{@version}/keyword_extractor"
|
16
|
+
@client = HttpWrapper.new(base_url: base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Store your corpus file
|
21
|
+
#
|
22
|
+
# @param [String] name: model name
|
23
|
+
# @param [Integer] features: max number of features to extract from the corpus
|
24
|
+
# @param [File] file
|
25
|
+
#
|
26
|
+
# @return [JSON]
|
27
|
+
#
|
28
|
+
def save_model(name:, features: nil, file:)
|
29
|
+
client.endpoint = 'save_model'
|
30
|
+
client.payload = {
|
31
|
+
model_name: name,
|
32
|
+
file: file
|
33
|
+
}
|
34
|
+
client.payload[:max_features] = features unless features.nil?
|
35
|
+
client.post.transform_keys(&:to_sym)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get status for a model_id
|
40
|
+
#
|
41
|
+
# @param [String] model_id
|
42
|
+
#
|
43
|
+
# @return [JSON]
|
44
|
+
#
|
45
|
+
def status(model_id:)
|
46
|
+
client.endpoint = 'status'
|
47
|
+
client.payload = {
|
48
|
+
model_id: model_id
|
49
|
+
}
|
50
|
+
client.get.transform_keys(&:to_sym)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Return the list of keywords extractors models
|
55
|
+
#
|
56
|
+
# @return [JSON]
|
57
|
+
#
|
58
|
+
def models
|
59
|
+
client.endpoint = 'models'
|
60
|
+
client.get.map { |item| item.transform_keys(&:to_sym) }
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Delete a model
|
65
|
+
#
|
66
|
+
# @return [JSON]
|
67
|
+
#
|
68
|
+
def delete(model_id:)
|
69
|
+
client.endpoint = model_id
|
70
|
+
client.delete.transform_keys(&:to_sym)
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Extract top keywords from passed text using your model
|
75
|
+
#
|
76
|
+
# @param [String] model_id
|
77
|
+
# @param [String] text
|
78
|
+
#
|
79
|
+
# @return [JSON]
|
80
|
+
#
|
81
|
+
def analyze(model_id:, text:)
|
82
|
+
client.endpoint = 'analyze'
|
83
|
+
client.payload = {
|
84
|
+
model_id: model_id,
|
85
|
+
text: text
|
86
|
+
}
|
87
|
+
client.get.transform_keys(&:to_sym)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
require 'json'
|
5
|
+
#
|
6
|
+
# Decorator class for the RestClient, mainly used to add the headers with authorization
|
7
|
+
#
|
8
|
+
class HttpWrapper
|
9
|
+
attr_accessor :payload
|
10
|
+
attr_writer :endpoint
|
11
|
+
|
12
|
+
def initialize(base_url:)
|
13
|
+
@base_url = base_url
|
14
|
+
@headers = {
|
15
|
+
'Authorization': Datagun.config.api_key
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def post
|
20
|
+
JSON.parse(RestClient.post(url, payload, @headers).body)['data']
|
21
|
+
rescue StandardError => e
|
22
|
+
{ error: e.message }
|
23
|
+
end
|
24
|
+
|
25
|
+
def get
|
26
|
+
JSON.parse(RestClient.get(url, { Authorization: Datagun.config.api_key, params: payload }).body)['data']
|
27
|
+
rescue StandardError => e
|
28
|
+
{ error: e.message }
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete
|
32
|
+
JSON.parse(RestClient.delete(url, { Authorization: Datagun.config.api_key }).body)['data']
|
33
|
+
rescue StandardError => e
|
34
|
+
{ error: e.message }
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
"#{@base_url}/#{@endpoint}"
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagun
|
4
|
+
class ConfigurationError < StandardError; end
|
5
|
+
|
6
|
+
#
|
7
|
+
# Datagun configuration
|
8
|
+
#
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
OPTIONAL_ATTRS = %i[api_url].freeze
|
12
|
+
MANDATORY_ATTRS = %i[api_key api_version].freeze
|
13
|
+
|
14
|
+
attr_accessor(*OPTIONAL_ATTRS)
|
15
|
+
attr_accessor(*MANDATORY_ATTRS)
|
16
|
+
|
17
|
+
MANDATORY_ATTRS.each do |attr|
|
18
|
+
define_method(attr) do
|
19
|
+
attr_value = instance_variable_get("@#{attr}")
|
20
|
+
if attr_value.nil? || attr_value.strip == ''
|
21
|
+
raise ConfigurationError, "Datagun #{attr} missing!"
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
# Creates the Datagun initializer file for Rails apps.
|
6
|
+
#
|
7
|
+
# @example Invokation from terminal
|
8
|
+
# rails generate datagun
|
9
|
+
#
|
10
|
+
class DatagunGenerator < Rails::Generators::Base
|
11
|
+
desc "Description:\n This creates a Rails initializer for Datagun"
|
12
|
+
|
13
|
+
source_root File.expand_path('templates', __dir__)
|
14
|
+
|
15
|
+
desc 'Configures Datagun to connect to Datagun api'
|
16
|
+
def generate_layout
|
17
|
+
template 'initializer.rb', 'config/initializers/datagun.rb'
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datagun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Duccio Giovannelli
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
description: A Ruby interface to the Datagun API.
|
28
|
+
email:
|
29
|
+
- giovannelli@extendi.it
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".ruby-version"
|
37
|
+
- ".travis.yml"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- datagun.gemspec
|
47
|
+
- lib/datagun.rb
|
48
|
+
- lib/datagun/api/base.rb
|
49
|
+
- lib/datagun/api/community_detection/client.rb
|
50
|
+
- lib/datagun/api/image_hash/client.rb
|
51
|
+
- lib/datagun/api/keywords_extractor/client.rb
|
52
|
+
- lib/datagun/concerns/http_wrapper.rb
|
53
|
+
- lib/datagun/configuration.rb
|
54
|
+
- lib/datagun/version.rb
|
55
|
+
- lib/generators/datagun_generator.rb
|
56
|
+
- lib/generators/templates/initializer.rb
|
57
|
+
homepage: https://github.com/4forges/datagun
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
allowed_push_host: https://rubygems.org
|
62
|
+
homepage_uri: https://github.com/4forges/datagun
|
63
|
+
source_code_uri: https://github.com/4forges/datagun
|
64
|
+
changelog_uri: https://github.com/4forges/datagun/blob/master/CHANGELOG.md
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.3.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.1.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: ''
|
84
|
+
test_files: []
|