Module: Ask

Extended by:
Ask
Included in:
Ask
Defined in:
lib/ask.rb

Constant Summary collapse

API_URL =
"https://api.asksurveys.com/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_tokenObject

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.

Parameters:

  • user (User)

    The user to send a survey to.

  • delay (FixNum) (defaults to: nil)

    How long to wait before sending the survey.

  • properties (Hash) (defaults to: {})

    Additional properties to send about this user, purchase, item, etc.

See Also:



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