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, req_options = {}) ⇒ Client
constructor
A new instance of Client.
- #invoke(resource, method, options = {}) ⇒ Object
Methods included from ClientDSL
Constructor Details
#initialize(api_key, token, req_options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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(.merge()) do |f| f.request :url_encoded f.use Errors::RequestError f.adapter Faraday.default_adapter 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
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/klaviyo/client.rb', line 24 def build_params(params = {}) = params.merge( api_key: api_key, token: token ) { data: Base64.strict_encode64(JSON.generate()) } end |
#invoke(resource, method, options = {}) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/klaviyo/client.rb', line 35 def invoke(resource, method, = {}) constantize("klaviyo/#{resource}").send( method, .merge(client: self) ) end |