class BrazeAPI::Client
The top-level class that handles configuration and connection to the Braze API.
Attributes
api_key[R]
app_id[R]
braze_url[R]
Public Class Methods
new(api_key:, braze_url:, app_id:)
click to toggle source
# File lib/braze_api/client.rb, line 23 def initialize(api_key:, braze_url:, app_id:) @api_key = api_key @braze_url = braze_url @app_id = app_id end
Public Instance Methods
post(endpoint, params: {})
click to toggle source
Returns a parsed response from a post request
# File lib/braze_api/client.rb, line 30 def post(endpoint, params: {}) response = client.post(endpoint, params.to_json) JSON.parse(response.body) end
Private Instance Methods
client()
click to toggle source
Creates a Faraday connection if there is none, otherwise returns the existing.
# File lib/braze_api/client.rb, line 39 def client @client ||= Faraday.new(braze_url) do |faraday| faraday.use BrazeAPI::Response::RaiseError faraday.adapter Faraday.default_adapter faraday.headers['User-Agent'] = "Braze API Client gem v#{BrazeAPI::VERSION}" faraday.headers['Content-Type'] = 'application/json' faraday.headers['Authorization'] = "Bearer #{api_key}" end end