Module: Ask
Constant Summary collapse
- API_URL =
"https://api.asksurveys.com/"
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
Instance Method Summary collapse
-
#schedule_nps(email, name = nil, delay = nil, properties = {}) ⇒ Object
Sends a POST to the Asksurveys API to schedule a satisfaction survey to be sent after a set amount of time.
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
9 10 11 |
# File 'lib/ask.rb', line 9 def api_token @api_token end |
Instance Method Details
#schedule_nps(email, name = nil, delay = nil, properties = {}) ⇒ Object
Sends a POST to the Asksurveys API to schedule a satisfaction survey to be sent
after a set amount of time.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ask.rb', line 20 def schedule_nps(email, name=nil, delay=nil, properties = {}) unless defined?(Ask.api_token) raise "Make sure to set the API key before using the library: Ask.key = '1234567890'" end connection = Faraday.new(url: API_URL) do |faraday| faraday.basic_auth api_token, '' faraday.request :url_encoded faraday.response :json # Parses response bodies as json. faraday.adapter Faraday.default_adapter end payload = {} payload[:email] = email payload[:name] = name if name payload[:schedule_at] = delay if delay payload[:properties] = properties connection.post "/v1/nps.json", payload end |