Class: ApioticsFactory::Publish

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/apiotics_factory/publish.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



15
16
17
18
19
20
21
# File 'lib/apiotics_factory/publish.rb', line 15

def self.source_root
  if :path == nil
    Dir.pwd
  else
    :path
  end
end

Instance Method Details

#fetch_infoObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/apiotics_factory/publish.rb', line 23

def fetch_info
  config_dir = File.dirname(__FILE__).chomp("/lib/apiotics_factory") + "/var"

  if File.exist?(config_dir + "/config.json")
    config = JSON.parse(File.read(config_dir + "/config.json"))
    ApioticsFactory.configuration.public_key = config["public_key"]
    ApioticsFactory.configuration.private_key = config["private_key"]
    ApioticsFactory.configuration.portal = config["portal"]
  else
    say("Please enter your vendor public key from the Apiotics Portal.")
    ApioticsFactory.configuration.public_key = ask("Vendor Public Key: ")
    say("Please enter your vendor private key from the Apiotics Portal.")
    ApioticsFactory.configuration.private_key = ask("Vendor Private Key: ")
    say("Please confirm the Apiotics Portal web address.")
    ApioticsFactory.configuration.portal = ask("Portal: ", default: "https://portal.apiotics.com/")
    unless ApioticsFactory.configuration.portal[-1] == "/"
      ApioticsFactory.configuration.portal = ApioticsFactory.configuration.portal + "/"
    end
    config = {
      "public_key" => ApioticsFactory.configuration.public_key,
      "private_key" => ApioticsFactory.configuration.private_key,
      "portal" => ApioticsFactory.configuration.portal
    }
    unless Dir.exist?(config_dir)
      Dir.mkdir(config_dir)
    end
    File.write(config_dir + "/config.json", config.to_json)
  end
  data = ApioticsFactory::Portal.driver_version(id)
  #puts data
  data = JSON.parse(data)
  @driver_name = data["name"]
  @status = true
  unless data.keys.include?("errors")
    @version = data["version"]
  else
    @status = false
    say("#{data['errors']['detail']}")
  end
end

#publishObject

need to account for the case where the portal call fails.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/apiotics_factory/publish.rb', line 66

def publish
  if @status == true
    run("tar -cvzf #{@driver_name.downcase}-#{@version}.tgz ./#{@driver_name.downcase}")
    say("Uploading driver to the portal...")
    path = Dir.pwd + "/#{@driver_name.downcase}-#{@version}.tgz"
    response = ApioticsFactory::Portal.publish_driver(id, path)
    say("Cleaning up...")
    run("rm #{@driver_name.downcase}-#{@version}.tgz")
    if response.code == 200
      say("Upload successful")
    else
      say("Upload not successful")
    end
  end
end