Class: BrazeRuby::HTTP
- Inherits:
-
Object
- Object
- BrazeRuby::HTTP
- Defined in:
- lib/braze_ruby/http.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Method Summary collapse
- #connection ⇒ Object
- #get(path, query = {}) ⇒ Object
-
#initialize(api_key, braze_url, options = {}) ⇒ HTTP
constructor
A new instance of HTTP.
- #post(path, payload) ⇒ Object
Constructor Details
#initialize(api_key, braze_url, options = {}) ⇒ HTTP
Returns a new instance of HTTP.
10 11 12 13 14 |
# File 'lib/braze_ruby/http.rb', line 10 def initialize(api_key, braze_url, = {}) @api_key = api_key @braze_url = braze_url @options = .merge() end |
Instance Method Details
#connection ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/braze_ruby/http.rb', line 26 def connection @connection ||= Faraday.new(url: @braze_url) do |connection| connection.headers["Content-Type"] = "application/json" connection.headers["Accept"] = "application/json" connection.headers["User-Agent"] = "Braze Ruby gem v#{BrazeRuby::VERSION}" connection.headers["Authorization"] = "Bearer #{@api_key}" connection.response :logger if ENV['BRAZE_RUBY_DEBUG'] connection.adapter Faraday.default_adapter connection.[:timeout] = @options[:timeout] end end |
#get(path, query = {}) ⇒ Object
22 23 24 |
# File 'lib/braze_ruby/http.rb', line 22 def get(path, query = {}) connection.get path, query end |
#post(path, payload) ⇒ Object
16 17 18 19 20 |
# File 'lib/braze_ruby/http.rb', line 16 def post(path, payload) connection.post path do |request| request.body = JSON.dump(payload) end end |