Class: Escobar::Heroku::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/escobar/heroku/client.rb

Overview

Top-level client for interacting with Heroku API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/escobar/heroku/client.rb', line 7

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/escobar/heroku/client.rb', line 6

def token
  @token
end

Instance Method Details

#get(path, version = 3) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/escobar/heroku/client.rb', line 22

def get(path, version = 3)
  response = with_error_handling do
    client.get do |request|
      request.url path
      request_defaults(request, version)
    end
  end
  JSON.parse(response.body)
end

#get_range(path, range, version = 3) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/escobar/heroku/client.rb', line 32

def get_range(path, range, version = 3)
  response = with_error_handling do
    client.get do |request|
      request.url path
      request_defaults(request, version)
      request.headers["Range"] = range
    end
  end
  JSON.parse(response.body)
end

#inspectObject

mask password



12
13
14
15
16
# File 'lib/escobar/heroku/client.rb', line 12

def inspect
  inspected = super
  inspected = inspected.gsub! @token, "*******" if @token
  inspected
end

#post(path, body, second_factor = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/escobar/heroku/client.rb', line 43

def post(path, body, second_factor = nil)
  response = with_error_handling do
    client.post do |request|
      request.url path
      request_defaults(request)
      if second_factor
        request.headers["Heroku-Two-Factor-Code"] = second_factor.to_s
      end
      request.body = body.to_json
    end
  end
  JSON.parse(response.body)
end

#put(path, body, second_factor = nil, version = 3) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/escobar/heroku/client.rb', line 57

def put(path, body, second_factor = nil, version = 3)
  response = with_error_handling do
    client.put do |request|
      request.url path
      request_defaults(request, version)
      if second_factor
        request.headers["Heroku-Two-Factor-Code"] = second_factor.to_s
      end
      request.body = body.to_json
    end
  end
  JSON.parse(response.body)
end

#user_informationObject



18
19
20
# File 'lib/escobar/heroku/client.rb', line 18

def user_information
  get("/account")
end