oc 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d117af6f190633d90c279830b34b373a6de057b5
4
- data.tar.gz: da3130d2c44f668ff658c7ef18067ee62dc1c9ee
3
+ metadata.gz: 0d074a9487fcacce6033c9a6ffa5c796f6bb378f
4
+ data.tar.gz: c5f1094f985d74bd5f8cbf87bce07b79320788b1
5
5
  SHA512:
6
- metadata.gz: c240c1c999e3f7e1423b8a304d3ef1e34c8864c9564906b72a2979e9984566f133be76fe71b447288eeb87648255a10a5ecd40ecbe2489d83b259b12e10e1f88
7
- data.tar.gz: 8acfa9362414b7b348a045699680506c371c602cd99b6b1c0c35145d7b2081187f0a3018d4f7e3ec182f5cf26e6830c58036310c5cc533c86fd2fa3c1e9c9b20
6
+ metadata.gz: 672e890f29dab2511e06d64ac7bbac933210015e6d9e5417b0384fbb8f48d2a7293da4fbe78ef749c8a5f4f5c5b478e67ee44e377fbae2f8446f87b07d4087a3
7
+ data.tar.gz: 5f1f9492e0493830937ba15ab7ca913c1d1a04d39a512dabcafecf4cbac281c5bd0ba52c20c48dbb7d0f3b4c08880fa8b5070d20f80cd666eb8ddfbdf643989b
data/lib/oc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oc
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -8,12 +8,13 @@ module Oc::Run
8
8
 
9
9
  description "Change your API information"
10
10
  def change(*args)
11
- config = Netrc.read("#{(ENV["HOME"] || "./")}/digitalocean.netrc")
11
+ config = Netrc.read("#{(ENV["HOME"] || "./")}/oc.netrc")
12
12
  api_key = [(print 'Access Tokens: '), STDIN.gets.rstrip][1]
13
+ client_id = "empty"
13
14
  if api_key.empty?
14
15
  puts "Please fill all fields".red
15
16
  else
16
- config["api.digitalocean.com"] = api_key
17
+ config["api.digitalocean.com"] = api_key, client_id
17
18
  config.save
18
19
  puts "Informations is changed".red
19
20
  end
@@ -8,8 +8,8 @@ module Oc::Run
8
8
  description "This method lists all the available public SSH keys in your account that can be added to a droplet."
9
9
  syntax "oc ssh keys"
10
10
  def keys
11
- result = Oc::Get.get_json("ssh_keys")
12
- if result["status"] == "ERROR"
11
+ result = barge.key.all
12
+ if !result.success?
13
13
  puts "Error: Please check your information".red
14
14
  else
15
15
  puts "Your SSH Keys".yellow
@@ -20,7 +20,7 @@ module Oc::Run
20
20
  'Name'
21
21
  ]
22
22
 
23
- result["ssh_keys"].each do |key|
23
+ result.ssh_keys.each do |key|
24
24
  rows << [
25
25
  key["id"],
26
26
  key["name"].red,
@@ -36,16 +36,18 @@ module Oc::Run
36
36
 
37
37
  def add(*args)
38
38
  name = args[0]
39
- email = args[1]
40
- pub_key = args[2]
39
+ pub_key = args[1]
41
40
  if name.nil? or pub_key.nil?
42
41
  puts "Argument Error".red
43
42
  puts "Usage".yellow
44
43
  puts "$ oc ssh add [KEY_NAME] [KEY_EMAIL] [KEY_PUB]".yellow
45
44
  else
46
- result = Oc::Get.get_json_parameter("ssh_keys","new",{"name" => name, "ssh_pub_key" => "ssh-rsa " + pub_key + " #{email}"})
47
- if result["status"] == "ERROR"
48
- puts "#{result["message"]}".red
45
+ result = barge.key.create({
46
+ :name => name,
47
+ :public_key => pub_key
48
+ })
49
+ if !result.success?
50
+ puts "#{result.message}".red
49
51
  else
50
52
  puts "SSH Key Added".green
51
53
  end
@@ -62,23 +64,22 @@ module Oc::Run
62
64
  puts "$ oc ssh show [KEY_ID]".yellow
63
65
  else
64
66
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
65
- result = Oc::Get.get_json_parameter("ssh_keys",id)
66
- if result["status"] == "ERROR"
67
- puts "#{result["error_message"]}".red
67
+ result = barge.key.show(id)
68
+ if !result.success?
69
+ puts "#{result.message}".red
68
70
  else
69
71
  puts "SSH Keys".yellow
70
72
  rows = []
71
73
 
72
74
  rows << [
73
75
  'ID',
74
- 'Name',
75
- 'SSH Pub Key'
76
+ 'Name'
76
77
  ]
77
78
 
79
+ key = result.ssh_key
78
80
  rows << [
79
- result["ssh_key"]["id"],
80
- result["ssh_key"]["name"].red,
81
- result["ssh_key"]["ssh_pub_key"].red
81
+ key.id,
82
+ key.name.to_s.red
82
83
  ]
83
84
 
84
85
  table = Terminal::Table.new :rows => rows
@@ -91,22 +92,23 @@ module Oc::Run
91
92
  description "This method allows you to modify an existing public SSH key in your account."
92
93
  syntax "oc ssh edit [KEY_ID] [KEY_NAME] [KEY_EMAIL] [KEY_PUB]"
93
94
 
94
- def edit(*args)
95
+ def update(*args)
95
96
  id = args[0]
96
97
  name = args[1]
97
- email = args[2]
98
- pub_key = args[3]
98
+ pub_key = args[2]
99
99
 
100
- if id.nil? or name.nil? or email.nil? or pub_key.nil?
100
+ if id.nil? or name.nil? or pub_key.nil?
101
101
  puts "Argument Error".red
102
102
  puts "Usage".yellow
103
- puts "$ oc ssh edit [KEY_ID] [KEY_NAME] [KEY_EMAIL] [KEY_PUB]".yellow
103
+ puts "$ oc ssh edit [KEY_ID] [KEY_NAME] [KEY_PUB]".yellow
104
104
  else
105
105
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
106
- url = "https://api.digitalocean.com/ssh_keys/#{id}/edit/"
107
- result = Oc::Get.get_json_url(url,{"name" => name, "ssh_pub_key" => "ssh-rsa " + pub_key + " #{email}"})
108
- if result["status"] == "ERROR"
109
- puts "#{result["message"]}".red
106
+ result = barge.key.update(id, {
107
+ :name => name,
108
+ :public_key => pub_key
109
+ })
110
+ if !result.success?
111
+ puts "#{result.message}".red
110
112
  else
111
113
  puts "SSH Key Edited".green
112
114
  end
@@ -124,10 +126,9 @@ module Oc::Run
124
126
  puts "$ oc ssh destroy [KEY_ID]".yellow
125
127
  else
126
128
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
127
- url = "https://api.digitalocean.com/ssh_keys/#{id}/destroy/"
128
- result = Oc::Get.get_json_url(url)
129
- if result["status"] == "ERROR"
130
- puts "#{result["message"]}".red
129
+ result = barge.key.destroy(id)
130
+ if !result.success?
131
+ puts "#{result.message}".red
131
132
  else
132
133
  puts "SSH Key Deleted".green
133
134
  end
@@ -139,7 +140,11 @@ module Oc::Run
139
140
  @config ||=value
140
141
  end
141
142
 
142
- private
143
+ def barge
144
+ puts "I'm thinking, please wait..".blue
145
+ Oc::Get.get_barge
146
+ end
147
+
143
148
  def new_key_request name, pub_key
144
149
 
145
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sedat Ciftci