arkrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ require 'mkmf'
2
+ require 'oga'
3
+ require 'open-uri'
4
+ require 'arkrb'
5
+ require 'arkrb/error'
6
+ require 'arkrb/server/mods'
7
+ module Arkrb
8
+ class Server
9
+
10
+ def initialize(instance_name, sanitize_output = true)
11
+ @instance_name = instance_name
12
+ @sanitize_output = sanitize_output
13
+ mod_list
14
+ end
15
+
16
+ attr_reader :instance_name, :mod_list
17
+
18
+ def install
19
+ arkmanager_exec :install
20
+ end
21
+
22
+ # @return [True, Exception]
23
+ def start!(verbose = false)
24
+ arkmanager_exec :start
25
+ end
26
+
27
+ # @return [True, Exception]
28
+ def stop!
29
+ arkmanager_exec :stop
30
+ end
31
+
32
+ # @return [True, Exception]
33
+ def restart!
34
+ arkmanager_exec :restart
35
+ end
36
+
37
+ def status!
38
+ arkmanager_exec :status
39
+ end
40
+
41
+ # @return [True, Exception]
42
+ def update!
43
+ arkmanager_exec :update
44
+ end
45
+
46
+ # @return [True, Exception]
47
+ def backup!
48
+ arkmanager_exec :backup
49
+ end
50
+
51
+ # @return [True, Exception]
52
+ def save_world!
53
+ arkmanager_exec :save_world
54
+ end
55
+
56
+ # @return [True, Exception]
57
+ def enable_mod(mod_id)
58
+ arkmanager_exec(:enable_mod, mod_id)
59
+ end
60
+
61
+ # @return [True, Exception]
62
+ def disable_mod(mod_id)
63
+ arkmanager_exec(:disable_mod, mod_id)
64
+ end
65
+
66
+ # @return [True, Exception]
67
+ def install_mod(mod_id)
68
+ arkmanager_exec(:install_mod, mod_id)
69
+ end
70
+
71
+ # @return [True, Exception]
72
+ def uninstall_mod(mod_id)
73
+ arkmanager_exec(:uninstall_mod, mod_id)
74
+ end
75
+
76
+ # @return [True, Exception]
77
+ def reinstall_mod(mod_id)
78
+ arkmanager_exec(:reinstall_mod, mod_id)
79
+ end
80
+
81
+ # @return [True, Exception]
82
+ def broadcast(message)
83
+ arkmanager_exec(:broadcast, message)
84
+ end
85
+
86
+ # @return [Object]
87
+ def rcon_cmd(command)
88
+ arkmanager_exec(:rcon, command)
89
+ end
90
+
91
+ # @return [Boolean]
92
+ def update_available?
93
+ arkmanager_exec :check_update
94
+ end
95
+
96
+ # @return [Boolean]
97
+ def mod_updates_available?
98
+ arkmanager_exec :check_mod_update
99
+ end
100
+
101
+ def mod_list
102
+ @mod_list ||= Arkrb::Mods.new
103
+ end
104
+
105
+ private
106
+
107
+ def arkmanager_exec(command, command_opts = '')
108
+ Arkrb.execute(command, command_opts, instance_name, @sanitize_output)
109
+ end
110
+
111
+ end
112
+ end
113
+
114
+ # server = Arkrb::Server.new('main')
115
+ # server.mod_list.add(731604991)
116
+ #
117
+ # pp server
118
+ #
119
+ # pp server.mod_list.to_h
120
+ #
121
+ #
122
+ #
123
+ # mod_list = Arkrb::Mods.new
124
+ #
125
+ # pp mod_list
126
+ # mod_a = 731604991
127
+ # mod_b = 812655342
128
+ #
129
+ # mod_list.add(731604991)
130
+ # mod_list.add(812655342)
131
+ # pp mod_list.to_h
132
+ # # mod_list.add(731604991)
133
+ # # pp mod_list.find_by_id(mod_a).to_h
@@ -0,0 +1,57 @@
1
+ require 'oga'
2
+ require 'open-uri'
3
+ require 'digest/md5'
4
+ module Arkrb
5
+ class Mod
6
+ def initialize(mod_id)
7
+ @id = mod_id.to_i
8
+ @workshop_url = "https://steamcommunity.com/sharedfiles/filedetails/?id=#{mod_id}"
9
+ @changelog_url = "https://steamcommunity.com/sharedfiles/filedetails/changelog/#{mod_id}"
10
+
11
+ does_mod_exist?
12
+
13
+ @name = update_mod_name
14
+ @version_tag = latest_version_tag
15
+ end
16
+
17
+ attr :id, :name, :version_tag, :workshop_url, :changelog_url
18
+
19
+ def update_info
20
+ self.name = update_mod_name
21
+ self.version = latest_version_tag
22
+ end
23
+
24
+ def update_mod_name
25
+ document = Oga.parse_html(open(changelog_url))
26
+ document.at_css('div[class="workshopItemTitle"]').text
27
+ end
28
+
29
+ def latest_version_tag
30
+ document = Oga.parse_html(open(changelog_url))
31
+ version = document.at_css('div[class~="workshopAnnouncement"]:nth-child(3) > div[class="headline"]').text.strip
32
+ Digest::MD5.hexdigest(version).strip
33
+ end
34
+
35
+ def does_mod_exist?
36
+ document = Oga.parse_html(open(workshop_url))
37
+ if document.at_css('div[class="error_ctn"] h3').text == 'That item does not exist. It may have been removed by the author.'
38
+ raise Arkrb::Error::ModDoesNotExist, "Woah the mod #{id} does not exist!"
39
+ end
40
+ rescue NoMethodError
41
+ true
42
+ end
43
+
44
+ def to_h
45
+ {
46
+ id: id,
47
+ name: name,
48
+ version_tag: version_tag,
49
+ workshop_url: workshop_url,
50
+ changelog_url: changelog_url
51
+ }
52
+ end
53
+
54
+ alias_method :to_hash, :to_h
55
+
56
+ end
57
+ end
@@ -0,0 +1,59 @@
1
+ require 'arkrb/error'
2
+ require 'arkrb/server/mod'
3
+ module Arkrb
4
+ class Mods
5
+ def initialize
6
+ @mod_list = []
7
+ end
8
+
9
+ # @return [Arkrb::Mod, Exception]
10
+ def find_by_id(id)
11
+ mod = @mod_list.find {|m| m.id == id}
12
+ if mod.nil?
13
+ raise Arkrb::Error::ModIDNotFound, "Mod #{id} was not found in the mod list!"
14
+ else
15
+ mod
16
+ end
17
+ end
18
+
19
+ # @return [Arkrb::Mod, Exception]
20
+ def add(id)
21
+ begin
22
+ find_by_id(id)
23
+ raise Arkrb::Error::ModAlreadyExists, "Mod #{id} already exists in the mod list!"
24
+ rescue Arkrb::Error::ModIDNotFound
25
+ mod = Arkrb::Mod.new(id)
26
+ @mod_list << mod
27
+ mod
28
+ end
29
+ end
30
+
31
+ # @return [True, Exception]
32
+ def delete(id)
33
+ find_by_id(id)
34
+ @mod_list.delete_if {|m| m.id == id}
35
+ true
36
+ end
37
+
38
+ # @return [Hash]
39
+ def to_h
40
+ @mod_list.map {|m| m.to_h}
41
+ end
42
+
43
+ alias_method :to_hash, :to_h
44
+
45
+ end
46
+ end
47
+
48
+
49
+ # mod_list = Arkrb::Mods.new
50
+ #
51
+ # pp mod_list
52
+ # mod_a = 731604991
53
+ # mod_b = 812655342
54
+ #
55
+ # mod_list.add(731604991)
56
+ # mod_list.add(812655342)
57
+ # pp mod_list.to_h
58
+ # # mod_list.add(731604991)
59
+ # # pp mod_list.find_by_id(mod_a).to_h
@@ -0,0 +1,3 @@
1
+ module Arkrb
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arkrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bruno
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.12
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: oga
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.3.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: thor
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.20.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.20.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: colorize
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.8.1
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.8.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.16'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.16'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.11.3
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.11.3
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '10.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: yard
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.9.12
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.9.12
131
+ - !ruby/object:Gem::Dependency
132
+ name: minitest
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '5.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '5.0'
145
+ description: Gem wrapper for ark-server-tools
146
+ email:
147
+ - michael.bruno1337@gmail.com
148
+ executables:
149
+ - arkrb
150
+ extensions: []
151
+ extra_rdoc_files: []
152
+ files:
153
+ - ".gitignore"
154
+ - ".ruby-version"
155
+ - ".travis.yml"
156
+ - CODE_OF_CONDUCT.md
157
+ - Gemfile
158
+ - Gemfile.lock
159
+ - LICENSE.txt
160
+ - README.md
161
+ - Rakefile
162
+ - arkrb.gemspec
163
+ - bin/console
164
+ - bin/setup
165
+ - exe/arkrb
166
+ - lib/arkrb.rb
167
+ - lib/arkrb/cli.rb
168
+ - lib/arkrb/constants.rb
169
+ - lib/arkrb/error.rb
170
+ - lib/arkrb/error_parsing.rb
171
+ - lib/arkrb/install.rb
172
+ - lib/arkrb/output_parsing.rb
173
+ - lib/arkrb/server.rb
174
+ - lib/arkrb/server/mod.rb
175
+ - lib/arkrb/server/mods.rb
176
+ - lib/arkrb/version.rb
177
+ homepage: https://github.com/mbround18/ark_rb
178
+ licenses:
179
+ - MIT
180
+ metadata:
181
+ allowed_push_host: https://rubygems.org/
182
+ yard.run: yri
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.7.3
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: This is a wrapper for ark server tools which is located at
203
+ test_files: []