Sha256: 3d13b1cfffa88db291a47a23e4f620753406a789ef867f10159e427d74ecab84
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
require 'faraday' module Leadsquared class Client ENDPOINT = 'https://api.leadsquared.com'.freeze HEADERS = {'Content-Type' => 'application/json', 'Accept' => 'application/json'}.freeze attr_reader :key, :secret, :endpoint def initialize(key = nil, secret = nil, endpoint = nil) @key = key || Leadsquared.config.key @secret = secret || Leadsquared.config.secret @endpoint = endpoint || Leadsquared.config.endpoint || ENDPOINT raise ArgumentError.new("Missing key or secret") unless @secret and @key end def post(url, params = {}, body = nil) conn = Faraday.new(url: @endpoint) merged_params = {accessKey: @key, secretKey: @secret}.merge(params) response = conn.post(url) do |req| req.headers = HEADERS req.params = merged_params req.body = body if body end response end def get(url, params = {}) conn = Faraday.new(url: @endpoint) merged_params = {accessKey: @key, secretKey: @secret}.merge(params) response = conn.get(url) do |req| req.headers = HEADERS req.params = merged_params end response end end end
Version data entries
5 entries across 5 versions & 1 rubygems