Class: Drone::Client
- Inherits:
-
Object
- Object
- Drone::Client
- Defined in:
- lib/drone/client.rb
Constant Summary collapse
- DEFAULT_HOST =
"drone.io"
- USER_AGENT =
"#{self}/#{VERSION}"
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
Instance Method Summary collapse
- #commits(repos: nil) ⇒ Object
- #console(repos: nil, branch: nil, commit: nil) ⇒ Object
-
#initialize(host: nil, access_token: nil) ⇒ Client
constructor
A new instance of Client.
- #rebuild(repos: nil, branch: nil, commit: nil) ⇒ Object
- #repository(path) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(host: nil, access_token: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
10 11 12 |
# File 'lib/drone/client.rb', line 10 def http @http end |
Instance Method Details
#commits(repos: nil) ⇒ Object
34 35 36 37 38 39 |
# 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) ⇒ Object
47 48 49 50 |
# 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) ⇒ Object
41 42 43 44 45 |
# 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) ⇒ Object
27 28 29 30 31 32 |
# 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 ⇒ Object
20 21 22 23 24 25 |
# File 'lib/drone/client.rb', line 20 def user url = "https://#{@host}/api/user" response = get_json(url) User.build_with_hash(response) end |