Class: BBC::Cosmos::Tools::Config::API

Inherits:
Object
  • Object
show all
Defined in:
lib/bbc/cosmos/tools/config/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, key_path) ⇒ API

Returns a new instance of API.



11
12
13
# File 'lib/bbc/cosmos/tools/config/api.rb', line 11

def initialize(host, key_path)
  @connection = Faraday.new host, :ssl => {:client_key => client_key(key_path), :client_cert  => client_cert(key_path), :verify => false }
end

Instance Method Details

#client_cert(path) ⇒ Object



19
20
21
# File 'lib/bbc/cosmos/tools/config/api.rb', line 19

def client_cert(path)
  OpenSSL::X509::Certificate.new(File.read path)
end

#client_key(path) ⇒ Object



15
16
17
# File 'lib/bbc/cosmos/tools/config/api.rb', line 15

def client_key(path)
  OpenSSL::PKey::RSA.new(File.read path)
end

#content_type_from(type) ⇒ Object



32
33
34
# File 'lib/bbc/cosmos/tools/config/api.rb', line 32

def content_type_from(type)
  @connection.headers[:content_type] = type
end

#get(path) ⇒ Object



23
24
25
# File 'lib/bbc/cosmos/tools/config/api.rb', line 23

def get(path)
  @connection.get path
end

#put(path, payload, content_type = 'application/json') ⇒ Object



27
28
29
30
# File 'lib/bbc/cosmos/tools/config/api.rb', line 27

def put(path, payload, content_type = 'application/json')
  content_type_from content_type
  @connection.put path, payload
end