Class: RakeCircleCI::Client
- Inherits:
-
Object
- Object
- RakeCircleCI::Client
- Defined in:
- lib/rake_circle_ci/client.rb
Instance Method Summary collapse
- #create_env_var(name, value) ⇒ Object
- #create_ssh_key(private_key, opts = {}) ⇒ Object
- #delete_env_var(name) ⇒ Object
- #delete_env_vars ⇒ Object
- #delete_ssh_key(fingerprint, opts = {}) ⇒ Object
- #delete_ssh_keys ⇒ Object
- #find_env_vars ⇒ Object
- #find_ssh_keys ⇒ Object
-
#initialize(opts) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/rake_circle_ci/client.rb', line 7 def initialize(opts) @base_url = opts[:base_url] @api_token = opts[:api_token] @project_slug = opts[:project_slug] end |
Instance Method Details
#create_env_var(name, value) ⇒ Object
21 22 23 24 25 |
# File 'lib/rake_circle_ci/client.rb', line 21 def create_env_var(name, value) body = JSON.dump(name: name, value: value) assert_successful( Excon.post(env_vars_url, body: body, headers: headers)) end |
#create_ssh_key(private_key, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rake_circle_ci/client.rb', line 51 def create_ssh_key(private_key, opts = {}) body = { fingerprint: SSHKey.new(private_key).sha1_fingerprint, private_key: private_key, } body = body.merge(hostname: opts[:hostname]) if opts[:hostname] body = JSON.dump(body) assert_successful( Excon.post(ssh_keys_url, body: body, headers: headers)) end |
#delete_env_var(name) ⇒ Object
27 28 29 |
# File 'lib/rake_circle_ci/client.rb', line 27 def delete_env_var(name) assert_successful(Excon.delete(env_var_url(name), headers: headers)) end |
#delete_env_vars ⇒ Object
31 32 33 34 35 36 |
# File 'lib/rake_circle_ci/client.rb', line 31 def delete_env_vars env_vars = find_env_vars env_vars.each do |env_var| delete_env_var(env_var) end end |
#delete_ssh_key(fingerprint, opts = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rake_circle_ci/client.rb', line 62 def delete_ssh_key(fingerprint, opts = {}) body = { fingerprint: fingerprint } body = body.merge(hostname: opts[:hostname]) if opts[:hostname] body = JSON.dump(body) assert_successful( Excon.delete(ssh_keys_url, body: body, headers: headers)) end |
#delete_ssh_keys ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rake_circle_ci/client.rb', line 72 def delete_ssh_keys ssh_keys = find_ssh_keys ssh_keys.each do |ssh_key| fingerprint = ssh_key[:fingerprint] hostname = ssh_key[:hostname] = hostname && {hostname: hostname} args = [fingerprint, ].compact delete_ssh_key(*args) end end |
#find_env_vars ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rake_circle_ci/client.rb', line 13 def find_env_vars response = assert_successful(Excon.get(env_vars_url, headers: headers)) body = JSON.parse(response.body) env_vars = body["items"].map { |item| item["name"] } env_vars end |
#find_ssh_keys ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rake_circle_ci/client.rb', line 38 def find_ssh_keys response = assert_successful(Excon.get(settings_url, headers: headers)) body = JSON.parse(response.body) ssh_keys = body["ssh_keys"].map do |ssh_key| { fingerprint: ssh_key["fingerprint"], hostname: ssh_key["hostname"] } end ssh_keys end |