Class: GoAPI
- Inherits:
-
Object
- Object
- GoAPI
- Defined in:
- lib/goapi.rb,
lib/goapi/http.rb
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#artifact(artifact) ⇒ Object
artifact: object from artifacts(stage, job_name), it should have 2 attributes “type” and “url”, and “type” should be “file”.
-
#artifacts(stage, job_name) ⇒ Object
stage: object has attribute methods: pipeline_name, pipeline_counter, name, counter You can get this object by calling stages(pipeline_name, stage_name) job_name: job name.
-
#initialize(server, credentials = nil) ⇒ GoAPI
constructor
server: Go server url, for example: go01.domain.com credentials: only support basic auth right now, example: [username, password] default value is nil.
-
#job_properties(stage, job_name) ⇒ Object
stage: object has attribute methods: pipeline_name, pipeline_counter, name, counter You can get this object by calling stages(pipeline_name, stage_name) job_name: job name.
-
#stage_id(stage) ⇒ Object
build stage uniq identifier for stage object.
- #stages(pipeline_name, stage_name) ⇒ Object
Constructor Details
#initialize(server, credentials = nil) ⇒ GoAPI
server: Go server url, for example: go01.domain.com credentials:
only support basic auth right now, example: {basic_auth: [username, password]}
default value is nil
36 37 38 |
# File 'lib/goapi.rb', line 36 def initialize(server, credentials=nil) @server, @http = server, Http.new(credentials) end |
Class Method Details
.logger ⇒ Object
27 28 29 |
# File 'lib/goapi.rb', line 27 def logger @logger ||= Logger.new(STDOUT) end |
Instance Method Details
#artifact(artifact) ⇒ Object
artifact: object from artifacts(stage, job_name), it should have 2 attributes “type” and “url”, and “type” should be “file”
66 67 68 69 70 |
# File 'lib/goapi.rb', line 66 def artifact(artifact) raise "Only accept file type artifact" if artifact.type != 'file' u = URI(artifact.url) @http.get([@server, u.path].join('/'))[1] end |
#artifacts(stage, job_name) ⇒ Object
stage:
object has attribute methods: pipeline_name, pipeline_counter, name, counter
You can get this object by calling stages(pipeline_name, stage_name)
job_name: job name
61 62 63 |
# File 'lib/goapi.rb', line 61 def artifacts(stage, job_name) fetch(:files, stage.pipeline_name, stage.pipeline_counter, stage.name, stage.counter, "#{job_name}.json") end |
#job_properties(stage, job_name) ⇒ Object
stage:
object has attribute methods: pipeline_name, pipeline_counter, name, counter
You can get this object by calling stages(pipeline_name, stage_name)
job_name: job name
48 49 50 51 52 53 54 55 |
# File 'lib/goapi.rb', line 48 def job_properties(stage, job_name) text = @http.get(url(:properties, stage.pipeline_name, stage.pipeline_counter, stage.name, stage.counter, job_name))[1] names, values = text.split("\n") values = values.split(',') OpenStruct.new(Hash[names.split(',').each_with_index.map do |name, i| [name, values[i]] end]) end |
#stage_id(stage) ⇒ Object
build stage uniq identifier for stage object
73 74 75 |
# File 'lib/goapi.rb', line 73 def stage_id(stage) "#{stage.pipeline_name}/#{stage.pipeline_counter}/#{stage.name}/#{stage.counter}" end |