flox 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad9881566390837774beb2f6ba709d533e2cd94
4
- data.tar.gz: 25da47a5b5d16804352e2beba5e479b332f38ccf
3
+ metadata.gz: 4e270b70cbf4293d5e3ded85a0e179a1aadecb21
4
+ data.tar.gz: 7a9dd4ddb98a13d4491fbe12c677c8f77779a450
5
5
  SHA512:
6
- metadata.gz: f39a94d6a7edc427e1b003773f9f44c813a033339a52c13d748cdda5306b63c19c83e012253b2caa31386570c8743707c856b666e2e736cd4adb327e2c47a316
7
- data.tar.gz: 539663241fe8bfea69b91f928f052b88fea07029037ed4a56da069db6e080053708be529d972ef48b125fdc761ac2e494980b6bc0fc9798e80201a0e61951590
6
+ metadata.gz: 9233cde0da9935db8d8e9b4aa2e00177eee2f68c2ef46a9db828b3f247fa2a609fe15ac9198b13fbbf6aeb0db18da71b580edbb632ced6491807f0b4ef01f2c2
7
+ data.tar.gz: d748fe1818ce22e485257ed39916ab5211cb8b0a18c0f1f05ae53578726391de3e0a764934ce1c8f48d85ba043cd6ff207ab9f96880a9b7b17fb2dad9944e7d8
data/bin/flox CHANGED
@@ -4,43 +4,36 @@
4
4
  ## Copyright: Copyright 2014 Gamua
5
5
  ## License: Simplified BSD
6
6
 
7
- $LOAD_PATH << '../lib'
8
-
9
7
  require 'flox'
10
8
  require 'fileutils'
11
- require 'trollop'
9
+ require 'slop'
12
10
 
11
+ # Helper class that does the heavy lifting.
13
12
  class Worker
14
13
 
15
14
  attr_reader :flox
16
15
 
17
- def initialize(game_id, game_key, base_url)
18
- @flox = Flox.new(game_id, game_key, base_url)
19
- end
20
-
21
- def login_with_key(key)
22
- flox.login_with_key(key)
23
- end
16
+ def initialize(args={})
17
+ base_url = args[:url] || Flox::DEFAULT_URL
18
+ game_id = args[:game_id]
19
+ game_key = args[:game_key]
20
+ hero_key = args[:hero_key]
24
21
 
25
- def execute(command_name, args)
26
- begin
27
- method_name = command_name.downcase.gsub("-", "_")
28
- self.send(method_name, **args)
29
- rescue Exception => e
30
- log "Error: " + e.to_s
31
- end
22
+ @flox = Flox.new(game_id, game_key, base_url)
23
+ print "Logging in as Hero ... "
24
+ @flox.login_with_key hero_key
25
+ puts "done."
32
26
  end
33
27
 
34
- private
35
-
36
- def download_logs(args={})
28
+ def load_logs(args={})
37
29
  query = args[:query]
38
30
  limit = args[:limit]
39
31
  destination = args[:destination] || Dir.pwd
40
32
  FileUtils.mkdir_p(destination)
41
33
 
42
- log "Fetching Logs ..."
34
+ print "Loading log IDs (this could take a moment) ... "
43
35
  log_ids = flox.load_log_ids(query, limit)
36
+ puts "found #{log_ids.length} logs."
44
37
  log_ids.each do |log_id|
45
38
  remote_path = "logs/#{log_id}"
46
39
  local_path = File.join(destination, log_id) + ".json"
@@ -48,55 +41,55 @@ class Worker
48
41
  end
49
42
  end
50
43
 
51
- def status(args={})
52
- log "Fetching Server Status ..."
53
- status = flox.status
54
- log "Version: #{status['version']}, status: #{status['status']}"
55
- end
56
-
57
- def log(message)
58
- puts message
59
- end
60
-
61
- def fail(message)
62
- log message
63
- exit
64
- end
44
+ private
65
45
 
66
46
  def load_and_save_resource(remote_path, local_path)
67
47
  if (File.exists? local_path)
68
- log("Skipped #{local_path} (file exists)")
48
+ puts("Skipped #{local_path} (file exists)")
69
49
  else
70
50
  resource = flox.load_resource(remote_path)
71
51
  File.write(local_path, JSON.pretty_generate(resource))
72
- log("Saved #{local_path}")
52
+ puts("Saved #{local_path}")
73
53
  end
74
54
  end
75
55
 
76
56
  end
77
57
 
78
- options = Trollop::options do
79
- banner "Administrative utility for the Flox.cc Game Backend"
80
- opt :key, "The 'Hero' key used for authentication", :type => :string, :required => true
81
- opt :game_id, "The ID of the game", :type => :string, :required => true
82
- opt :game_key, "The key of the game", :type => :string, :required => true
83
- opt :base_url, "The URL of the Flox service", :type => :string
84
- opt :destination, "The directory in which to store the logs", :type => :string
85
- opt :query, "Narrows down the list of results", :type => :string
86
- opt :limit, "Maximum number of logs to download", :type => :int
58
+ #
59
+ # Parsing command line arguments
60
+ #
61
+
62
+ def shared_options
63
+ on :i, "game_id=", "The public identifier of the game", :required => true
64
+ on :k, "game_key=", "The private key of the game", :required => true
65
+ on :o, "hero_key=", "The key of a Hero player that will be logged in", :required => true
66
+ on :u, "url=", "The URL to the Flox service"
87
67
  end
88
68
 
89
- commands = ARGV.clone
90
- # puts "Optons: #{options}"
69
+ begin
70
+
71
+ ARGV << "-h" if ARGV.empty?
72
+ Slop.parse(ARGV, :help => true) do
91
73
 
92
- hero_key = options[:key]
93
- game_id = options[:game_id]
94
- game_key = options[:game_key]
95
- base_url = options[:base_url] || Flox::DEFAULT_URL
74
+ on :v, "version", 'Print the current version of the Flox Gem.' do
75
+ puts "Gamua Flox v#{Flox::VERSION}"
76
+ end
96
77
 
97
- worker = Worker.new(game_id, game_key, base_url)
98
- worker.login_with_key(hero_key)
78
+ command "load_logs" do
79
+ description "Fetch log files from the server."
80
+
81
+ shared_options
82
+ on :d, "destination=", "The directory in which to store the logs"
83
+ on :q, "query=", "Narrow down the results, e.g. 'day:2013-12-24 severity:error'"
84
+ on :l, "limit=", "Maximum number of logs to download", as: Integer
85
+
86
+ run do |opts, args|
87
+ Worker.new(opts).load_logs(opts)
88
+ end
89
+ end
90
+
91
+ end
99
92
 
100
- commands.each do |command|
101
- worker.execute(command, options)
93
+ rescue Slop::Error, Flox::Error => error
94
+ puts error
102
95
  end
@@ -8,6 +8,9 @@
8
8
  # of all players.
9
9
  class Flox
10
10
 
11
+ # The main Error class, all Exception classes inherit from this class.
12
+ class Error < StandardError; end
13
+
11
14
  # The URL where the Flox servers are found.
12
15
  DEFAULT_URL = "https://www.flox.cc"
13
16
 
@@ -115,7 +115,7 @@ class Flox::RestService
115
115
  rescue
116
116
  response.body
117
117
  end
118
- raise message
118
+ raise Flox::Error, message
119
119
  end
120
120
  end
121
121
  end
@@ -9,6 +9,6 @@
9
9
  class Flox
10
10
 
11
11
  # The current version of the Flox SDK.
12
- VERSION = '0.0.2'
12
+ VERSION = '0.1.0'
13
13
 
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Sperl
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.7
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mocha
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +86,8 @@ description: |
72
86
  specific entities. It can be used from other Ruby scripts or directly with
73
87
  its bundled command-line utility.
74
88
  email: daniel@gamua.com
75
- executables: []
89
+ executables:
90
+ - flox
76
91
  extensions: []
77
92
  extra_rdoc_files: []
78
93
  files: