Class: KlaviyoAPI::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/klaviyo_api/resources/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activate_session(session) ⇒ Object



15
16
17
18
19
# File 'lib/klaviyo_api/resources/base.rb', line 15

def activate_session(session)
  self.headers['api-key'] = session.api_key.to_s # rubocop:disable Style/RedundantSelf

  KlaviyoAPI::Base.site = KlaviyoAPI.configuration.url
end

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/klaviyo_api/resources/base.rb', line 34

def element_path(id, prefix_options = {}, query_options = nil)
  check_prefix_options(prefix_options)

  id = URI.parser.escape id.to_s
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?

  "#{prefix(prefix_options)}#{element_name}#{'/' + id if id.present?}#{format_extension}#{query_string(query_options)}"
end

.headersObject



27
28
29
30
31
32
# File 'lib/klaviyo_api/resources/base.rb', line 27

def headers
  return _headers            if _headers_defined?
  return superclass.headers  if superclass != Object && superclass.headers

  _headers || {}
end

.reset_sessionObject



21
22
23
24
25
# File 'lib/klaviyo_api/resources/base.rb', line 21

def reset_session
  self.headers['api-key'] = nil # rubocop:disable Style/RedundantSelf

  KlaviyoAPI::Base.site = KlaviyoAPI.configuration.url
end

Instance Method Details

#to_hObject



44
45
46
# File 'lib/klaviyo_api/resources/base.rb', line 44

def to_h
  JSON.parse(attributes.to_json).symbolize_keys
end