class Zenps::Client
Api client for Zenps
Attributes
options[R]
response[R]
Public Class Methods
new()
click to toggle source
# File lib/zenps/client.rb, line 8 def initialize check_configuration end
Public Instance Methods
call(options = {})
click to toggle source
# File lib/zenps/client.rb, line 12 def call(options = {}) @options = options perform_request expose_response end
Private Instance Methods
body()
click to toggle source
# File lib/zenps/client.rb, line 51 def body { to: to, locale: get_attribute(:locale, default: 'en'), event: get_attribute(:event), tags: tags }.compact.to_json end
check_configuration()
click to toggle source
# File lib/zenps/client.rb, line 22 def check_configuration raise KeyMissingError if ::Zenps.config[:zenps_key].nil? end
end_point()
click to toggle source
# File lib/zenps/client.rb, line 78 def end_point 'https://api.zenps.io/nps/v1/surveys' end
expose_response()
click to toggle source
# File lib/zenps/client.rb, line 32 def expose_response { email: get_attribute(:email), code: response.code.to_i, body: response.body } end
get_attribute(attribute, params = {})
click to toggle source
# File lib/zenps/client.rb, line 68 def get_attribute(attribute, params = {}) options[attribute.to_s] || options[attribute] || params[:default] end
header()
click to toggle source
# File lib/zenps/client.rb, line 44 def header @header ||= { 'Content-Type': 'text/json', 'Authorization': ::Zenps.config[:zenps_key] } end
perform_request()
click to toggle source
# File lib/zenps/client.rb, line 26 def perform_request request = Net::HTTP::Post.new(uri, header) request.body = body @response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request request } end
to()
click to toggle source
# File lib/zenps/client.rb, line 60 def to { email: get_attribute(:email), first_name: get_attribute(:first_name), last_name: get_attribute(:last_name) }.compact end
uri()
click to toggle source
# File lib/zenps/client.rb, line 40 def uri @uri ||= URI.parse(end_point) end