Class: BBC::Cosmos::Tools::Config::API
- Inherits:
-
Object
- Object
- BBC::Cosmos::Tools::Config::API
- Defined in:
- lib/bbc/cosmos/tools/config/api.rb
Instance Method Summary collapse
- #client_cert(path) ⇒ Object
- #client_key(path) ⇒ Object
- #content_type_from(type) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(host, key_path) ⇒ API
constructor
A new instance of API.
- #put(path, payload, content_type = 'application/json') ⇒ Object
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 |