module FreshmailApi::Client
Constants
- ENDPOINT
Public Instance Methods
perform(method, path, data={})
click to toggle source
# File lib/freshmail_api/client.rb, line 6 def perform(method, path, data={}) data = parse_data(data) path = "/rest/#{path}" response = client.send(method, path) do |request| request.headers = headers(path, data) request.body = data if method == :post end JSON.parse(response.body) end
Private Instance Methods
client()
click to toggle source
# File lib/freshmail_api/client.rb, line 19 def client @client ||= Faraday.new(ENDPOINT) end
headers(path, data)
click to toggle source
# File lib/freshmail_api/client.rb, line 27 def headers(path, data) { 'Content-Type' => 'application/json', 'X-Rest-ApiKey' => configuration.api_key, 'X-Rest-ApiSign' => authorize(path, data) } end
parse_data(data)
click to toggle source
# File lib/freshmail_api/client.rb, line 23 def parse_data(data) data.empty? ? '' : data.to_json end