Class: Danger::CircleAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/circle_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(circle_token = nil) ⇒ CircleAPI

Returns a new instance of CircleAPI.



7
8
9
# File 'lib/danger/circle_api.rb', line 7

def initialize(circle_token = nil)
  self.circle_token = circle_token
end

Instance Attribute Details

#circle_tokenObject

Returns the value of attribute circle_token.



5
6
7
# File 'lib/danger/circle_api.rb', line 5

def circle_token
  @circle_token
end

Instance Method Details

#clientObject



11
12
13
# File 'lib/danger/circle_api.rb', line 11

def client
  @client ||= Faraday.new(url: 'https://circleci.com/api/v1')
end

#fetch_build(repo_slug, build_number) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/danger/circle_api.rb', line 15

def fetch_build(repo_slug, build_number)
  url = "project/#{repo_slug}/#{build_number}"
  params = { :'circle-token' => circle_token }
  response = client.get url, params, accept: 'application/json'
  json = JSON.parse(response.body, symbolize_names: true)
  json
end