Class: GameMachine::Console::Bundle
- Inherits:
-
Object
- Object
- GameMachine::Console::Bundle
- Defined in:
- lib/game_machine/console/bundle.rb
Instance Attribute Summary collapse
-
#bundle_dir ⇒ Object
readonly
Returns the value of attribute bundle_dir.
-
#bundle_file ⇒ Object
readonly
Returns the value of attribute bundle_file.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #conn ⇒ Object
- #create_bundle ⇒ Object
-
#initialize(argv) ⇒ Bundle
constructor
A new instance of Bundle.
- #run! ⇒ Object
- #upload_bundle(name) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Bundle
Returns a new instance of Bundle.
27 28 29 30 31 32 |
# File 'lib/game_machine/console/bundle.rb', line 27 def initialize(argv) @command = argv.shift @name = argv.shift @bundle_dir = File.join(ENV['APP_ROOT'],'.game_machine') @bundle_file = File.join(bundle_dir,'bundle.zip') end |
Instance Attribute Details
#bundle_dir ⇒ Object (readonly)
Returns the value of attribute bundle_dir.
26 27 28 |
# File 'lib/game_machine/console/bundle.rb', line 26 def bundle_dir @bundle_dir end |
#bundle_file ⇒ Object (readonly)
Returns the value of attribute bundle_file.
26 27 28 |
# File 'lib/game_machine/console/bundle.rb', line 26 def bundle_file @bundle_file end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
26 27 28 |
# File 'lib/game_machine/console/bundle.rb', line 26 def command @command end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/game_machine/console/bundle.rb', line 26 def name @name end |
Instance Method Details
#conn ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/game_machine/console/bundle.rb', line 56 def conn Faraday.new do |f| f.request :multipart f.request :url_encoded #f.response :logger f.adapter Faraday.default_adapter end end |
#create_bundle ⇒ Object
65 66 67 68 69 70 |
# File 'lib/game_machine/console/bundle.rb', line 65 def create_bundle FileUtils.mkdir_p(bundle_dir) FileUtils.rm_f(bundle_file) system("cd #{ENV['APP_ROOT']} && bundle install --path=.game_machine/vendor/bundle >> /dev/null && rm -rf #{ENV['APP_ROOT']}/.bundle") system("cd #{ENV['APP_ROOT']} && zip -r .game_machine/bundle.zip games config db lib java bin script web .game_machine/vendor mono >> /dev/null") end |
#run! ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/game_machine/console/bundle.rb', line 72 def run! if name.nil? || name.blank? puts "Must specify bundle name" puts "Usage: game_machine service push [bundle name]" exit end puts "Creating bundle" create_bundle puts "Uploading bundle to server" response = upload_bundle(name) if response.status == 204 puts "Push Successful" else puts response.body puts "Push failed, server returned #{response.status}" end end |
#upload_bundle(name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/game_machine/console/bundle.rb', line 35 def upload_bundle(name) username = AppConfig.instance.config.gamecloud.user api_key = AppConfig.instance.config.gamecloud.api_key host = AppConfig.instance.config.gamecloud.host url = "http://#{host}/bundle/#{username}/upload" token = Digest::SHA256.hexdigest("#{username}#{name}#{api_key}") file = Faraday::UploadIO.new(bundle_file, 'application/octet-stream') body = { :file => file, :name => name } response = conn.post do |req| req.[:timeout] = 10 req.[:open_timeout] = 2 req.url url req.headers['X-Auth'] = token req.body = body end end |