Class: Prefab::HttpConnection
- Inherits:
-
Object
- Object
- Prefab::HttpConnection
- Defined in:
- lib/prefab/http_connection.rb
Constant Summary collapse
- AUTH_USER =
'authuser'
- PROTO_HEADERS =
{ 'Content-Type' => 'application/x-protobuf', 'Accept' => 'application/x-protobuf', 'X-PrefabCloud-Client-Version' => "prefab-cloud-ruby-#{Prefab::VERSION}" }.freeze
Instance Method Summary collapse
- #connection(headers = {}) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(api_root, api_key) ⇒ HttpConnection
constructor
A new instance of HttpConnection.
- #post(path, body) ⇒ Object
Constructor Details
#initialize(api_root, api_key) ⇒ HttpConnection
Returns a new instance of HttpConnection.
12 13 14 15 |
# File 'lib/prefab/http_connection.rb', line 12 def initialize(api_root, api_key) @api_root = api_root @api_key = api_key end |
Instance Method Details
#connection(headers = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prefab/http_connection.rb', line 25 def connection(headers = {}) if Faraday::VERSION[0].to_i >= 2 Faraday.new(@api_root) do |conn| conn.request :authorization, :basic, AUTH_USER, @api_key conn.headers.merge!(headers) end else Faraday.new(@api_root) do |conn| conn.request :basic_auth, AUTH_USER, @api_key conn.headers.merge!(headers) end end end |
#get(path) ⇒ Object
17 18 19 |
# File 'lib/prefab/http_connection.rb', line 17 def get(path) connection.get(path) end |
#post(path, body) ⇒ Object
21 22 23 |
# File 'lib/prefab/http_connection.rb', line 21 def post(path, body) connection(PROTO_HEADERS).post(path, body.to_proto) end |