Class: Klaviyo::Client
- Inherits:
-
Object
- Object
- Klaviyo::Client
- Extended by:
- ClientDSL
- Defined in:
- lib/klaviyo/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #build_params(params = {}) ⇒ Object
-
#initialize(api_key, token) ⇒ Client
constructor
A new instance of Client.
- #invoke(resource, method, options = {}) ⇒ Object
Methods included from ClientDSL
Constructor Details
#initialize(api_key, token) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/klaviyo/client.rb', line 10 def initialize(api_key, token) @api_key = api_key @token = token raise Errors::AuthenticationError, 'No API key provided.' unless @api_key raise Errors::AuthenticationError, 'No Token provided.' unless @token @conn = Faraday.new( url: API_ENDPOINT, ssl: { ca_path: Klaviyo::DEFAULT_CA_BUNDLE_PATH } ) do |f| f.headers['Accept'] = 'application/json' f.request :url_encoded f.response :logger f.response :json, content_type: 'application/json' f.adapter Faraday.default_adapter f.use Errors::RequestError end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/klaviyo/client.rb', line 9 def api_key @api_key end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/klaviyo/client.rb', line 9 def conn @conn end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/klaviyo/client.rb', line 9 def token @token end |
Instance Method Details
#build_params(params = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/klaviyo/client.rb', line 31 def build_params(params = {}) = params.merge( api_key: api_key, token: token ) { data: CGI.escape(Base64.strict_encode64(JSON.generate())) } end |
#invoke(resource, method, options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/klaviyo/client.rb', line 42 def invoke(resource, method, = {}) constantize("klaviyo/#{resource}").send( method, .merge(client: self) ) end |