lib/klaviyo/client.rb in parallel588-klaviyo-0.7.0 vs lib/klaviyo/client.rb in parallel588-klaviyo-0.8.0

- old
+ new

@@ -1,22 +1,27 @@ +require_relative 'client_dsl' +require_relative 'errors' module Klaviyo API_ENDPOINT = 'https://a.klaviyo.com' class Client + extend ClientDSL + attr_reader :api_key, :conn, :token def initialize(api_key, token) @api_key = api_key @token = token @conn = Faraday.new( url: API_ENDPOINT, ssl: { ca_path: Klaviyo::DEFAULT_CA_BUNDLE_PATH } - ) do |b| - b.headers['Accept'] = 'application/json' - b.request :url_encoded - b.response :logger - b.response :json, content_type: 'application/json' - b.adapter Faraday.default_adapter + ) 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 def build_params(params = {}) options = params.merge( @@ -34,12 +39,44 @@ method, options.merge(client: self) ) end + define_api_method resource: :people, action: :identify + define_api_method resource: :people, action: :find + define_api_method resource: :people, action: :exclusions + define_api_method resource: :people, action: :exclude + define_api_method resource: :people, action: :update + define_api_method resource: :people, action: :events + define_api_method resource: :people, action: :metric_events + + define_api_method resource: :lists, action: :all + define_api_method resource: :lists, action: :find + define_api_method resource: :lists, action: :create + define_api_method resource: :lists, action: :update + define_api_method resource: :lists, action: :delete + define_api_method resource: :lists, action: :include_member_in_list? + define_api_method resource: :lists, action: :include_member_in_segment? + define_api_method resource: :lists, action: :subscribe + define_api_method resource: :lists, action: :unsubscribe + define_api_method resource: :lists, action: :batch_subscribe + define_api_method resource: :lists, action: :unsubscribes + + define_api_method resource: :templates, action: :all + define_api_method resource: :templates, action: :create + define_api_method resource: :templates, action: :update + define_api_method resource: :templates, action: :delete + define_api_method resource: :templates, action: :clone + define_api_method resource: :templates, action: :render + define_api_method resource: :templates, action: :render_and_send + private def constantize(class_name) - Object.module_eval(class_name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }) + Object.module_eval( + class_name.to_s.gsub(/\/(.?)/) { + "::#{$1.upcase}" + }.gsub(/(?:^|_)(.)/) { $1.upcase } + ) end end end