Class: Apperol::HerokuClient

Inherits:
Object
  • Object
show all
Defined in:
lib/apperol/heroku_client.rb

Instance Method Summary collapse

Instance Method Details

#builds_clientObject



31
32
33
34
35
# File 'lib/apperol/heroku_client.rb', line 31

def builds_client
  @builds_client ||= Net::HTTP.new(builds_url.hostname, 443).tap do |http|
    http.use_ssl = true
  end
end

#builds_urlObject



37
38
39
# File 'lib/apperol/heroku_client.rb', line 37

def builds_url
  URI("https://build-output.heroku.com")
end

#clientObject



48
49
50
51
52
# File 'lib/apperol/heroku_client.rb', line 48

def client
  @client ||= Net::HTTP.new("api.heroku.com", 443).tap do |http|
    http.use_ssl = true
  end
end

#default_headersObject



41
42
43
44
45
46
# File 'lib/apperol/heroku_client.rb', line 41

def default_headers
  {
    "Content-Type" => "application/json",
    "Accept" => "application/vnd.heroku+json; version=edge"
  }
end

#get(url) ⇒ Object



6
7
8
9
10
11
# File 'lib/apperol/heroku_client.rb', line 6

def get(url)
  request = Net::HTTP::Get.new(url, initheader = default_headers)
  request.basic_auth *Apperol::Creds.heroku
  res = client.request(request)
  Apperol::Response.new(res.code, res.body)
end

#post(url, body) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/apperol/heroku_client.rb', line 13

def post(url, body)
  request = Net::HTTP::Post.new(url, initheader = default_headers)
  request.basic_auth *Apperol::Creds.heroku
  request.body = body
  res = client.request(request)
  Apperol::Response.new(res.code, res.body)
end

#stream_build(url) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/apperol/heroku_client.rb', line 21

def stream_build(url)
  req = Net::HTTP::Get.new(url, initheader = default_headers)
  req.basic_auth *Apperol::Creds.heroku
  builds_client.request req do |response|
    response.read_body do |chunk|
      yield chunk
    end
  end
end