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
- #follow_project ⇒ 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
25 26 27 28 29 |
# File 'lib/rake_circle_ci/client.rb', line 25 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
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rake_circle_ci/client.rb', line 55 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
31 32 33 |
# File 'lib/rake_circle_ci/client.rb', line 31 def delete_env_var(name) assert_successful(Excon.delete(env_var_url(name), headers: headers)) end |
#delete_env_vars ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rake_circle_ci/client.rb', line 35 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
66 67 68 69 70 71 72 73 74 |
# File 'lib/rake_circle_ci/client.rb', line 66 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
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rake_circle_ci/client.rb', line 76 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
17 18 19 20 21 22 23 |
# File 'lib/rake_circle_ci/client.rb', line 17 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
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rake_circle_ci/client.rb', line 42 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 |
#follow_project ⇒ Object
13 14 15 |
# File 'lib/rake_circle_ci/client.rb', line 13 def follow_project assert_successful(Excon.post(follow_url, headers: headers)) end |