cloudwalk 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76fa03d69bf8f3d0d59c5c199e4fc18795eb1a0f
4
- data.tar.gz: 9251eb4d60a9e7cff81da98eedf7f69049ce76f0
3
+ metadata.gz: a76eb0a4e3788de1be11141163b5f42589b64565
4
+ data.tar.gz: 492470763d237efd68559c1ffb025269d51ccba4
5
5
  SHA512:
6
- metadata.gz: 701c4cc10a5857668aec621afd2548ba4fdef30cebddab6e835b3314c98c30d45d08da9c8c2c10dc1194cd8295b944b1d62c1924bd710e37fcdd11d971ce0f05
7
- data.tar.gz: d0665b30ac7ca6ed7bca08eded16145b32323f1fc29e78ee4553b0d88d1cf300897795eef8ebbc55286a8e0e0586bc2433b5b1dc7cd4e0b2188b8eaa9a4e66cc
6
+ metadata.gz: 5ae5747d259dea477e657ece603a9de7be247e034aadb2caeca36246e306e86425c691b82c08d57ae1405436f43aa0355c0c4c4e1aac4e2dc597c35852a4bf2f
7
+ data.tar.gz: da09203da62f05e97b224b0c9cf7663125bffad6a31b5cf52ff6332403d6d4d6f2e22c34e080a2ae7cf8a0dbc2667dcda0fa8ea619b9f0ca0c78e248895e30b3
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/cloudwalk.rb CHANGED
@@ -3,6 +3,8 @@ require "net/http"
3
3
  require "json"
4
4
  require "fileutils"
5
5
 
6
+ require_relative "cloudwalk/config"
7
+ require_relative "cloudwalk/cw_file_json"
6
8
  require_relative "cloudwalk/posxml_application"
7
9
  require_relative "cloudwalk/posxml_version"
8
10
  require_relative "cloudwalk/rake_task"
@@ -24,7 +24,9 @@ module Cloudwalk
24
24
  CW_FILE_LOCK_PATH = "./Cwfile.json.lock"
25
25
  CW_FILE_PATH = "./Cwfile.json"
26
26
 
27
- attr_accessor :cwfile, :lock
27
+ class << self
28
+ attr_accessor :cwfile, :lock
29
+ end
28
30
 
29
31
  def self.load_cwfile_lock
30
32
  JSON.parse(File.read(CW_FILE_LOCK_PATH))
@@ -52,7 +54,7 @@ module Cloudwalk
52
54
  # - json and lock are the same
53
55
  # R: Just execute :)
54
56
  #
55
- # 2.
57
+ # 2.
56
58
  # - Cwfile.json exists.
57
59
  # - Cwfile.json.lock exists.
58
60
  # - json and lock aren't the same
@@ -67,14 +69,14 @@ module Cloudwalk
67
69
  # Scenarios:
68
70
  # - The user could create a version on manager and just updated Cwfile.json, instead of delete Cwfile.json.lock
69
71
  # - Maybe create an update action, rake cloudwalk:update
70
- # - The user
72
+ # - The user
71
73
  #
72
- # 3.
74
+ # 3.
73
75
  # - Cwfile.json exists.
74
76
  # - Cwfile.json.lock not exists.
75
77
  # R: Create Cwfile.json.lock
76
78
  #
77
- # 4.
79
+ # 4.
78
80
  # - Cwfile.json not exists.
79
81
  # - Cwfile.json.lock not exists.
80
82
  # R: ASK: Cwfile.json not exists, should I create a skeleton or get the last versions available for the files we have here?
@@ -111,13 +113,13 @@ module Cloudwalk
111
113
  all = Cloudwalk::PosxmlApplication.all
112
114
  config = []
113
115
  self.cwfile["apps"].each do |app_local|
114
- app_remote = all.find { |app_json| app_json["posxml_app"]["name"] == xml2posxml(app) }
116
+ app_remote = all.find { |app_json| app_json["posxml_app"]["name"] == xml2posxml(app_local["name"]) }
115
117
  app_posxml = app_remote["posxml_app"]
116
118
  versions = Cloudwalk::PosxmlVersion.all(app_posxml["id"])
117
- version = versions.find { |json| json["app_version"]["number"] == version }
119
+ version = versions.find { |json| json["app_version"]["number"] == app_local["version"] }
118
120
 
119
121
  if version && version = version["app_version"]
120
- version_detail = PosxmlApplication::Version.get(app_posxml["id"], version["id"])
122
+ version_detail = Cloudwalk::PosxmlVersion.get(app_posxml["id"], version["id"])
121
123
  config << build_application(app_posxml, version, version_detail["app_version"]["module_ids"])
122
124
  else
123
125
  # TODO Version not found, what to do?
@@ -127,10 +129,10 @@ module Cloudwalk
127
129
  end
128
130
 
129
131
  def self.build_module(mod)
130
- response = PosxmlApplication::Version.get(mod["app_id"], mod["version_id"])
132
+ response = Cloudwalk::PosxmlVersion.get(mod["app_id"], mod["version_id"])
131
133
  module_version = response["app_version"]
132
134
  {
133
- "name" => PosxmlApplication::Apps.get_name(module_version["app_id"]),
135
+ "name" => Cloudwalk::PosxmlApplication.get_name(module_version["app_id"]),
134
136
  "version" => module_version["number"],
135
137
  "id" => module_version["app_id"],
136
138
  "version_id" => module_version["id"]
@@ -159,10 +161,7 @@ module Cloudwalk
159
161
  # TODO Check CRC
160
162
  def self.deploy(outs)
161
163
  outs.each do |path|
162
- p path
163
- posxml = path.split("/").last
164
- #app = posxml2xml(posxml)
165
-
164
+ posxml = path.split("/").last
166
165
  app_lock = self.lock.find {|config| config["name"] == posxml }
167
166
 
168
167
  unless app_lock
@@ -197,7 +196,7 @@ module Cloudwalk
197
196
  # TODO future!
198
197
 
199
198
  def self.compare
200
- cwfile_list = self.cwfile.inject({}) do |hash, app|
199
+ cwfile_list = self.cwfile["apps"].inject({}) do |hash, app|
201
200
  hash[app["name"]] = app["modules"].inject({}) do |hash_m, app_module|
202
201
  hash_m[app_module[0]] = app_module[1]
203
202
  hash_m
@@ -253,7 +252,7 @@ module Cloudwalk
253
252
  remote_version_json = remote_versions.find { |json| json["app_version"]["number"] == version }
254
253
 
255
254
  if remote_version_json && (remote_version = remote_version_json["app_version"])
256
- remote_version_detail = PosxmlApplication::Version.get(remote_posxml_app["id"], remote_version["id"])
255
+ remote_version_detail = Cloudwalk::PosxmlVersion.get(remote_posxml_app["id"], remote_version["id"])
257
256
  # TODO: Check if application exists locally
258
257
  build_application(local_app, config, remote_posxml_app, remote_version, remote_version_detail["app_version"]["module_ids"])
259
258
  else
@@ -12,13 +12,13 @@ module Cloudwalk
12
12
  if @apps
13
13
  @apps
14
14
  else
15
- response = JSON.parse(Net::HTTP.get(URI("https://#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100")))
15
+ response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100")))
16
16
  raise ManagerException.new(response["message"]) if response["message"]
17
17
 
18
18
  total_pages = response["pagination"]["total_pages"].to_i
19
19
  apps = response["posxmlapps"]
20
20
  (total_pages - 1).times do |page|
21
- url = "https://#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100&page=#{page+2}"
21
+ url = "#{self.host}/v1/apps/posxml?access_token=#{self.token}&per_page=100&page=#{page+2}"
22
22
  response = JSON.parse(Net::HTTP.get(URI(url)))
23
23
  raise ManagerException.new(response["message"]) if response["message"]
24
24
 
@@ -29,7 +29,7 @@ module Cloudwalk
29
29
  end
30
30
 
31
31
  def self.get(id)
32
- url = "https://#{self.host}/v1/apps/posxml/#{id}?access_token=#{self.token}"
32
+ url = "#{self.host}/v1/apps/posxml/#{id}?access_token=#{self.token}"
33
33
  response = JSON.parse(Net::HTTP.get(URI(url)))
34
34
  raise ManagerException.new(response["message"]) if response["message"]
35
35
 
@@ -9,7 +9,7 @@ module Cloudwalk
9
9
  end
10
10
 
11
11
  def self.get_or_create(app, version)
12
- response = JSON.parse(Net::HTTP.get(URI("https://#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
12
+ response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
13
13
  raise ManagerException.new(response["message"]) if response["message"]
14
14
 
15
15
  #TODO
@@ -17,14 +17,14 @@ module Cloudwalk
17
17
  end
18
18
 
19
19
  def self.all(app_id)
20
- response = JSON.parse(Net::HTTP.get(URI("https://#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
20
+ response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100")))
21
21
  raise ManagerException.new(response["message"]) if response["message"]
22
22
 
23
23
  total_pages = response["pagination"]["total_pages"].to_i
24
24
  versions = response["appversions"]
25
25
 
26
26
  (total_pages - 1).times do |page|
27
- url = "https://#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100&page=#{page+2}"
27
+ url = "#{self.host}/v1/apps/posxml/#{app_id}/versions?access_token=#{self.token}&per_page=100&page=#{page+2}"
28
28
  response = JSON.parse(Net::HTTP.get(URI(url)))
29
29
  raise ManagerException.new(response["message"]) if response["message"]
30
30
 
@@ -34,7 +34,7 @@ module Cloudwalk
34
34
  end
35
35
 
36
36
  def self.get(app_id, id)
37
- url = "https://#{self.host}/v1/apps/posxml/#{app_id}/versions/#{id}?access_token=#{token}"
37
+ url = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{id}?access_token=#{token}"
38
38
  response = JSON.parse(Net::HTTP.get(URI(url)))
39
39
  raise ManagerException.new(response["message"]) if response["message"]
40
40
 
@@ -44,13 +44,14 @@ module Cloudwalk
44
44
  def self.update(app_id, version_id, bytecode)
45
45
  url = "#{self.host}/v1/apps/posxml/#{app_id}/versions/#{version_id}?access_token=#{self.token}"
46
46
  uri = URI(url)
47
- uri.encode_www_form({"bytecode" => Base64.strict_encode64(bytecode)})
47
+ response = nil
48
48
 
49
49
  Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
50
50
  request = Net::HTTP::Put.new(uri)
51
- response = http.request request
51
+ request.set_form_data({"bytecode" => Base64.strict_encode64(bytecode)})
52
+ response = http.request(request)
52
53
  end
53
- p response
54
+ response.code == 200
54
55
  end
55
56
  end
56
57
  end
@@ -15,7 +15,7 @@ module Cloudwalk
15
15
  class RakeTask < ::Rake::TaskLib
16
16
  include ::Rake::DSL if defined?(::Rake::DSL)
17
17
 
18
- attr_accessor :libs, :root_path, :main_out, :out_path
18
+ attr_accessor :libs, :root_path, :main_out, :out_path, :outs
19
19
 
20
20
  def initialize
21
21
  yield self if block_given?
@@ -39,20 +39,35 @@ module Cloudwalk
39
39
  def define
40
40
  namespace :cloudwalk do
41
41
  desc "Compile posxml"
42
- task :build do
43
- FileUtils.rm_rf self.out_path
44
- FileUtils.mkdir_p self.out_path
45
- self.libs.zip(self.outs).each do |file, out|
46
- posxml = CwFileJson.xml2posxml(out)
47
- puts "cloudwalk compile -xml -o #{posxml} #{file}"
48
- platform_call "cloudwalk compile -xml -o #{posxml} #{file}"
42
+ task :build do |t, args|
43
+ if path = ARGV[1..-1].first
44
+ xml, out = self.libs.zip(self.outs).find { |file, out| file == path }
45
+
46
+ posxml = Cloudwalk::CwFileJson.xml2posxml(out)
47
+ platform_call "cloudwalk compile -xml -o #{posxml} #{xml}"
48
+ else
49
+ FileUtils.rm_rf self.out_path
50
+ FileUtils.mkdir_p self.out_path
51
+
52
+ self.libs.zip(self.outs).each do |file, out|
53
+ posxml = Cloudwalk::CwFileJson.xml2posxml(out)
54
+ platform_call "cloudwalk compile -xml -o #{posxml} #{file}"
55
+ end
49
56
  end
50
57
  end
51
58
 
52
59
  desc "Deploy all compiled applications based in Cwfile.json"
53
60
  task :deploy => :build do
54
61
  if Cloudwalk::CwFileJson.setup
55
- Cloudwalk::CwFileJson.deploy(self.outs)
62
+ if path = ARGV[1..-1].first
63
+ xml, out = self.libs.zip(self.outs).find { |file, out| file == path }
64
+ Cloudwalk::CwFileJson.deploy([Cloudwalk::CwFileJson.xml2posxml(out)])
65
+ else
66
+ posxmls = self.outs.collect do |xml|
67
+ Cloudwalk::CwFileJson.xml2posxml(out)
68
+ end
69
+ Cloudwalk::CwFileJson.deploy(posxmls)
70
+ end
56
71
  end
57
72
  end
58
73
 
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.0.2
4
+ version: 0.1.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-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake