cloudwalk 0.6.0 → 0.7.0
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 +4 -4
- data/exe/i386-apple-darwin14 +0 -0
- data/exe/i686-pc-linux-gnu +0 -0
- data/exe/i686-w64-mingw32.exe +0 -0
- data/exe/x86_64-apple-darwin14 +0 -0
- data/exe/x86_64-pc-linux-gnu +0 -0
- data/exe/x86_64-w64-mingw32.exe +0 -0
- data/lib/cloudwalk.rb +8 -3
- data/lib/cloudwalk/config.rb +1 -1
- data/lib/cloudwalk/cw_file_json.rb +76 -138
- data/lib/cloudwalk/cw_file_json_exception.rb +4 -0
- data/lib/cloudwalk/deploy.rb +73 -0
- data/lib/cloudwalk/deploy_exception.rb +4 -0
- data/lib/cloudwalk/manager_helper.rb +24 -0
- data/lib/cloudwalk/posxml/posxml_application.rb +40 -0
- data/lib/cloudwalk/posxml/posxml_version.rb +77 -0
- data/lib/cloudwalk/posxml/rake_task.rb +90 -0
- data/lib/cloudwalk/ruby/rake_task.rb +57 -0
- data/lib/cloudwalk/ruby/ruby_application.rb +71 -0
- metadata +11 -5
- data/lib/cloudwalk/posxml_application.rb +0 -44
- data/lib/cloudwalk/posxml_version.rb +0 -66
- data/lib/cloudwalk/rake_task.rb +0 -89
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6a7426aa8b410bc7e519a77d25818fa6c688fa57
         | 
| 4 | 
            +
              data.tar.gz: ad600f23ebb2665d339a0438b0ca7ba4e6afdd12
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5395cee97c912694bd1105d164bfa36577d5fda4c4c369beb0b0c69f991c5e3865201e32d297400e62aa0d905b856bcd282d3efa36d3d272b0ac0cfdb789153d
         | 
| 7 | 
            +
              data.tar.gz: 92fa1ea8a4f71b598fbb4fc481df5446507431f1fd373075faf0dba7c6c062a3a0e75c04fbab89c52e3255242dfeed40a298e92ad585b80003f7677c07989210
         | 
    
        data/exe/i386-apple-darwin14
    CHANGED
    
    | Binary file | 
    
        data/exe/i686-pc-linux-gnu
    CHANGED
    
    | Binary file | 
    
        data/exe/i686-w64-mingw32.exe
    CHANGED
    
    | Binary file | 
    
        data/exe/x86_64-apple-darwin14
    CHANGED
    
    | Binary file | 
    
        data/exe/x86_64-pc-linux-gnu
    CHANGED
    
    | Binary file | 
    
        data/exe/x86_64-w64-mingw32.exe
    CHANGED
    
    | Binary file | 
    
        data/lib/cloudwalk.rb
    CHANGED
    
    | @@ -3,8 +3,13 @@ require "net/http" | |
| 3 3 | 
             
            require "json"
         | 
| 4 4 | 
             
            require "fileutils"
         | 
| 5 5 |  | 
| 6 | 
            +
            require_relative "cloudwalk/manager_exception"
         | 
| 7 | 
            +
            require_relative "cloudwalk/manager_helper"
         | 
| 6 8 | 
             
            require_relative "cloudwalk/config"
         | 
| 7 9 | 
             
            require_relative "cloudwalk/cw_file_json"
         | 
| 8 | 
            -
            require_relative "cloudwalk/ | 
| 9 | 
            -
            require_relative "cloudwalk/ | 
| 10 | 
            -
            require_relative "cloudwalk/ | 
| 10 | 
            +
            require_relative "cloudwalk/deploy"
         | 
| 11 | 
            +
            require_relative "cloudwalk/posxml/posxml_application"
         | 
| 12 | 
            +
            require_relative "cloudwalk/posxml/posxml_version"
         | 
| 13 | 
            +
            require_relative "cloudwalk/posxml/rake_task"
         | 
| 14 | 
            +
            require_relative "cloudwalk/ruby/ruby_application"
         | 
| 15 | 
            +
            require_relative "cloudwalk/ruby/rake_task"
         | 
    
        data/lib/cloudwalk/config.rb
    CHANGED
    
    | @@ -8,7 +8,7 @@ module Cloudwalk | |
| 8 8 |  | 
| 9 9 | 
             
                def self.host
         | 
| 10 10 | 
             
                  @host ||= `cloudwalk config host`.chomp
         | 
| 11 | 
            -
                  raise ManagerException.new(" | 
| 11 | 
            +
                  raise ManagerException.new("Host not found, try 'cloudwalk login'") if @host.empty?
         | 
| 12 12 | 
             
                  @host
         | 
| 13 13 | 
             
                end
         | 
| 14 14 | 
             
              end
         | 
| @@ -21,6 +21,8 @@ | |
| 21 21 |  | 
| 22 22 | 
             
            module Cloudwalk
         | 
| 23 23 | 
             
              class CwFileJson
         | 
| 24 | 
            +
                include Cloudwalk::ManagerHelper
         | 
| 25 | 
            +
             | 
| 24 26 | 
             
                CW_FILE_LOCK_PATH = "./Cwfile.json.lock"
         | 
| 25 27 | 
             
                CW_FILE_PATH      = "./Cwfile.json"
         | 
| 26 28 |  | 
| @@ -105,83 +107,57 @@ module Cloudwalk | |
| 105 107 | 
             
                end
         | 
| 106 108 |  | 
| 107 109 | 
             
                def self.lock_build
         | 
| 108 | 
            -
                  all = Cloudwalk::PosxmlApplication.all
         | 
| 109 110 | 
             
                  config = []
         | 
| 110 | 
            -
                  self. | 
| 111 | 
            -
                     | 
| 112 | 
            -
             | 
| 113 | 
            -
                    versions   = Cloudwalk::PosxmlVersion.all(app_posxml["id"])
         | 
| 114 | 
            -
                    version    = versions.find { |json| json["app_version"]["number"] == app_local["version"] }
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                    if version && version = version["app_version"]
         | 
| 117 | 
            -
                      version_detail = Cloudwalk::PosxmlVersion.get(app_posxml["id"], version["id"])
         | 
| 118 | 
            -
                      config << build_application(app_posxml, version, version_detail["app_version"]["module_ids"])
         | 
| 111 | 
            +
                  if self.ruby?
         | 
| 112 | 
            +
                    if app = Cloudwalk::Ruby::RubyApplication.find(self.cwfile["name"])
         | 
| 113 | 
            +
                      config << build_application(:ruby, app)
         | 
| 119 114 | 
             
                    else
         | 
| 120 | 
            -
                      # TODO  | 
| 115 | 
            +
                      # TODO App not found, what to do?
         | 
| 116 | 
            +
                    end
         | 
| 117 | 
            +
                  else
         | 
| 118 | 
            +
                    self.cwfile["apps"].each do |app_local|
         | 
| 119 | 
            +
                      app, version = Cloudwalk::Posxml::PosxmlVersion.find(app_local["name"], app_local["version"])
         | 
| 120 | 
            +
                      if app && version
         | 
| 121 | 
            +
                        detail = Cloudwalk::Posxml::PosxmlVersion.get(app["id"], version["id"])
         | 
| 122 | 
            +
                        config << build_application(:posxml, app, version, detail["module_ids"])
         | 
| 123 | 
            +
                      else
         | 
| 124 | 
            +
                        raise Cloudwalk::CwFileJsonException.new("App (#{app_local["name"]}) Version (#{app_local["version"]}) not found")
         | 
| 125 | 
            +
                      end
         | 
| 121 126 | 
             
                    end
         | 
| 122 127 | 
             
                  end
         | 
| 128 | 
            +
             | 
| 123 129 | 
             
                  self.lock = config
         | 
| 124 130 | 
             
                end
         | 
| 125 131 |  | 
| 126 132 | 
             
                def self.build_module(mod)
         | 
| 127 | 
            -
                   | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
                     | 
| 134 | 
            -
                   | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
                def self.build_application(posxml_app, version_remote, modules_remote)
         | 
| 138 | 
            -
                  {
         | 
| 139 | 
            -
                    "name"       => posxml_app["name"],
         | 
| 140 | 
            -
                    "id"         => posxml_app["id"],
         | 
| 141 | 
            -
                    "modules"    => modules_remote.collect {|mod| build_module(mod)},
         | 
| 142 | 
            -
                    "version"    => version_remote["number"],
         | 
| 143 | 
            -
                    "version_id" => version_remote["id"]
         | 
| 144 | 
            -
                  }
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                  #old = config.find {|app| app["id"] == posxml_app["id"]}
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                  #if old
         | 
| 149 | 
            -
                    #config.delete(old)
         | 
| 150 | 
            -
                    #config << new
         | 
| 151 | 
            -
                  #else
         | 
| 152 | 
            -
                    #config << new
         | 
| 153 | 
            -
                  #end
         | 
| 133 | 
            +
                  if module_version = Cloudwalk::Posxml::PosxmlVersion.get(mod["app_id"], mod["version_id"])
         | 
| 134 | 
            +
                    {
         | 
| 135 | 
            +
                      "name"       => Cloudwalk::Posxml::PosxmlApplication.get_name(module_version["app_id"]),
         | 
| 136 | 
            +
                      "version"    => module_version["number"],
         | 
| 137 | 
            +
                      "id"         => module_version["app_id"],
         | 
| 138 | 
            +
                      "version_id" => module_version["id"]
         | 
| 139 | 
            +
                    }
         | 
| 140 | 
            +
                  else
         | 
| 141 | 
            +
                    raise Cloudwalk::CwFileJsonException.new("App (#{mod['app_id']}) Module Version (#{mod['version_id']}) not found")
         | 
| 142 | 
            +
                  end
         | 
| 154 143 | 
             
                end
         | 
| 155 144 |  | 
| 156 | 
            -
                 | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
                     | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
                       | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 172 | 
            -
                      raise Exception.new("application or module #{path} not found in Manager, please create it")
         | 
| 173 | 
            -
                    end
         | 
| 174 | 
            -
             | 
| 175 | 
            -
                    app_cwfile = self.cwfile["apps"].find {|config| config["name"] == posxml2xml(posxml) }
         | 
| 176 | 
            -
             | 
| 177 | 
            -
                    ret, response = Cloudwalk::PosxmlVersion.update(
         | 
| 178 | 
            -
                      app_lock["id"], app_lock["version_id"], File.read(path), app_cwfile
         | 
| 179 | 
            -
                    )
         | 
| 180 | 
            -
                    if ret
         | 
| 181 | 
            -
                      STDOUT.write("\r=> Success Deployed                               \n")
         | 
| 182 | 
            -
                    else
         | 
| 183 | 
            -
                      STDOUT.write("\r=> Error #{response.code}:#{response.body}\n")
         | 
| 184 | 
            -
                    end
         | 
| 145 | 
            +
                def self.build_application(type, app, version = nil, modules_remote = nil)
         | 
| 146 | 
            +
                  if type == :ruby
         | 
| 147 | 
            +
                    {
         | 
| 148 | 
            +
                      "name"       => app["name"],
         | 
| 149 | 
            +
                      "id"         => app["id"],
         | 
| 150 | 
            +
                      "modules"    => [],
         | 
| 151 | 
            +
                      "version"    => "1.0.0"
         | 
| 152 | 
            +
                    }
         | 
| 153 | 
            +
                  else
         | 
| 154 | 
            +
                    {
         | 
| 155 | 
            +
                      "name"       => app["name"],
         | 
| 156 | 
            +
                      "id"         => app["id"],
         | 
| 157 | 
            +
                      "modules"    => modules_remote.collect {|mod| build_module(mod)},
         | 
| 158 | 
            +
                      "version"    => version["number"],
         | 
| 159 | 
            +
                      "version_id" => version["id"]
         | 
| 160 | 
            +
                    }
         | 
| 185 161 | 
             
                  end
         | 
| 186 162 | 
             
                end
         | 
| 187 163 |  | 
| @@ -193,32 +169,45 @@ module Cloudwalk | |
| 193 169 | 
             
                  File.exists? CW_FILE_LOCK_PATH
         | 
| 194 170 | 
             
                end
         | 
| 195 171 |  | 
| 196 | 
            -
                def self. | 
| 197 | 
            -
                   | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 200 | 
            -
                def self.xml2posxml(str)
         | 
| 201 | 
            -
                  str.sub(".xml", ".posxml")
         | 
| 172 | 
            +
                def self.ruby?
         | 
| 173 | 
            +
                  if self.cwfile
         | 
| 174 | 
            +
                    self.cwfile["runtime"] == "ruby"
         | 
| 175 | 
            +
                  end
         | 
| 202 176 | 
             
                end
         | 
| 203 177 |  | 
| 204 | 
            -
                 | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
                   | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 210 | 
            -
             | 
| 211 | 
            -
             | 
| 178 | 
            +
                def self.cwfile_apps_and_versions
         | 
| 179 | 
            +
                  if self.ruby?
         | 
| 180 | 
            +
                    [self.cwfile["name"], self.cwfile["version"]]
         | 
| 181 | 
            +
                  else
         | 
| 182 | 
            +
                    self.cwfile["apps"].inject([]) do |array, app|
         | 
| 183 | 
            +
                      array << [app["name"], app["version"]]
         | 
| 184 | 
            +
                      app["modules"].each do |app_module|
         | 
| 185 | 
            +
                        array << [app_module[0], app_module[1]]
         | 
| 186 | 
            +
                      end
         | 
| 187 | 
            +
                      array
         | 
| 212 188 | 
             
                    end
         | 
| 213 189 | 
             
                  end
         | 
| 190 | 
            +
                end
         | 
| 214 191 |  | 
| 215 | 
            -
             | 
| 216 | 
            -
                  self.lock. | 
| 217 | 
            -
                     | 
| 218 | 
            -
             | 
| 219 | 
            -
             | 
| 192 | 
            +
                def self.lock_apps_and_versions
         | 
| 193 | 
            +
                  self.lock.inject([]) do |array, app|
         | 
| 194 | 
            +
                    if self.ruby?
         | 
| 195 | 
            +
                      array.concat([app["name"], app["version"]])
         | 
| 196 | 
            +
                    else
         | 
| 197 | 
            +
                      array << [posxml2xml(app["name"]), app["version"]]
         | 
| 198 | 
            +
                      app["modules"].each do |app_module|
         | 
| 199 | 
            +
                        array << [posxml2xml(app_module["name"]), posxml2xml(app_module["version"])]
         | 
| 200 | 
            +
                      end
         | 
| 201 | 
            +
                      array
         | 
| 220 202 | 
             
                    end
         | 
| 221 203 | 
             
                  end
         | 
| 204 | 
            +
                end
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                # TODO future!
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                def self.compare
         | 
| 209 | 
            +
                  cwfile_list = self.cwfile_apps_and_versions
         | 
| 210 | 
            +
                  lock_list = self.lock_apps_and_versions
         | 
| 222 211 |  | 
| 223 212 | 
             
                  cwdiff = cwfile_list - lock_list
         | 
| 224 213 | 
             
                  lockdiff = lock_list - cwfile_list
         | 
| @@ -233,57 +222,6 @@ module Cloudwalk | |
| 233 222 | 
             
                    true
         | 
| 234 223 | 
             
                  end
         | 
| 235 224 | 
             
                end
         | 
| 236 | 
            -
             | 
| 237 | 
            -
                def compare_modules(local_app, module_ids)
         | 
| 238 | 
            -
                  local_module_app_ids = local_app["modules"].inject([]) do |mods, app|
         | 
| 239 | 
            -
                    mods << app["id"]
         | 
| 240 | 
            -
                  end
         | 
| 241 | 
            -
             | 
| 242 | 
            -
                  module_app_ids = module_ids.inject([]) do |mods, app|
         | 
| 243 | 
            -
                    mods << app["app_id"]
         | 
| 244 | 
            -
                  end
         | 
| 245 | 
            -
             | 
| 246 | 
            -
                  local_creation = local_module_app_ids - module_app_ids
         | 
| 247 | 
            -
                  remote_creation = module_app_ids - local_module_app_ids
         | 
| 248 | 
            -
             | 
| 249 | 
            -
                  if local_creation.nil?
         | 
| 250 | 
            -
                    raise ApplicationConfigError.new("Application #{local_app["name"]}: Local modules are missing #{local_creation}")
         | 
| 251 | 
            -
                  end
         | 
| 252 | 
            -
             | 
| 253 | 
            -
                  if remote_creation.nil?
         | 
| 254 | 
            -
                    raise ApplicationConfigError.new("Application #{local_app["name"]}: Remote modules are missing #{local_creation}")
         | 
| 255 | 
            -
                  end
         | 
| 256 | 
            -
                end
         | 
| 257 | 
            -
             | 
| 258 | 
            -
                # curl -X GET "https://api-staging.cloudwalk.io/v1/apps/posxml?access_token=d79db7b1dc59c9c5a1f369478444625a0d1adef8"
         | 
| 259 | 
            -
                # curl -X GET "https://manager.cloudwalk.io/v1/apps/posxml/3082/versions?access_token=d79db7b1dc59c9c5a1f369478444625a0d1adef8"
         | 
| 260 | 
            -
                def update_apps(list, apps, config)
         | 
| 261 | 
            -
                  all = Cloudwalk::PosxmlApplication.all
         | 
| 262 | 
            -
                  list.each do |app, version|
         | 
| 263 | 
            -
                    local_app = apps.find { |json| json["name"] == app }
         | 
| 264 | 
            -
             | 
| 265 | 
            -
                    if app[-4..-1] == ".xml" # Check if is posxml application
         | 
| 266 | 
            -
                      remote_app = all.find { |app_json| app_json["posxml_app"]["name"] == xml2posxml(app) }
         | 
| 267 | 
            -
             | 
| 268 | 
            -
                      if remote_app
         | 
| 269 | 
            -
                        remote_posxml_app   = remote_app["posxml_app"]
         | 
| 270 | 
            -
                        remote_versions     = Cloudwalk::PosxmlVersion.all(remote_posxml_app["id"])
         | 
| 271 | 
            -
                        remote_version_json = remote_versions.find { |json| json["app_version"]["number"] == version }
         | 
| 272 | 
            -
             | 
| 273 | 
            -
                        if remote_version_json && (remote_version = remote_version_json["app_version"])
         | 
| 274 | 
            -
                          remote_version_detail = Cloudwalk::PosxmlVersion.get(remote_posxml_app["id"], remote_version["id"])
         | 
| 275 | 
            -
                          # TODO: Check if application exists locally
         | 
| 276 | 
            -
                          build_application(local_app, config, remote_posxml_app, remote_version, remote_version_detail["app_version"]["module_ids"])
         | 
| 277 | 
            -
                        else
         | 
| 278 | 
            -
                          # TODO versions not found, what to do?
         | 
| 279 | 
            -
                        end
         | 
| 280 | 
            -
                      else
         | 
| 281 | 
            -
                        # TODO app not found, what to do?
         | 
| 282 | 
            -
                      end
         | 
| 283 | 
            -
                    else
         | 
| 284 | 
            -
                      # Ruby flow
         | 
| 285 | 
            -
                    end
         | 
| 286 | 
            -
                  end
         | 
| 287 | 
            -
                end
         | 
| 288 225 | 
             
              end
         | 
| 289 226 | 
             
            end
         | 
| 227 | 
            +
             | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            module Cloudwalk
         | 
| 2 | 
            +
              class Deploy
         | 
| 3 | 
            +
                include Cloudwalk::ManagerHelper
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                attr_accessor :cwfile, :lock
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(cwfile, lock)
         | 
| 8 | 
            +
                  @cwfile = cwfile
         | 
| 9 | 
            +
                  @lock   = lock
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                # TODO Check CRC
         | 
| 13 | 
            +
                def posxml(outs)
         | 
| 14 | 
            +
                  outs.each do |path|
         | 
| 15 | 
            +
                    posxml   = path.split("/").last
         | 
| 16 | 
            +
                    print "=> Deploying #{posxml}"
         | 
| 17 | 
            +
                    app_lock = self.lock.find {|config| config["name"] == posxml }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    unless app_lock
         | 
| 20 | 
            +
                      self.lock.each do |application|
         | 
| 21 | 
            +
                        app_lock = application["modules"].find {|config| config["name"] == posxml }
         | 
| 22 | 
            +
                        break if app_lock
         | 
| 23 | 
            +
                      end
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    unless app_lock
         | 
| 27 | 
            +
                      # TODO Improve!
         | 
| 28 | 
            +
                      raise DeployException.new("application or module #{path} not found in Manager, please create it")
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    app_cwfile = self.cwfile["apps"].find {|config| config["name"] == posxml2xml(posxml) }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    ret, response = Cloudwalk::Posxml::PosxmlVersion.update(
         | 
| 34 | 
            +
                      app_lock["id"], app_lock["version_id"], File.read(path), app_cwfile
         | 
| 35 | 
            +
                    )
         | 
| 36 | 
            +
                    if ret
         | 
| 37 | 
            +
                      STDOUT.write("\r=> Success Deployed                               \n")
         | 
| 38 | 
            +
                    else
         | 
| 39 | 
            +
                      STDOUT.write("\r=> Error #{response.code}:#{response.body}\n")
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def name
         | 
| 45 | 
            +
                  self.cwfile["name"] 
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def ruby
         | 
| 49 | 
            +
                  zip = "out/#{self.name}.zip"
         | 
| 50 | 
            +
                  if File.exists? zip
         | 
| 51 | 
            +
                    print "=> Deploying #{self.name}"
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    app_lock = self.lock.find {|config| config["name"] == self.name }
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    unless app_lock
         | 
| 56 | 
            +
                      # TODO Improve!
         | 
| 57 | 
            +
                      raise DeployException.new("application #{self.name} not found at Manager, please create it")
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    ret, response = Cloudwalk::Ruby::RubyApplication.update(
         | 
| 61 | 
            +
                      app_lock["id"], File.read(zip), self.cwfile
         | 
| 62 | 
            +
                    )
         | 
| 63 | 
            +
                    if ret
         | 
| 64 | 
            +
                      STDOUT.write("\r=> Success Deployed                               \n")
         | 
| 65 | 
            +
                    else
         | 
| 66 | 
            +
                      STDOUT.write("\r=> Error #{response.code}:#{response.body}\n")
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
                  else
         | 
| 69 | 
            +
                    raise DeployException.new("application package #{zip} not found")
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module Cloudwalk
         | 
| 2 | 
            +
              module ManagerHelper
         | 
| 3 | 
            +
                def self.included(base)
         | 
| 4 | 
            +
                  base.extend(self)
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def token
         | 
| 8 | 
            +
                  Cloudwalk::Config.token
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def host
         | 
| 12 | 
            +
                  Cloudwalk::Config.host
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def posxml2xml(str)
         | 
| 16 | 
            +
                  str.sub(".posxml", ".xml")
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def xml2posxml(str)
         | 
| 20 | 
            +
                  str.sub(".xml", ".posxml")
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module Cloudwalk
         | 
| 2 | 
            +
              module Posxml
         | 
| 3 | 
            +
                class PosxmlApplication
         | 
| 4 | 
            +
                  include Cloudwalk::ManagerHelper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def self.all
         | 
| 7 | 
            +
                    if @apps
         | 
| 8 | 
            +
                      @apps
         | 
| 9 | 
            +
                    else
         | 
| 10 | 
            +
                      response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100")))
         | 
| 11 | 
            +
                      raise ManagerException.new(response["message"]) if response["message"]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                      total_pages = response["pagination"]["total_pages"].to_i
         | 
| 14 | 
            +
                      apps = response["posxmlapps"]
         | 
| 15 | 
            +
                      (total_pages - 1).times do |page|
         | 
| 16 | 
            +
                        url = "#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100&page=#{page+2}"
         | 
| 17 | 
            +
                        response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 18 | 
            +
                        raise ManagerException.new(response["message"]) if response["message"]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                        apps.concat(response["posxmlapps"])
         | 
| 21 | 
            +
                      end
         | 
| 22 | 
            +
                      @apps = apps
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def self.get(id)
         | 
| 27 | 
            +
                    url = "#{self.host}/v1/apps/posxml/#{id}?access_token=#{self.token}"
         | 
| 28 | 
            +
                    response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 29 | 
            +
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    response["posxml_app"]
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def self.get_name(id)
         | 
| 35 | 
            +
                    get(id)["name"]
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
| 40 | 
            +
             | 
| @@ -0,0 +1,77 @@ | |
| 1 | 
            +
            module Cloudwalk
         | 
| 2 | 
            +
              module Posxml
         | 
| 3 | 
            +
                class PosxmlVersion
         | 
| 4 | 
            +
                  include Cloudwalk::ManagerHelper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def self.get_or_create(app, version)
         | 
| 7 | 
            +
                    response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
         | 
| 8 | 
            +
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    #TODO
         | 
| 11 | 
            +
                    #`curl -X GET "https://api-staging.cloudwalk.io/v1/apps/posxml/3082/versions?access_token=#{self.token}`
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def self.all(app_id)
         | 
| 15 | 
            +
                    response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
         | 
| 16 | 
            +
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    total_pages = response["pagination"]["total_pages"].to_i
         | 
| 19 | 
            +
                    versions = response["appversions"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    (total_pages - 1).times do |page|
         | 
| 22 | 
            +
                      url = "#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100&page=#{page+2}"
         | 
| 23 | 
            +
                      response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 24 | 
            +
                      raise ManagerException.new(response["message"]) if response["message"]
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                      versions.concat(response["posxmlapps"])
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                    versions
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  def self.get(app_id, id)
         | 
| 32 | 
            +
                    url = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{id}?access_token=#{token}"
         | 
| 33 | 
            +
                    response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 34 | 
            +
                    if response["message"]
         | 
| 35 | 
            +
                      raise ManagerException.new(response["message"]) 
         | 
| 36 | 
            +
                    else
         | 
| 37 | 
            +
                      response["app_version"]
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
             | 
| 42 | 
            +
                  # NEW
         | 
| 43 | 
            +
                  def self.find(app_name, version_name)
         | 
| 44 | 
            +
                    applications = Cloudwalk::Posxml::PosxmlApplication.all
         | 
| 45 | 
            +
                    app_remote   = applications.find { |app_json| app_json["posxml_app"]["name"] == xml2posxml(app_name) }
         | 
| 46 | 
            +
                    app_posxml   = app_remote["posxml_app"]
         | 
| 47 | 
            +
                    versions     = Cloudwalk::Posxml::PosxmlVersion.all(app_posxml["id"])
         | 
| 48 | 
            +
                    version      = versions.find { |json| json["app_version"]["number"] == version_name }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    [app_posxml, (version && version["app_version"])]
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  # NEW B4
         | 
| 54 | 
            +
                  def self.update(app_id, version_id, bytecode, app_parameters = nil)
         | 
| 55 | 
            +
                    url      = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{version_id}?access_token=#{self.token}"
         | 
| 56 | 
            +
                    uri      = URI(url)
         | 
| 57 | 
            +
                    form     = {"bytecode" => Base64.strict_encode64(bytecode)}
         | 
| 58 | 
            +
                    response = nil
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    if app_parameters
         | 
| 61 | 
            +
                      form["authorizer_url"]    = app_parameters["authorizer_url"]
         | 
| 62 | 
            +
                      form["description"]       = app_parameters["description"]
         | 
| 63 | 
            +
                      form["pos_display_label"] = app_parameters["pos_display_label"]
         | 
| 64 | 
            +
                      form["displayable"]       = app_parameters["pos_display_label"] != "X"
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
         | 
| 68 | 
            +
                      request = Net::HTTP::Put.new(uri)
         | 
| 69 | 
            +
                      request.set_form_data(form)
         | 
| 70 | 
            +
                      response = http.request(request)
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
                    [response.code.to_i == 200, response]
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
| 77 | 
            +
             | 
| @@ -0,0 +1,90 @@ | |
| 1 | 
            +
            #!/usr/bin/env rake
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rake'
         | 
| 4 | 
            +
            require 'rake/tasklib'
         | 
| 5 | 
            +
            require 'fileutils'
         | 
| 6 | 
            +
            require 'bundler/setup'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # Tasks:
         | 
| 9 | 
            +
            # cloudwalk:build (Will build mruby or posxml application)
         | 
| 10 | 
            +
            # cloddwalk:deploy (Send Posxml or Ruby application)
         | 
| 11 | 
            +
            # cloddwalk:update (Update Cwfile.lock)
         | 
| 12 | 
            +
            # cloudwalk:package - maybe not
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            module Cloudwalk
         | 
| 15 | 
            +
              module Posxml
         | 
| 16 | 
            +
                class RakeTask < ::Rake::TaskLib
         | 
| 17 | 
            +
                  include Cloudwalk::ManagerHelper
         | 
| 18 | 
            +
                  include ::Rake::DSL if defined?(::Rake::DSL)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  attr_accessor :libs, :root_path, :main_out, :out_path, :outs
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def initialize
         | 
| 23 | 
            +
                    yield self if block_given?
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    @libs      ||= FileList['lib/*.xml']
         | 
| 26 | 
            +
                    @root_path ||= "./"
         | 
| 27 | 
            +
                    @out_path  ||= File.join(root_path, "out", "shared")
         | 
| 28 | 
            +
                    @outs      ||= @libs.pathmap("%{lib,#{@out_path}}p")
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    define
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def platform_call(command)
         | 
| 34 | 
            +
                    if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM)
         | 
| 35 | 
            +
                      sh("bash -c \"#{command}\"")
         | 
| 36 | 
            +
                    else
         | 
| 37 | 
            +
                      sh command
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def define
         | 
| 42 | 
            +
                    namespace :cloudwalk do
         | 
| 43 | 
            +
                      desc "Compile posxml"
         | 
| 44 | 
            +
                      task :build do |t, args|
         | 
| 45 | 
            +
                        arguments = ARGV[1..-1]
         | 
| 46 | 
            +
                        if arguments && path = arguments.first
         | 
| 47 | 
            +
                          FileUtils.mkdir_p self.out_path
         | 
| 48 | 
            +
                          xml, out  = self.libs.zip(self.outs).find { |file, out| file == path }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                          posxml = xml2posxml(out)
         | 
| 51 | 
            +
                          platform_call "cloudwalk compile -xml -o #{posxml} #{xml}"
         | 
| 52 | 
            +
                          puts "=> #{File.size(posxml)} "
         | 
| 53 | 
            +
                        else
         | 
| 54 | 
            +
                          FileUtils.rm_rf self.out_path
         | 
| 55 | 
            +
                          FileUtils.mkdir_p self.out_path
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                          self.libs.zip(self.outs).each do |file, out|
         | 
| 58 | 
            +
                            posxml = xml2posxml(out)
         | 
| 59 | 
            +
                            platform_call "cloudwalk compile -xml -o #{posxml} #{file}"
         | 
| 60 | 
            +
                            puts "=> #{File.size(posxml)} "
         | 
| 61 | 
            +
                          end
         | 
| 62 | 
            +
                        end
         | 
| 63 | 
            +
                      end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      desc "Deploy all compiled applications based in Cwfile.json"
         | 
| 66 | 
            +
                      task :deploy => :build do
         | 
| 67 | 
            +
                        if Cloudwalk::CwFileJson.setup
         | 
| 68 | 
            +
                          if path = ARGV[1..-1].first
         | 
| 69 | 
            +
                            xml, out  = self.libs.zip(self.outs).find { |file, out| file == path }
         | 
| 70 | 
            +
                            posxmls = [xml2posxml(out)]
         | 
| 71 | 
            +
                          else
         | 
| 72 | 
            +
                            posxmls = self.outs.collect { |xml| xml2posxml(xml) }
         | 
| 73 | 
            +
                          end
         | 
| 74 | 
            +
                          Cloudwalk::Deploy.new(Cloudwalk::CwFileJson.cwfile,
         | 
| 75 | 
            +
                                                Cloudwalk::CwFileJson.lock).posxml(posxmls)
         | 
| 76 | 
            +
                        end
         | 
| 77 | 
            +
                      end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                      desc "Update CwFile.json.lock"
         | 
| 80 | 
            +
                      task :update do
         | 
| 81 | 
            +
                        Cloudwalk::CwFileJson.delete_lock!
         | 
| 82 | 
            +
                        Cloudwalk::CwFileJson.setup(true)
         | 
| 83 | 
            +
                        Cloudwalk::CwFileJson.persist_lock!
         | 
| 84 | 
            +
                      end
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
                    task :default => "cloudwalk:build"
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
            end
         | 
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            #!/usr/bin/env rake
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rake'
         | 
| 4 | 
            +
            require 'rake/tasklib'
         | 
| 5 | 
            +
            require 'fileutils'
         | 
| 6 | 
            +
            require 'bundler/setup'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # Tasks:
         | 
| 9 | 
            +
            # cloudwalk:build (Will build mruby or posxml application)
         | 
| 10 | 
            +
            # cloddwalk:deploy (Send Posxml or Ruby application)
         | 
| 11 | 
            +
            # cloddwalk:update (Update Cwfile.lock)
         | 
| 12 | 
            +
            # cloudwalk:package - maybe not
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            module Cloudwalk
         | 
| 15 | 
            +
              module Ruby
         | 
| 16 | 
            +
                class RakeTask < ::Rake::TaskLib
         | 
| 17 | 
            +
                  include Cloudwalk::ManagerHelper
         | 
| 18 | 
            +
                  include ::Rake::DSL if defined?(::Rake::DSL)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  def initialize
         | 
| 21 | 
            +
                    define
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def define
         | 
| 25 | 
            +
                    namespace :cloudwalk do
         | 
| 26 | 
            +
                      desc "Compile ruby application"
         | 
| 27 | 
            +
                      task :build do
         | 
| 28 | 
            +
                        Rake::Task[:build].invoke
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      desc "Package Build"
         | 
| 32 | 
            +
                      task :package do
         | 
| 33 | 
            +
                        Rake::Task[:package].invoke
         | 
| 34 | 
            +
                      end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                      desc "Deploy all compiled applications based in Cwfile.json"
         | 
| 37 | 
            +
                      task :deploy => "cloudwalk:package" do
         | 
| 38 | 
            +
                        if Cloudwalk::CwFileJson.setup
         | 
| 39 | 
            +
                          Cloudwalk::Deploy.new(Cloudwalk::CwFileJson.cwfile,
         | 
| 40 | 
            +
                                                Cloudwalk::CwFileJson.lock).ruby
         | 
| 41 | 
            +
                        end
         | 
| 42 | 
            +
                      end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                      desc "Update CwFile.json.lock"
         | 
| 45 | 
            +
                      task :update do
         | 
| 46 | 
            +
                        Cloudwalk::CwFileJson.delete_lock!
         | 
| 47 | 
            +
                        Cloudwalk::CwFileJson.setup(true)
         | 
| 48 | 
            +
                        Cloudwalk::CwFileJson.persist_lock!
         | 
| 49 | 
            +
                      end
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    task :default => "cloudwalk:build"
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
| 57 | 
            +
             | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            module Cloudwalk
         | 
| 2 | 
            +
              module Ruby
         | 
| 3 | 
            +
                class RubyApplication
         | 
| 4 | 
            +
                  include Cloudwalk::ManagerHelper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  # NEW
         | 
| 7 | 
            +
                  def self.find(name)
         | 
| 8 | 
            +
                    self.all.find do |app|
         | 
| 9 | 
            +
                      app["name"] == name
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def self.all
         | 
| 14 | 
            +
                    if @apps
         | 
| 15 | 
            +
                      @apps
         | 
| 16 | 
            +
                    else
         | 
| 17 | 
            +
                      response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/ruby?access_token=#{self.token}&per_page=100")))
         | 
| 18 | 
            +
                      raise ManagerException.new(response["message"]) if response["message"]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                      total_pages = response["pagination"]["total_pages"].to_i
         | 
| 21 | 
            +
                      @apps = response["rubyapps"].collect {|r| r["ruby_app"] }
         | 
| 22 | 
            +
                      (total_pages - 1).times do |page|
         | 
| 23 | 
            +
                        url = "#{self.host}/v1/apps/ruby?access_token=#{self.token}&per_page=100&page=#{page+2}"
         | 
| 24 | 
            +
                        response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 25 | 
            +
                        raise ManagerException.new(response["message"]) if response["message"]
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                        @apps.concat(response["ruby_app"])
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                      @apps
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  # BASE
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def self.get(id)
         | 
| 36 | 
            +
                    url = "#{self.host}/v1/apps/ruby/#{id}?access_token=#{self.token}"
         | 
| 37 | 
            +
                    response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 38 | 
            +
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    response["ruby_app"]
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def self.get_name(id)
         | 
| 44 | 
            +
                    get(id)["name"]
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def self.update(app_id, bytecode, app_parameters = nil)
         | 
| 49 | 
            +
                    url      = "#{self.host}/v1/apps/ruby/#{app_id}?access_token=#{self.token}"
         | 
| 50 | 
            +
                    uri      = URI(url)
         | 
| 51 | 
            +
                    form     = {"bytecode" => Base64.strict_encode64(bytecode)}
         | 
| 52 | 
            +
                    response = nil
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    if app_parameters
         | 
| 55 | 
            +
                      form["authorizer_url"]    = app_parameters["authorizer_url"]
         | 
| 56 | 
            +
                      form["description"]       = app_parameters["description"]
         | 
| 57 | 
            +
                      form["pos_display_label"] = app_parameters["pos_display_label"]
         | 
| 58 | 
            +
                      form["displayable"]       = app_parameters["pos_display_label"] != "X"
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
         | 
| 62 | 
            +
                      request = Net::HTTP::Put.new(uri)
         | 
| 63 | 
            +
                      request.set_form_data(form)
         | 
| 64 | 
            +
                      response = http.request(request)
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                    [response.code.to_i == 200, response]
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
             | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: cloudwalk
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.7.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Thiago Scalone
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-08- | 
| 11 | 
            +
            date: 2017-08-29 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         | 
| @@ -56,10 +56,16 @@ files: | |
| 56 56 | 
             
            - lib/cloudwalk.rb
         | 
| 57 57 | 
             
            - lib/cloudwalk/config.rb
         | 
| 58 58 | 
             
            - lib/cloudwalk/cw_file_json.rb
         | 
| 59 | 
            +
            - lib/cloudwalk/cw_file_json_exception.rb
         | 
| 60 | 
            +
            - lib/cloudwalk/deploy.rb
         | 
| 61 | 
            +
            - lib/cloudwalk/deploy_exception.rb
         | 
| 59 62 | 
             
            - lib/cloudwalk/manager_exception.rb
         | 
| 60 | 
            -
            - lib/cloudwalk/ | 
| 61 | 
            -
            - lib/cloudwalk/ | 
| 62 | 
            -
            - lib/cloudwalk/ | 
| 63 | 
            +
            - lib/cloudwalk/manager_helper.rb
         | 
| 64 | 
            +
            - lib/cloudwalk/posxml/posxml_application.rb
         | 
| 65 | 
            +
            - lib/cloudwalk/posxml/posxml_version.rb
         | 
| 66 | 
            +
            - lib/cloudwalk/posxml/rake_task.rb
         | 
| 67 | 
            +
            - lib/cloudwalk/ruby/rake_task.rb
         | 
| 68 | 
            +
            - lib/cloudwalk/ruby/ruby_application.rb
         | 
| 63 69 | 
             
            homepage: https://cloudwalk.io/cli
         | 
| 64 70 | 
             
            licenses:
         | 
| 65 71 | 
             
            - MIT
         | 
| @@ -1,44 +0,0 @@ | |
| 1 | 
            -
            module Cloudwalk
         | 
| 2 | 
            -
              class PosxmlApplication
         | 
| 3 | 
            -
                def self.token
         | 
| 4 | 
            -
                  Cloudwalk::Config.token
         | 
| 5 | 
            -
                end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                def self.host
         | 
| 8 | 
            -
                  Cloudwalk::Config.host
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def self.all
         | 
| 12 | 
            -
                  if @apps
         | 
| 13 | 
            -
                    @apps
         | 
| 14 | 
            -
                  else
         | 
| 15 | 
            -
                    response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100")))
         | 
| 16 | 
            -
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                    total_pages = response["pagination"]["total_pages"].to_i
         | 
| 19 | 
            -
                    apps = response["posxmlapps"]
         | 
| 20 | 
            -
                    (total_pages - 1).times do |page|
         | 
| 21 | 
            -
                      url = "#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100&page=#{page+2}"
         | 
| 22 | 
            -
                      response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 23 | 
            -
                      raise ManagerException.new(response["message"]) if response["message"]
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                      apps.concat(response["posxmlapps"])
         | 
| 26 | 
            -
                    end
         | 
| 27 | 
            -
                    @apps = apps
         | 
| 28 | 
            -
                  end
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def self.get(id)
         | 
| 32 | 
            -
                  url = "#{self.host}/v1/apps/posxml/#{id}?access_token=#{self.token}"
         | 
| 33 | 
            -
                  response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 34 | 
            -
                  raise ManagerException.new(response["message"]) if response["message"]
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  response["posxml_app"]
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                def self.get_name(id)
         | 
| 40 | 
            -
                  get(id)["name"]
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
            end
         | 
| 44 | 
            -
             | 
| @@ -1,66 +0,0 @@ | |
| 1 | 
            -
            module Cloudwalk
         | 
| 2 | 
            -
              class PosxmlVersion
         | 
| 3 | 
            -
                def self.token
         | 
| 4 | 
            -
                  Cloudwalk::Config.token
         | 
| 5 | 
            -
                end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                def self.host
         | 
| 8 | 
            -
                  Cloudwalk::Config.host
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def self.get_or_create(app, version)
         | 
| 12 | 
            -
                  response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
         | 
| 13 | 
            -
                  raise ManagerException.new(response["message"]) if response["message"]
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  #TODO
         | 
| 16 | 
            -
                  #`curl -X GET "https://api-staging.cloudwalk.io/v1/apps/posxml/3082/versions?access_token=#{self.token}`
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def self.all(app_id)
         | 
| 20 | 
            -
                  response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
         | 
| 21 | 
            -
                  raise ManagerException.new(response["message"]) if response["message"]
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  total_pages = response["pagination"]["total_pages"].to_i
         | 
| 24 | 
            -
                  versions = response["appversions"]
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  (total_pages - 1).times do |page|
         | 
| 27 | 
            -
                    url = "#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100&page=#{page+2}"
         | 
| 28 | 
            -
                    response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 29 | 
            -
                    raise ManagerException.new(response["message"]) if response["message"]
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                    versions.concat(response["posxmlapps"])
         | 
| 32 | 
            -
                  end
         | 
| 33 | 
            -
                  versions
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def self.get(app_id, id)
         | 
| 37 | 
            -
                  url = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{id}?access_token=#{token}"
         | 
| 38 | 
            -
                  response = JSON.parse(Net::HTTP.get(URI(url)))
         | 
| 39 | 
            -
                  raise ManagerException.new(response["message"]) if response["message"]
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  response
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                def self.update(app_id, version_id, bytecode, app_parameters = nil)
         | 
| 45 | 
            -
                  url      = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{version_id}?access_token=#{self.token}"
         | 
| 46 | 
            -
                  uri      = URI(url)
         | 
| 47 | 
            -
                  form     = {"bytecode" => Base64.strict_encode64(bytecode)}
         | 
| 48 | 
            -
                  response = nil
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                  if app_parameters
         | 
| 51 | 
            -
                    form["authorizer_url"]    = app_parameters["authorizer_url"]
         | 
| 52 | 
            -
                    form["description"]       = app_parameters["description"]
         | 
| 53 | 
            -
                    form["pos_display_label"] = app_parameters["pos_display_label"]
         | 
| 54 | 
            -
                    form["displayable"]       = app_parameters["pos_display_label"] != "X"
         | 
| 55 | 
            -
                  end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                  Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
         | 
| 58 | 
            -
                    request = Net::HTTP::Put.new(uri)
         | 
| 59 | 
            -
                    request.set_form_data(form)
         | 
| 60 | 
            -
                    response = http.request(request)
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
                  [response.code.to_i == 200, response]
         | 
| 63 | 
            -
                end
         | 
| 64 | 
            -
              end
         | 
| 65 | 
            -
            end
         | 
| 66 | 
            -
             | 
    
        data/lib/cloudwalk/rake_task.rb
    DELETED
    
    | @@ -1,89 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env rake
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require 'rake'
         | 
| 4 | 
            -
            require 'rake/tasklib'
         | 
| 5 | 
            -
            require 'fileutils'
         | 
| 6 | 
            -
            require 'bundler/setup'
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            # Tasks:
         | 
| 9 | 
            -
            # cloudwalk:build (Will build mruby or posxml application)
         | 
| 10 | 
            -
            # cloddwalk:deploy (Send Posxml or Ruby application)
         | 
| 11 | 
            -
            # cloddwalk:update (Update Cwfile.lock)
         | 
| 12 | 
            -
            # cloudwalk:package - maybe not
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            module Cloudwalk
         | 
| 15 | 
            -
              class RakeTask < ::Rake::TaskLib
         | 
| 16 | 
            -
                include ::Rake::DSL if defined?(::Rake::DSL)
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                attr_accessor :libs, :root_path, :main_out, :out_path, :outs
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def initialize
         | 
| 21 | 
            -
                  yield self if block_given?
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  @libs      ||= FileList['lib/*.xml']
         | 
| 24 | 
            -
                  @root_path ||= "./"
         | 
| 25 | 
            -
                  @out_path  ||= File.join(root_path, "out", "shared")
         | 
| 26 | 
            -
                  @outs      ||= @libs.pathmap("%{lib,#{@out_path}}p")
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  define
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def platform_call(command)
         | 
| 32 | 
            -
                  if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM)
         | 
| 33 | 
            -
                    sh("bash -c \"#{command}\"")
         | 
| 34 | 
            -
                  else
         | 
| 35 | 
            -
                    sh command
         | 
| 36 | 
            -
                  end
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                def define
         | 
| 40 | 
            -
                  namespace :cloudwalk do
         | 
| 41 | 
            -
                    desc "Compile posxml"
         | 
| 42 | 
            -
                    task :build do |t, args|
         | 
| 43 | 
            -
                      if path = ARGV[1..-1].first
         | 
| 44 | 
            -
                        FileUtils.mkdir_p self.out_path
         | 
| 45 | 
            -
                        xml, out  = self.libs.zip(self.outs).find { |file, out| file == path }
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                        posxml = Cloudwalk::CwFileJson.xml2posxml(out)
         | 
| 48 | 
            -
                        platform_call "cloudwalk compile -xml -o #{posxml} #{xml}"
         | 
| 49 | 
            -
                        puts "=> #{File.size(posxml)} "
         | 
| 50 | 
            -
                      else
         | 
| 51 | 
            -
                        FileUtils.rm_rf self.out_path
         | 
| 52 | 
            -
                        FileUtils.mkdir_p self.out_path
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                        self.libs.zip(self.outs).each do |file, out|
         | 
| 55 | 
            -
                          posxml = Cloudwalk::CwFileJson.xml2posxml(out)
         | 
| 56 | 
            -
                          platform_call "cloudwalk compile -xml -o #{posxml} #{file}"
         | 
| 57 | 
            -
                          puts "=> #{File.size(posxml)} "
         | 
| 58 | 
            -
                        end
         | 
| 59 | 
            -
                      end
         | 
| 60 | 
            -
                    end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                    desc "Deploy all compiled applications based in Cwfile.json"
         | 
| 63 | 
            -
                    task :deploy => :build do
         | 
| 64 | 
            -
                      if Cloudwalk::CwFileJson.setup
         | 
| 65 | 
            -
                        if path = ARGV[1..-1].first
         | 
| 66 | 
            -
                          xml, out  = self.libs.zip(self.outs).find { |file, out| file == path }
         | 
| 67 | 
            -
                          Cloudwalk::CwFileJson.deploy([Cloudwalk::CwFileJson.xml2posxml(out)])
         | 
| 68 | 
            -
                        else
         | 
| 69 | 
            -
                          posxmls = self.outs.collect do |xml|
         | 
| 70 | 
            -
                            Cloudwalk::CwFileJson.xml2posxml(xml)
         | 
| 71 | 
            -
                          end
         | 
| 72 | 
            -
                          Cloudwalk::CwFileJson.deploy(posxmls)
         | 
| 73 | 
            -
                        end
         | 
| 74 | 
            -
                      end
         | 
| 75 | 
            -
                    end
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                    desc "Update CwFile.json.lock"
         | 
| 78 | 
            -
                    task :update do
         | 
| 79 | 
            -
                      Cloudwalk::CwFileJson.delete_lock!
         | 
| 80 | 
            -
                      Cloudwalk::CwFileJson.setup(true)
         | 
| 81 | 
            -
                      Cloudwalk::CwFileJson.persist_lock!
         | 
| 82 | 
            -
                    end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                    task :default => :build
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
              end
         | 
| 88 | 
            -
            end
         | 
| 89 | 
            -
             |