game_dig 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5292bd7b7c7bddd3fa91f1081e6b9dbe2497f9036680047e55d14f4e25f5752b
4
+ data.tar.gz: f51410f39c2b62206bf3e2437e22793116ea04e48d8f24ac00b571b952f61688
5
+ SHA512:
6
+ metadata.gz: c5eb259271be2e071f5f31b6002465c21492c3bb43faa3cd5f3f22426b6d6339fd20a0ffb3ee8cf9b2e06aec9e69c8a6c44c0ddaf3e465c76e8572ac8932e77c
7
+ data.tar.gz: 8a08df836cec0cdfbff4308d961c3c6e29a6026897a6c815dcd96b6747805ea6582fba323071c899673f8cdcd2f0745252b88ab5074cd17dcf721d3779b7d11f
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.vscode/
11
+ /.idea/
12
+ *.gem
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at game_dig.gemspec@mail.magynhard.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in game_dig.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Matthäus J. N. Beyrle
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # GameDig for Ruby
2
+ ![Gem](https://img.shields.io/gem/v/game_dig?color=default&style=plastic&logo=ruby&logoColor=red)
3
+ ![Gem](https://img.shields.io/gem/dt/game_dig?color=blue&style=plastic)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic&logo=mit)](LICENSE)
5
+
6
+ > Ruby wrapper gem for [node-gamedig](https://github.com/gamedig/node-gamedig).
7
+
8
+ Providing support to use the node cli or running a tiny webservice for faster responses.
9
+
10
+
11
+
12
+
13
+
14
+ # Contents
15
+
16
+ * [Installation](#installation)
17
+ * [Usage examples](#usage)
18
+ * [Documentation](#documentation)
19
+ * [Contributing](#contributing)
20
+
21
+
22
+
23
+
24
+ <a name="installation"></a>
25
+ ## Installation
26
+ ### Prerequisites
27
+ NodeJS or a compatible alternative is installed.
28
+
29
+ Then install the gamedig package with your favourite package manager globally, e.g. here with npm or yarn:
30
+
31
+ #### yarn
32
+ ```
33
+ yarn global add gamedig
34
+ ```
35
+
36
+ #### npm
37
+ ```
38
+ npm install -g gamedig
39
+ ```
40
+
41
+ ### Gem
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem 'game_dig'
47
+ ```
48
+
49
+ And then execute:
50
+
51
+ $ bundle install
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install game_dig
56
+
57
+
58
+ <a name="usage"></a>
59
+ ## Usage examples
60
+
61
+ You can use the basic cli wrapper or the tiny webservice instance.
62
+
63
+ ### CLI wrapper
64
+
65
+ This will just run the gamedig cli and return its result.
66
+ ```ruby
67
+ require 'game_dig'
68
+ data = GameDig.query(type: 'minecraft', host: 'my-server.example.com')
69
+ p data
70
+ ```
71
+
72
+ ### Service wrapper (not implemented yet!)
73
+ Behaves the same to the user, but runs a tiny node webservice in the background to avoid startup times.
74
+
75
+ ```
76
+ your-ruby-app
77
+ --------> ruby-game_dig
78
+ --------> tiny node instance in a separate thread using gamedig node module
79
+ <----------------
80
+ ```
81
+
82
+ It needs only about half of the query time, but might be not as stable as it involves much more complexity. (about 10ms vs 20ms)
83
+
84
+ ```ruby
85
+ require 'game_dig/service'
86
+ data = GameDig.query(type: 'minecraft', host: 'my-server.example.com')
87
+ p data
88
+ ```
89
+
90
+ <a name="documentation"></a>
91
+ ## Documentation
92
+ Check out the doc at RubyDoc:<br>
93
+ https://www.rubydoc.info/gems/game_dig
94
+
95
+
96
+ As this library is only a wrapper, checkout the original node-gamedig documentation:<br>
97
+ https://github.com/gamedig/node-gamedig
98
+
99
+
100
+
101
+
102
+
103
+
104
+ <a name="contributing"></a>
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/ruby-game_dig.
108
+
109
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
110
+
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require "json"
5
+ require "colorize"
6
+
7
+ #
8
+ # run default task to see tasks to build and publish gem
9
+ #
10
+ task :default do
11
+ system 'rake --tasks'
12
+ end
13
+
14
+ desc "start cli to play with the environment"
15
+ task :cli do |t|
16
+ puts
17
+ puts %{ Starting CLI ... }.red
18
+ puts
19
+ require_relative 'cli/pry'
20
+ end
21
+
22
+ RSpec::Core::RakeTask.new(:spec)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "game_dig"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cli/pry.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ require_relative '../lib/game_dig'
3
+
4
+ require 'pry'
5
+ binding.pry
data/game_dig.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'game_dig/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "game_dig"
8
+ spec.version = GameDig::VERSION
9
+ spec.authors = ["Matthäus Beyrle"]
10
+ spec.email = ["game_dig.gemspec@mail.magynhard.de"]
11
+
12
+ spec.summary = %q{Ruby wrapper gem for node-gamedig}
13
+ spec.homepage = "https://github.com/magynhard/ruby-game_dig"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ 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_development_dependency 'bundler', '>= 1.14'
33
+ spec.add_development_dependency 'rake', '>= 10.0'
34
+ spec.add_development_dependency 'rspec', '>= 3.0'
35
+
36
+ spec.add_development_dependency 'colorize', '0.8.1'
37
+ spec.add_development_dependency 'pry', '0.14.1'
38
+ end
@@ -0,0 +1,2 @@
1
+ class GameDigCliNotFound < StandardError
2
+ end
@@ -0,0 +1,2 @@
1
+ class GameDigError < StandardError
2
+ end
@@ -0,0 +1,3 @@
1
+ module GameDig
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/game_dig.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'mkmf'
2
+ require 'game_dig/version'
3
+ require_relative 'custom_errors/game_dig_error'
4
+ require_relative 'custom_errors/game_dig_cli_not_found'
5
+
6
+ #
7
+ # GameDig
8
+ #
9
+
10
+ module GameDig
11
+
12
+ DEBUG_MESSAGE_END = 'Q#0 Query was successful'
13
+
14
+ #----------------------------------------------------------------------------------------------------
15
+
16
+ # Query a server for insight data
17
+ #
18
+ # @param [String] type
19
+ # @param [String] host
20
+ # @param [Number] port
21
+ # @param [Number] max_attempts
22
+ # @param [Number] socket_timeout
23
+ # @param [Number] attempt_timeout
24
+ # @param [Boolean] given_port_only
25
+ # @param [Boolean] debug
26
+ # @param [Boolean] request_rules
27
+ def self.query(type:, host:, port: nil, max_attempts: nil, socket_timeout: nil, attempt_timeout: nil, given_port_only: nil, debug: nil, request_rules: nil)
28
+ throw GameDigCliNotFound unless cli_installed?
29
+ command = "gamedig --type #{type}"
30
+ command += " --port #{port}" if port
31
+ command += " --maxAttempts #{max_attempts}" if max_attempts
32
+ command += " --socketTimeout #{socket_timeout}" if socket_timeout
33
+ command += " --attemptTimeout #{attempt_timeout}" if attempt_timeout
34
+ command += " --givenPortOnly" if given_port_only
35
+ command += " --debug #{debug}" if debug
36
+ command += " --requestRules" if request_rules
37
+ command += " #{host}"
38
+ puts command
39
+ begin
40
+ output = `#{command}`
41
+ json = if debug
42
+ output.split(DEBUG_MESSAGE_END).last
43
+ else
44
+ output
45
+ end
46
+ response = JSON.parse json
47
+ if debug
48
+ response['debug'] = output[0...(output.index(DEBUG_MESSAGE_END)+DEBUG_MESSAGE_END.size)]
49
+ end
50
+ if response['error']
51
+ raise GameDigError.new response['error']
52
+ end
53
+ response
54
+ rescue => e
55
+ raise e
56
+ end
57
+ end
58
+
59
+ #----------------------------------------------------------------------------------------------------
60
+
61
+ private
62
+
63
+ #
64
+ # Check if gamedig cli is installed globally
65
+ #
66
+ # @return [Boolean]
67
+ def self.cli_installed?()
68
+ !!(which 'gamedig')
69
+ end
70
+
71
+ #----------------------------------------------------------------------------------------------------
72
+
73
+ def self.which(cmd)
74
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
75
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
76
+ exts.each do |ext|
77
+ exe = File.join(path, "#{cmd}#{ext}")
78
+ return exe if File.executable?(exe) && !File.directory?(exe)
79
+ end
80
+ end
81
+ nil
82
+ end
83
+
84
+ #----------------------------------------------------------------------------------------------------
85
+
86
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: game_dig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthäus Beyrle
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-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
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.1
83
+ description:
84
+ email:
85
+ - game_dig.gemspec@mail.magynhard.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - cli/pry.rb
100
+ - game_dig.gemspec
101
+ - lib/custom_errors/game_dig_cli_not_found.rb
102
+ - lib/custom_errors/game_dig_error.rb
103
+ - lib/game_dig.rb
104
+ - lib/game_dig/version.rb
105
+ homepage: https://github.com/magynhard/ruby-game_dig
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.1.4
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby wrapper gem for node-gamedig
129
+ test_files: []