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.
- #patch(path, payload) ⇒ Object
- #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 = .merge() end |
Instance Method Details
#connection ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/braze_ruby/http.rb', line 45 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, [:retry] if [:retry] connection.adapter Faraday.default_adapter connection.[:timeout] = [:timeout] connection.[:open_timeout] = [:open_timeout] .fetch(:middlewares, []).each do |middleware| connection.use middleware end end end |
#delete(path, payload = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/braze_ruby/http.rb', line 39 def delete(path, payload = nil) connection.delete path do |request| request.body = JSON.dump(payload) if payload end end |
#get(path, query = {}) ⇒ Object
35 36 37 |
# File 'lib/braze_ruby/http.rb', line 35 def get(path, query = {}) connection.get path, query end |
#patch(path, payload) ⇒ Object
29 30 31 32 33 |
# File 'lib/braze_ruby/http.rb', line 29 def patch(path, payload) connection.patch path do |request| request.body = JSON.dump(payload) end 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 |