Class: CircleCI::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mina-circle/circle-ci/client.rb

Constant Summary collapse

BASE_URI =
'https://circleci.com/api/v1.1'
CONFIG_FILE_PATH =
File.join(Dir.home, '.mina-circle.yml')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_tokenObject



39
40
41
42
43
44
45
# File 'lib/mina-circle/circle-ci/client.rb', line 39

def api_token
  [
    @api_token,
    ENV['MINA_CIRCLE_TOKEN'],
    system_token
  ].compact.first
end

Instance Method Details

#get(path, params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mina-circle/circle-ci/client.rb', line 14

def get(path, params = {})
  uri = URI("#{BASE_URI}/#{path}")
  params['circle-token'] = api_token
  uri.query = URI.encode_www_form(params) unless params.empty?
  puts "Sending URL: #{uri}"
  request = Net::HTTP::Get.new uri
  request['Accept'] = 'application/json'
  response = Net::HTTP.start uri.host, uri.port, use_ssl: true do |http|
    http.request request
  end
  return_object = JSON.parse response.body

  JSON.pretty_generate return_object

  if return_object.instance_of? Object
    if return_object['message']
      puts return_object['message']
      puts "Check your branch and/or build on CircleCI..."
      exit
    end
  end

  return_object
end