Class: BrazeRuby::HTTP
- Inherits:
-
Object
- Object
- BrazeRuby::HTTP
- Defined in:
- lib/braze_ruby/http.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
- DEFAULT_OPEN_TIMEOUT =
5
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(path, payload = nil) ⇒ Object
- #get(path, query = {}) ⇒ Object
-
#initialize(api_key, braze_url, options = {}) ⇒ HTTP
constructor
A new instance of HTTP.
- #post(path, payload) ⇒ Object
- #put(path, payload) ⇒ Object
Constructor Details
#initialize(api_key, braze_url, options = {}) ⇒ HTTP
Returns a new instance of HTTP.
11 12 13 14 15 |
# File 'lib/braze_ruby/http.rb', line 11 def initialize(api_key, braze_url, = {}) @api_key = api_key @braze_url = braze_url @options = .merge() end |
Instance Method Details
#connection ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/braze_ruby/http.rb', line 39 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.request :retry, @options[:retry] if @options[:retry] connection.adapter Faraday.default_adapter connection.[:timeout] = @options[:timeout] connection.[:open_timeout] = @options[:open_timeout] end end |
#delete(path, payload = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/braze_ruby/http.rb', line 33 def delete(path, payload = nil) connection.delete path do |request| request.body = JSON.dump(payload) if payload end end |
#get(path, query = {}) ⇒ Object
29 30 31 |
# File 'lib/braze_ruby/http.rb', line 29 def get(path, query = {}) connection.get path, query end |
#post(path, payload) ⇒ Object
17 18 19 20 21 |
# File 'lib/braze_ruby/http.rb', line 17 def post(path, payload) connection.post path do |request| request.body = JSON.dump(payload) end end |
#put(path, payload) ⇒ Object
23 24 25 26 27 |
# File 'lib/braze_ruby/http.rb', line 23 def put(path, payload) connection.post path do |request| request.body = JSON.dump(payload) end end |