class Drone::Client
Constants
- DEFAULT_HOST
- USER_AGENT
Attributes
http[RW]
Public Class Methods
new(host: nil, access_token: nil)
click to toggle source
# File lib/drone/client.rb, line 12 def initialize(host: nil, access_token: nil) @host = host || DEFAULT_HOST @access_token = access_token @http = HTTPClient.new @http.agent_name = USER_AGENT end
Public Instance Methods
commits(repos: nil)
click to toggle source
# File lib/drone/client.rb, line 34 def commits(repos: nil) url = "#{base_url}/repos/#{repos.path}/commits" response = get_json(url) response.map { |commit| Commit.build_with_hash(commit) } end
console(repos: nil, branch: nil, commit: nil)
click to toggle source
# File lib/drone/client.rb, line 47 def console(repos: nil, branch: nil, commit: nil) url = "#{base_url}/repos/#{repos.path}/branches/#{branch}/commits/#{commit.sha}/console" get(url) end
rebuild(repos: nil, branch: nil, commit: nil)
click to toggle source
# File lib/drone/client.rb, line 41 def rebuild(repos: nil, branch: nil, commit: nil) url = "#{base_url}/repos/#{repos.path}/branches/#{branch}/commits/#{commit.sha}" post(url) end
repository(path)
click to toggle source
# File lib/drone/client.rb, line 27 def repository(path) url = "#{base_url}/repos/#{path}" response = get_json(url) Repository.build_with_hash(response) end
user()
click to toggle source
# File lib/drone/client.rb, line 20 def user url = "https://#{@host}/api/user" response = get_json(url) User.build_with_hash(response) end
Private Instance Methods
base_url()
click to toggle source
# File lib/drone/client.rb, line 54 def base_url "https://#{@host}/api" end
get(url)
click to toggle source
# File lib/drone/client.rb, line 58 def get(url) @http.get(url, access_token: @access_token).body end
get_json(url)
click to toggle source
# File lib/drone/client.rb, line 62 def get_json(url) JSON.parse(@http.get(url, access_token: @access_token).body) end
post(url)
click to toggle source
# File lib/drone/client.rb, line 66 def post(url) @http.post(url, access_token: @access_token) end