rmuh 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2afa8d700e33ca03886586afae8cb833e30e6848
4
- data.tar.gz: 1812d02b9537370a22db998fcee1f6936e5b39c8
3
+ metadata.gz: ee6d35d0861a94192af934236bc6f749b43bf1ae
4
+ data.tar.gz: aae69a679fff65aa138f6f9328894f3403d444c0
5
5
  SHA512:
6
- metadata.gz: 6956e30ee23bc0d415276f263e5bac85d629781e272e082dd694f3af23bf3f2ba0deeb2a7fe6749dfcae8a398b572d9d540276575956bbe6a996bfd0cd0b7d05
7
- data.tar.gz: 5c3ce06cd77a60f70045da346fb340df5b4455290d5f92d07cbd6ca1f4969358801b20436fa4e143d459ee23a993918117bb5b8ff0ca551ee2e0ad1ef31e1635
6
+ metadata.gz: 55e40a5069510f01a0f6b5957596184ff994b0f33a0b78a9666194f521e7520e7200689bd04d06ccb357f3e627622295be480a6a95e7d7dd0bc213604ceb79a7
7
+ data.tar.gz: d3e196a3bd246975d82fea8b7bfe08bff3ab947dd106fb5cf9ae6ba3f6b0a8390c54c68bd12ef318f848a3cff85d03d02250d4aa633f534cd2f728c183b0658f
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  RMuh
2
2
  ====
3
3
  [![Build Status](https://img.shields.io/travis/theckman/rmuh/master.svg)](https://travis-ci.org/theckman/rpt-ruby)
4
- [![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://tldrlegal.com/license/mit-license)
5
- [![RubyGems](http://img.shields.io/gem/v/rmuh.svg)](https://rubygems.org/gems/rmuh)
4
+ [![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://tldrlegal.com/license/mit-license)
5
+ [![RubyGems :: RMuh Gem Version](http://img.shields.io/gem/v/rmuh.svg)](https://rubygems.org/gems/rmuh)
6
6
  [![Coveralls Coverage](https://img.shields.io/coveralls/theckman/rmuh/master.svg)](https://coveralls.io/r/theckman/rmuh)
7
7
  [![Code Climate](https://img.shields.io/codeclimate/github/theckman/rmuh.svg)](https://codeclimate.com/github/theckman/rmuh)
8
8
  [![Gemnasium](https://img.shields.io/gemnasium/theckman/rmuh.svg)](https://gemnasium.com/theckman/rmuh)
@@ -11,11 +11,146 @@ RMuh
11
11
  interacting with ArmA 2 servers (specifically tested against Operation
12
12
  Arrowhead servers).
13
13
 
14
- In short, this `README` file usless right now. It is a work in progress.
15
- Please refer to it in the future for more information as it should be helpful
16
- then...
17
-
18
14
  LICENSE
19
15
  -------
20
- **RMuh** is released under The MIT License. The full text of the license can be
21
- found in the `LICENSE` file
16
+ **RMuh** is released under the
17
+ [The MIT License](http://opensource.org/licenses/MIT) The full text of the
18
+ license can be found in the `LICENSE` file
19
+
20
+ CONTRIBUTING
21
+ ------------
22
+ I know different communities may have slightly different RPT/Server log files.
23
+ Want to contribute changes/additions to the project? Just for the project to
24
+ your own repo, make your changes and write corresponding RSpec tests, and then
25
+ submit a PR.
26
+
27
+ INSTALLATION
28
+ ------------
29
+ This is packaged on the [RubyGems](https://rubygems.org/) site and can be
30
+ installed via the `gem` command:
31
+
32
+ ```Ruby
33
+ $ gem install rmuh
34
+ ```
35
+
36
+ If you have a `Gemfile` or a `Gemspec` file for your project you can add
37
+ these entires to these files and use `bundle install` to install the gem:
38
+
39
+ **Gemfile**:
40
+
41
+ ```Ruby
42
+ gem 'rmuh'
43
+ ```
44
+
45
+ **Gemspec**:
46
+
47
+ ```Ruby
48
+ g.add_runtime_dependency 'rmuh'
49
+ ```
50
+
51
+ **Note:** If you want to do version pinning within your `Gemfile` or `Gemspec`
52
+ file visit [RubyGems :: RMuh](https://rubygems.org/gems/rmuh) to see the
53
+ specific versions available.
54
+
55
+ USAGE
56
+ -----
57
+ This is just an overview of how to use the specific features of `RMuh`. For
58
+ full documentation please view the `README.md` files within the `lib` dir,
59
+ look in the `examples` dir, or visit the docs on
60
+ [RubyDoc](http://rubydoc.info/gems/rmuh).
61
+
62
+ So here are some examples of how to use the different classes.
63
+
64
+ Log Fetching
65
+ ------------
66
+ There is a built in log fetcher that uses `httparty` to pull the log files.
67
+
68
+ Here is an example of how to just fetch the full log and print it:
69
+
70
+ ```Ruby
71
+ require 'rmuh/rpt/log/fetch'
72
+ URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_RPT.txt'
73
+ f = RMuh::RPT::Log::Fetch.new(URL)
74
+ puts f.log
75
+ ```
76
+ In this case `f.log` returns a `StringIO` object which will be used by the
77
+ parsers to parse the log files.
78
+
79
+ If you want to specify a
80
+ [byte range](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2):
81
+
82
+ ```Ruby
83
+ f = RMuh::RPT::Log::Fetch.new(URL, byte_start: 100, byte_end: 200)
84
+ ```
85
+ This can be used to pull the log in smaller sizes if you are doing incremental
86
+ updates. To compound the byte range ability, you can get the log file size as
87
+ well as update the byte range after initializing the object:
88
+
89
+ ```Ruby
90
+ f.size # prints Fixnum
91
+ f.byte_start = 10 # Sets the first byte to 10
92
+ f.byte_end = 40 # Sets the last byte to 40
93
+ ```
94
+
95
+ Log Parsing
96
+ -----------
97
+ Included with this module is a default log parser. The default parser does
98
+ nothing but return each line as a Hash within an Array. There is no metadata
99
+ extracted, it's a literal copy and paste of the provided log line. This default
100
+ parser is primarily used as an example class to be used for subclassing of your
101
+ own parser.
102
+
103
+ ```Ruby
104
+ require 'rmuh/rpt/log/fetch'
105
+ require 'rmuh/rpt/parsers/base
106
+ URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_RPT.txt'
107
+ f = RMuh::RPT::Log::Fetch.new(URL)
108
+ p = RMuh::RPT::Log::Parsers::Base.new
109
+ l = p.parse(f.log)
110
+ ```
111
+ At this specific moment `l` would contain an Array of Hashes corresponding to
112
+ the log lines.
113
+
114
+ Server Stats
115
+ ------------
116
+ The `RMuh` gem also wraps the
117
+ [GamespyQuery](https://rubygems.org/gems/gamespy_query) Rubygem for pulling
118
+ live statistics from the server. This includes current map, mission, play list,
119
+ and others. Deep down this just uses the GameSpy protocol to get the
120
+ information directly from the server.
121
+
122
+ Here is a quick overview of how to use this functionality:
123
+
124
+ ```
125
+ require 'rmuh/serverstats/base
126
+ UO_IP = '70.42.74.59'
127
+ s = RMuh::ServerStats::Base.new(host: UO_IP)
128
+ s.update_cache
129
+ puts s.stats
130
+ ```
131
+ By default the `ServerStats::Base` class caches the information so you need to
132
+ explicitly update the cache. This is not done automatically as it is a blocking
133
+ operation, this allow you to block somewhere other than where you instantiate
134
+ the object.
135
+
136
+ If you want to avoid using the cache:
137
+
138
+ ```
139
+ s = RMuh::ServerStats::Base.new(host: UO_IP, cache: false)
140
+ ```
141
+ If you want to be able to pull each part of the returned data set using
142
+ dot-notation, you can use the `Advanced` class:
143
+
144
+ ```
145
+ require 'rmuh/serverstats/base
146
+ s = RMuh::ServerStats::Advanced.new(host: UO_IP)
147
+ s.update_cache
148
+ puts s.players
149
+ ```
150
+ In this case, `players` is an Array. If you specify a key that doesn't exist
151
+ you will get a NoMethodError exception.
152
+
153
+ SUPPORT
154
+ -------
155
+ Having some problems understanding something? Just open an issue and I'll get
156
+ back to you as soon as I can.
@@ -5,43 +5,54 @@ require 'ostruct'
5
5
  module RMuh
6
6
  module RPT
7
7
  module Log
8
- # TODO: Fetch Class documentation
8
+ # This is the RPT Log fetcher class. It allows fetching a specific URL,
9
+ # only pulling a specific byte range, as well as getting the size of the
10
+ # external file
9
11
  #
10
12
  class Fetch
11
13
  include HTTParty
12
- attr_accessor :cfg
13
-
14
- def initialize(log_url, byte_start = 0, byte_end = nil)
15
- @cfg = OpenStruct.new(
16
- log_url: log_url,
17
- byte_start: byte_start,
18
- byte_end: byte_end
19
- )
14
+ attr_accessor :log_url, :byte_start, :byte_end
15
+
16
+ def self.validate_opts(opts)
17
+ if opts.key?(:byte_start) &&
18
+ (!opts[:byte_start].is_a?(Fixnum) || opts[:byte_start] < 0)
19
+ fail(ArgumentError, ':byte_start must be a Fixnum >= 0')
20
+ end
21
+ if opts.key?(:byte_end) &&
22
+ ![Fixnum, NilClass].include?(opts[:byte_end].class)
23
+ fail(ArgumentError, ':byte_end must be nil or Fixnum')
24
+ end
25
+ end
26
+
27
+ # New Fetch class. This is used for fetching the ArmA 2 log files
28
+ # Required param (#1): (String) The log file URL
29
+ # Optional param (#2): (Hash):
30
+ # * :byte_start - what byte to start the log file from
31
+ # * :byte_end - the last byte that we want from the log file
32
+ #
33
+ def initialize(log_url, opts = {})
34
+ @log_url = log_url
35
+ @byte_start = opts.key?(:byte_start) ? opts[:byte_start] : 0
36
+ @byte_end = opts.key?(:byte_end) ? opts[:byte_end] : nil
20
37
  end
21
38
 
22
39
  def byte_start=(bytes)
23
- if bytes.is_a?(Integer)
24
- @cfg.byte_start = bytes
25
- else
26
- fail ArgumentError, 'argument 1 must be an integer'
27
- end
40
+ self.class.validate_opts(byte_start: bytes)
41
+ @byte_start = bytes
28
42
  end
29
43
 
30
44
  def byte_end=(bytes)
31
- if bytes.nil? || bytes.is_a?(Integer)
32
- @cfg.byte_end = bytes
33
- else
34
- fail ArgumentError, 'argument 1 must be nil or an integer'
35
- end
45
+ self.class.validate_opts(byte_end: bytes)
46
+ @byte_end = bytes
36
47
  end
37
48
 
38
49
  def size
39
- self.class.head(@cfg.log_url).headers['content-length'].to_i
50
+ self.class.head(@log_url).headers['content-length'].to_i
40
51
  end
41
52
 
42
53
  def log
43
- headers = { 'Range' => "bytes=#{@cfg.byte_start}-#{@cfg.byte_end}" }
44
- response = self.class.get(@cfg.log_url, headers: headers)
54
+ headers = { 'Range' => "bytes=#{@byte_start}-#{@byte_end}" }
55
+ response = self.class.get(@log_url, headers: headers)
45
56
  StringIO.new(response.lines.map { |l| dos2unix(l) }.join)
46
57
  end
47
58
 
@@ -16,11 +16,9 @@ module RMuh
16
16
  def parse(loglines)
17
17
  fail(
18
18
  ArgumentError, 'argument 1 must be a StringIO object'
19
- ) unless loglines.is_a? StringIO
19
+ ) unless loglines.is_a?(StringIO)
20
20
 
21
- loglines.map do |line|
22
- { type: :log, message: line }
23
- end
21
+ loglines.map { |line| { type: :log, message: line } }
24
22
  end
25
23
  end
26
24
  end
@@ -10,7 +10,12 @@ module RMuh
10
10
  module RPT
11
11
  module Log
12
12
  module Parsers
13
- # TODO: UnitedOperationsLog Class Documentation
13
+ # This is the UnitedOperations Log parser class. It separates the log
14
+ # in to an array of Hashes, one for each log line.
15
+ #
16
+ # This can be used to rebuild the log file, from metadata alone.
17
+ #
18
+ # It extends RMuh::RPT::Log::Parsers::Base
14
19
  #
15
20
  class UnitedOperationsLog < RMuh::RPT::Log::Parsers::Base
16
21
  include RMuh::RPT::Log::Util::UnitedOperations
@@ -18,6 +23,11 @@ module RMuh
18
23
  include RMuh::RPT::Log::Util::UnitedOperationsLog # Regexp Constants
19
24
  extend RMuh::RPT::Log::Util::UnitedOperationsLog
20
25
 
26
+ # Validate the options that are passed in as arg 1 to the new()
27
+ # function
28
+ #
29
+ # This raises ArgumentError if something doesn't pass
30
+ #
21
31
  def self.validate_opts(opts)
22
32
  fail(
23
33
  ArgumentError, 'arg 1 should be an instance of Hash'
@@ -27,6 +37,13 @@ module RMuh
27
37
  validate_bool_opt(opts, :chat)
28
38
  end
29
39
 
40
+ # This builds the object. There are three optional args for the Hash:
41
+ # * :chat -- should chat lines be included?
42
+ # * :to_zulu -- convert timestamp to zulu
43
+ # * :timezone -- specify the server timezone
44
+ # --
45
+ # TODO: Make this use an auto hash to instance variable function
46
+ # ++
30
47
  def initialize(opts = {})
31
48
  self.class.validate_opts(opts)
32
49
  @include_chat = opts[:chat].nil? ? false : opts[:chat]
@@ -10,13 +10,20 @@ module RMuh
10
10
  module RPT
11
11
  module Log
12
12
  module Parsers
13
- # TODO: UnitedOperationsRPT Class Documentation
13
+ # This is the UnitedOperations parser class. This separates the
14
+ # UnitedOperations log lines in to their respective Hashes
15
+ #
16
+ # This can be used to rebuild the log file, from metadata alone.
17
+ #
18
+ # It extends RMuh::RPT::Log::Parsers::Base
14
19
  #
15
20
  class UnitedOperationsRPT < RMuh::RPT::Log::Parsers::Base
16
21
  include RMuh::RPT::Log::Util::UnitedOperations
17
22
  extend RMuh::RPT::Log::Util::UnitedOperations
18
23
  include RMuh::RPT::Log::Util::UnitedOperationsRPT # Regexp Constants
19
24
 
25
+ # This is used to validate the options passed in to new()
26
+ # Will throw ArgumentError if things aren't right.
20
27
  def self.validate_opts(opts)
21
28
  fail ArgumentError,
22
29
  'argument 1 should be a Hash' unless opts.class == Hash
@@ -24,6 +31,15 @@ module RMuh
24
31
  validate_timezone(opts)
25
32
  end
26
33
 
34
+ # This is the initializer for the whole object. There are two
35
+ # valid options for this class:
36
+ # :to_zulu -- convert the timestamp to zulu and add iso8601 and dtg
37
+ # timestamp -- this defaults to true
38
+ # :timezone -- specifies the server's timezone from the tz database
39
+ # this defaults to the UO timezone
40
+ # --
41
+ # TODO: Convert this to use an auto hash to instance variable
42
+ # ++
27
43
  def initialize(opts = {})
28
44
  self.class.validate_opts(opts)
29
45
 
@@ -31,6 +47,9 @@ module RMuh
31
47
  @timezone = opts[:timezone].nil? ? UO_TZ : opts[:timezone]
32
48
  end
33
49
 
50
+ # Parse the StringIO object which is the lines from the log.
51
+ # This expects arg 1 to be a StringIO object, otherwise it will
52
+ # throw an ArgumentError exception
34
53
  def parse(loglines)
35
54
  unless loglines.is_a?(StringIO)
36
55
  fail ArgumentError, 'argument 1 must be a StringIO object'
@@ -6,7 +6,8 @@ module RMuh
6
6
  module RPT
7
7
  module Log
8
8
  module Util
9
- # TODO: Module documentation
9
+ # UnitedOperations module. This has a constant and some shared
10
+ # functions. This is shared amongst the two UO logs
10
11
  #
11
12
  module UnitedOperations
12
13
  UO_TZ ||= TZInfo::Timezone.get('America/Los_Angeles')
data/lib/rmuh/rpt.rb ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ # RMuh::RPT
4
+ # Released under the MIT License
5
+ # Copyright (c) 2014 Tim Heckman
6
+
7
+ path = File.expand_path('..', __FILE__)
8
+ require File.join(path, 'rpt/log/fetch')
9
+ require File.join(path, 'rpt/log/parsers/base')
10
+ require File.join(path, 'rpt/log/parsers/unitedoperationsrpt')
11
+ require File.join(path, 'rpt/log/parsers/unitedoperationslog')
@@ -4,7 +4,10 @@ require 'rmuh/serverstats/base'
4
4
 
5
5
  module RMuh
6
6
  module ServerStats
7
- # TODO: Documentation
7
+ # This is an advanced extension of the Base class. This adds the ability to
8
+ # access the top level keys returned from the server using dot notation
9
+ #
10
+ # No additions / alterations exist to the methods from the Base class
8
11
  #
9
12
  class Advanced < RMuh::ServerStats::Base
10
13
  def method_missing(method, *args, &block)
@@ -3,10 +3,19 @@
3
3
  require 'gamespy_query'
4
4
 
5
5
  module RMuh
6
- # TODO: Documentation
6
+ # This is the namespace for the Gamespy Query Server Statistics.
7
+ # It has no methods.
7
8
  #
8
9
  module ServerStats
9
- # TODO: Documentation
10
+ # This is the Base server stats class. It wraps GamespyQuery::Socket and
11
+ # adds a simpler interface for the usage of querying the server.
12
+ #
13
+ # The required parameter within the Hash is ':host'. Optional params are:
14
+ # port and cache
15
+ #
16
+ # * port: the GamespyQuery port of the server (usually game port)
17
+ # * cache: whether the data will cache on request, or pull new data each
18
+ # stats request
10
19
  #
11
20
  class Base
12
21
  DEFAULT_PORT = 2_302
data/lib/rmuh/version.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # -*- coding: UTF-8 -*-
2
2
  # RMuh : the ArmA 2 Ruby library
3
3
  #
4
+ # This is just the version file.
5
+ #
4
6
  module RMuh
5
7
  VERSION_MAJ ||= 0
6
8
  VERSION_MIN ||= 2
7
- VERSION_REV ||= 0
9
+ VERSION_REV ||= 1
8
10
 
9
11
  VERSION ||= "#{VERSION_MAJ}.#{VERSION_MIN}.#{VERSION_REV}"
10
12
  end
data/lib/rmuh.rb CHANGED
@@ -20,3 +20,8 @@
20
20
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
+
24
+ path = File.expand_path('../rmuh', __FILE__)
25
+ require File.join(path, 'rpt')
26
+ require File.join(path, 'serverstats/base')
27
+ require File.join(path, 'serverstats/advanced')
@@ -15,18 +15,18 @@ describe RMuh::RPT::Log::Fetch do
15
15
  fetch.should be_an_instance_of RMuh::RPT::Log::Fetch
16
16
  end
17
17
 
18
- it 'should have a @cfg object which is an instance of OpenStruct' do
19
- fetch.cfg.should be_an_instance_of OpenStruct
18
+ it 'should have a @log_url object which is an instance of String' do
19
+ fetch.log_url.should be_an_instance_of String
20
20
  end
21
21
 
22
- it 'should set the "byte_start" config item if specified as arg:1' do
23
- rlfetch = RMuh::RPT::Log::Fetch.new(url, 10)
24
- rlfetch.cfg.byte_start.should eql 10
22
+ it 'should set the "byte_start" config item if specified' do
23
+ rlfetch = RMuh::RPT::Log::Fetch.new(url, byte_start: 10)
24
+ rlfetch.byte_start.should eql 10
25
25
  end
26
26
 
27
- it 'should set the "byte_end" config item if specified as arg:3' do
28
- rlfetch = RMuh::RPT::Log::Fetch.new(url, 10, 42)
29
- rlfetch.cfg.byte_end.should eql 42
27
+ it 'should set the "byte_end" config item if specified' do
28
+ rlfetch = RMuh::RPT::Log::Fetch.new(url, byte_end: 42)
29
+ rlfetch.byte_end.should eql 42
30
30
  end
31
31
  end
32
32
 
@@ -49,7 +49,7 @@ describe RMuh::RPT::Log::Fetch do
49
49
 
50
50
  it 'should update the @cfg.byte_start value' do
51
51
  fetch.byte_start = 10
52
- fetch.cfg.byte_start.should eql 10
52
+ fetch.byte_start.should eql 10
53
53
  end
54
54
  end
55
55
 
@@ -72,7 +72,7 @@ describe RMuh::RPT::Log::Fetch do
72
72
 
73
73
  it 'should update the @cfg.byte_end value' do
74
74
  fetch.byte_end = 42
75
- fetch.cfg.byte_end.should eql 42
75
+ fetch.byte_end.should eql 42
76
76
  end
77
77
  end
78
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmuh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
@@ -224,6 +224,7 @@ files:
224
224
  - README.md
225
225
  - Rakefile
226
226
  - lib/rmuh.rb
227
+ - lib/rmuh/rpt.rb
227
228
  - lib/rmuh/rpt/log/fetch.rb
228
229
  - lib/rmuh/rpt/log/parsers/base.rb
229
230
  - lib/rmuh/rpt/log/parsers/unitedoperationslog.rb