Class: Unleash::Admin::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/admin/client.rb

Defined Under Namespace

Classes: NotFoundError

Instance Method Summary collapse

Constructor Details

#initialize(config = Unleash::Admin.configuration) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/unleash/admin/client.rb', line 9

def initialize(config = Unleash::Admin.configuration)
  @config = config
end

Instance Method Details

#api_call(method, path, body = nil) ⇒ Object

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/unleash/admin/client.rb', line 17

def api_call(method, path, body = nil)
  url = URI.parse(@config.server_url + path)
  case method
  when :get
    request = Net::HTTP::Get.new(url)
  when :post
    request = Net::HTTP::Post.new(url)
  when :put
    request = Net::HTTP::Put.new(url)
  when :delete
    request = Net::HTTP::Delete.new(url)
  end
  request["Accept"] = "application/json"
  request["Authorization"] = @config.admin_api_key
  request.body = body if body
  use_ssl = url.scheme == "https"
  response = Net::HTTP.start(url.hostname, url.port, use_ssl: use_ssl) do |http|
    http.request(request)
  end

  raise NotFoundError if response.code == "404"
  
  [response.code, JSON.parse(response.body)]
end

#get_featuresObject



13
14
15
# File 'lib/unleash/admin/client.rb', line 13

def get_features
  api_call(:get, "/api/admin/projects/#{@config.project}/features")
end