Sha256: a978636d53d9ffba44a1108d117f28a9cf7df4f70b39304564d4725f52af369d
Contents?: true
Size: 1.33 KB
Versions: 3
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module ActiveCampaign module ApiHttp # :nodoc: extend ActiveSupport::Concern HTTP_METHODS = %i[get post put delete].freeze module ClassMethods # :nodoc: HTTP_METHODS.each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(path, params={}) root = params.delete(:_root) send(:'#{method}_raw', path, params) do |parsed_data, response| return {} unless [200, 201].include?(parsed_data[:status_code]) return {} unless parsed_data[:data].present? data = if root parsed_data[:data][root.to_sym] else parsed_data[:data].first.last end if data.is_a?(Array) new_records data else new_record data end end end def #{method}_raw(path, params={}, &block) request(params.merge(:_method => #{method.to_sym.inspect}, :_path => path), &block) end RUBY end def request(params = {}) api = ActiveCampaign::API.new request = api.request params if block_given? yield request[:parsed_data], request[:_response] else request end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ractive_campaign-0.1.3 | lib/active_campaign/api_http.rb |
ractive_campaign-0.1.2 | lib/active_campaign/api_http.rb |
ractive_campaign-0.1.1 | lib/active_campaign/api_http.rb |