Class: SnapCiManualTrigger::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/snap_ci_manual_trigger/service.rb

Constant Summary collapse

CONNECTION_URL =
'https://api.snap-ci.com'
HEADERS =
{
  'Accept'       => 'application/vnd.snap-ci.com.v1+json',
  'Content-type' => 'application/json',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, api_key:, owner:, repository:, branch_name:, connection: nil) ⇒ Service

Returns a new instance of Service.



13
14
15
16
17
18
19
20
# File 'lib/snap_ci_manual_trigger/service.rb', line 13

def initialize(user:, api_key:, owner:, repository:, branch_name:, connection: nil)
  @user        = user
  @api_key     = api_key
  @owner       = owner
  @repository  = repository
  @branch_name = branch_name
  @connection  = connection || build_connection
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def api_key
  @api_key
end

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def branch_name
  @branch_name
end

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def connection
  @connection
end

#ownerObject (readonly)

Returns the value of attribute owner.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def owner
  @owner
end

#repositoryObject (readonly)

Returns the value of attribute repository.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def repository
  @repository
end

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'lib/snap_ci_manual_trigger/service.rb', line 11

def user
  @user
end

Instance Method Details

#manual_stage(pipeline:, stage:) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/snap_ci_manual_trigger/service.rb', line 31

def manual_stage(pipeline:, stage:)
  response = call_manual_stage pipeline, stage
  check_unauthorized(response)
  check_not_found(response, pipeline, stage)

  parsed_response = parse_response response
  parsed_response['_embedded']['_links']['self']['href']
end

#manual_stage_on_new_pipeline(stage) ⇒ Object



40
41
42
43
# File 'lib/snap_ci_manual_trigger/service.rb', line 40

def manual_stage_on_new_pipeline(stage)
  pipeline_id = new_pipeline
  manual_stage pipeline: pipeline_id, stage: stage
end

#new_pipelineObject



22
23
24
25
26
27
28
29
# File 'lib/snap_ci_manual_trigger/service.rb', line 22

def new_pipeline
  response = call_new_pipeline
  check_unauthorized(response)
  check_not_found(response)

  parsed_response = parse_response response
  parsed_response['counter']
end