delighted 1.4.0.rc2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE +1 -1
- data/README.md +182 -8
- data/delighted.gemspec +3 -3
- data/lib/delighted.rb +1 -0
- data/lib/delighted/client.rb +1 -1
- data/lib/delighted/resources/bounce.rb +7 -0
- data/lib/delighted/resources/unsubscribe.rb +1 -0
- data/lib/delighted/version.rb +1 -1
- data/test/delighted_test.rb +43 -7
- data/test/test_helper.rb +1 -0
- metadata +10 -10
- data/USAGE.md +0 -150
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a61c272d2e9b5614ae8b289ac046686b89a537dc
|
4
|
+
data.tar.gz: b4511534ddea1075ff4e82892044eae1d39b6f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da76b95cfa9f4e3f0afb9516683b7d2d0ecd8036e92a8acab663f09d9cf1f1578e1095840919273b16945a8b9ae6088a019a742039548fcddabafa6517c5462
|
7
|
+
data.tar.gz: eff243c3c5b21dc77fe6985bd4aef5dff12a24f9796343a17ac000e71740b047cb2438c65ca60f5517b6db5bb69ede087d865523ef398aaf5326bfefa34b49ec
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,185 @@
|
|
1
|
-
|
1
|
+
[](https://travis-ci.org/delighted/delighted-ruby)
|
2
2
|
|
3
|
-
|
3
|
+
# Delighted API Ruby Client
|
4
4
|
|
5
|
-
|
5
|
+
Official Ruby client for the [Delighted API](https://delighted.com/docs/api).
|
6
6
|
|
7
|
-
|
7
|
+
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add `gem 'delighted'` to your application's Gemfile, and then run `bundle` to install.
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
To get started, you need to configure the client with your secret API key. If you're using Rails, you should add the following to new initializer file in `config/initializers/delighted.rb`.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'delighted'
|
17
|
+
Delighted.api_key = 'YOUR_API_KEY'
|
18
|
+
```
|
19
|
+
|
20
|
+
For further options, read the [advanced configuration section](#advanced-configuration).
|
21
|
+
|
22
|
+
**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* > *API*.
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Adding/updating people and scheduling surveys:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Add a new person, and schedule a survey immediately
|
30
|
+
person1 = Delighted::Person.create(:email => "foo+test1@delighted.com")
|
31
|
+
|
32
|
+
# Add a new person, and schedule a survey after 1 minute (60 seconds)
|
33
|
+
person2 = Delighted::Person.create(:email => "foo+test2@delighted.com",
|
34
|
+
:delay => 60)
|
35
|
+
|
36
|
+
# Add a new person, but do not schedule a survey
|
37
|
+
person3 = Delighted::Person.create(:email => "foo+test3@delighted.com",
|
38
|
+
:send => false)
|
39
|
+
|
40
|
+
# Add a new person with full set of attributes, including a custom question
|
41
|
+
# product name, and schedule a survey with a 30 second delay
|
42
|
+
person4 = Delighted::Person.create(:email => "foo+test4@delighted.com",
|
43
|
+
:name => "Joe Bloggs", :properties => { :customer_id => 123, :country => "USA",
|
44
|
+
:question_product_name => "The London Trench" }, :delay => 30)
|
45
|
+
|
46
|
+
# Update an existing person (identified by email), adding a name, without
|
47
|
+
# scheduling a survey
|
48
|
+
updated_person1 = Delighted::Person.create(:email => "foo+test1@delighted.com",
|
49
|
+
:name => "James Scott", :send => false)
|
50
|
+
```
|
51
|
+
|
52
|
+
Unsubscribing people:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# Unsubscribe an existing person
|
56
|
+
Delighted::Unsubscribe.create(:person_email => "foo+test1@delighted.com")
|
57
|
+
```
|
58
|
+
|
59
|
+
Listing people who have unsubscribed:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# List all people who have unsubscribed, 20 per page, first 2 pages
|
63
|
+
survey_responses_page1 = Delighted::Unsubscribe.all
|
64
|
+
survey_responses_page2 = Delighted::Unsubscribe.all(:page => 2)
|
65
|
+
```
|
66
|
+
|
67
|
+
Listing people whose emails have bounced:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# List all people whose emails have bounced, 20 per page, first 2 pages
|
71
|
+
survey_responses_page1 = Delighted::Bounce.all
|
72
|
+
survey_responses_page2 = Delighted::Bounce.all(:page => 2)
|
73
|
+
```
|
74
|
+
|
75
|
+
Deleting pending survey requests
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# Delete all pending (scheduled but unsent) survey requests for a person, by email.
|
79
|
+
Delighted::SurveyRequest.delete_pending(:person_email => "foo+test1@delighted.com")
|
80
|
+
```
|
81
|
+
|
82
|
+
Adding survey responses:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# Add a survey response, score only
|
86
|
+
survey_response1 = Delighted::SurveyResponse.create(:person => person1.id,
|
87
|
+
:score => 10)
|
88
|
+
|
89
|
+
# Add *another* survey response (for the same person), score and comment
|
90
|
+
survey_response2 = Delighted::SurveyResponse.create(:person => person1.id,
|
91
|
+
:score => 5, :comment => "Really nice.")
|
92
|
+
```
|
93
|
+
|
94
|
+
Retrieving a survey response:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# Retrieve an existing survey response
|
98
|
+
survey_response3 = Delighted::SurveyResponse.retrieve('123')
|
99
|
+
```
|
100
|
+
|
101
|
+
Updating survey responses:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# Update a survey response score
|
105
|
+
survey_response4 = Delighted::SurveyResponse.retrieve('234')
|
106
|
+
survey_response4.score = 10
|
107
|
+
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
108
|
+
|
109
|
+
# Update (or add) survey response properties
|
110
|
+
survey_response4.person_properties = { :segment => "Online" }
|
111
|
+
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
112
|
+
|
113
|
+
# Update person who recorded the survey response
|
114
|
+
survey_response4.person = '321'
|
115
|
+
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
116
|
+
```
|
117
|
+
|
118
|
+
Listing survey responses:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# List all survey responses, 20 per page, first 2 pages
|
122
|
+
survey_responses_page1 = Delighted::SurveyResponse.all
|
123
|
+
survey_responses_page2 = Delighted::SurveyResponse.all(:page => 2)
|
124
|
+
|
125
|
+
# List all survey responses, 20 per page, expanding person object
|
126
|
+
survey_responses_page1_expanded = Delighted::SurveyResponse.all(:expand => ['person'])
|
127
|
+
survey_responses_page1_expanded[0].person #=> #<Delighted::Person:...>
|
128
|
+
|
129
|
+
# List all survey responses, 20 per page, for a specific trend (ID: 123)
|
130
|
+
survey_responses_page1_trend = Delighted::SurveyResponse.all(:trend => "123")
|
131
|
+
|
132
|
+
# List all survey responses, 20 per page, in reverse chronological order (newest first)
|
133
|
+
survey_responses_page1_desc = Delighted::SurveyResponse.all(:order => 'desc')
|
134
|
+
|
135
|
+
# List all survey responses, 100 per page, page 5, with a time range
|
136
|
+
filtered_survey_responses = Delighted::SurveyResponse.all(:page => 5,
|
137
|
+
:per_page => 100, :since => Time.utc(2013, 10, 01),
|
138
|
+
:until => Time.utc(2013, 11, 01))
|
139
|
+
```
|
140
|
+
|
141
|
+
Retrieving metrics:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
# Get current metrics, 30-day simple moving average, from most recent response
|
145
|
+
metrics = Delighted::Metrics.retrieve
|
146
|
+
|
147
|
+
# Get current metrics, 30-day simple moving average, from most recent response,
|
148
|
+
# for a specific trend (ID: 123)
|
149
|
+
metrics = Delighted::Metrics.retrieve(:trend => "123")
|
150
|
+
|
151
|
+
# Get metrics, for given range
|
152
|
+
metrics = Delighted::Metrics.retrieve(:since => Time.utc(2013, 10, 01),
|
153
|
+
:until => Time.utc(2013, 11, 01))
|
154
|
+
```
|
155
|
+
|
156
|
+
## <a name="advanced-configuration"></a> Advanced configuration & testing
|
157
|
+
|
158
|
+
The following options are configurable for the client:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Delighted.api_key
|
162
|
+
Delighted.api_base_url # default: 'https://api.delighted.com/v1'
|
163
|
+
Delighted.http_adapter # default: Delighted::HTTPAdapter.new
|
164
|
+
```
|
165
|
+
|
166
|
+
By default, a shared instance of `Delighted::Client` is created lazily in `Delighted.shared_client`. If you want to create your own client, perhaps for test or if you have multiple API keys, you can:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
# Create an custom client instance, and pass as last argument to resource actions
|
170
|
+
client = Delighted::Client.new(:api_key => 'API_KEY',
|
171
|
+
:api_base_url => 'https://api.delighted.com/v1',
|
172
|
+
:http_adapter => Delighted::HTTPAdapter.new)
|
173
|
+
metrics_from_custom_client = Delighted::Metrics.retrieve({}, client)
|
174
|
+
|
175
|
+
# Or, you can set Delighted.shared_client yourself
|
176
|
+
Delighted.shared_client = Delighted::Client.new(:api_key => 'API_KEY',
|
177
|
+
:api_base_url => 'https://api.delighted.com/v1',
|
178
|
+
:http_adapter => Delighted::HTTPAdapter.new)
|
179
|
+
metrics_from_custom_shared_client = Delighted::Metrics.retrieve
|
180
|
+
```
|
181
|
+
|
182
|
+
## Supported runtimes
|
10
183
|
|
11
184
|
- Ruby MRI (1.8.7+)
|
12
185
|
- JRuby (1.8 + 1.9 modes)
|
@@ -17,6 +190,7 @@ For more detailed examples, please see [USAGE.md](https://github.com/delighted/d
|
|
17
190
|
|
18
191
|
1. Fork it
|
19
192
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
20
|
-
3.
|
21
|
-
4.
|
22
|
-
5.
|
193
|
+
3. Run the tests (`rake test`)
|
194
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
195
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
196
|
+
6. Create new Pull Request
|
data/delighted.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "delighted"
|
7
7
|
spec.version = Delighted::VERSION
|
8
8
|
spec.authors = ["Mark Dodwell"]
|
9
|
-
spec.email = ["mark@
|
10
|
-
spec.description = "Delighted API
|
11
|
-
spec.summary = "Delighted is the
|
9
|
+
spec.email = ["mark@delighted.com"]
|
10
|
+
spec.description = "Delighted API Ruby Client."
|
11
|
+
spec.summary = "Delighted is the fastest and easiest way to gather actionable feedback from your customers."
|
12
12
|
spec.homepage = "https://github.com/delighted/delighted-ruby"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
data/lib/delighted.rb
CHANGED
@@ -16,6 +16,7 @@ require 'delighted/operations/create'
|
|
16
16
|
require 'delighted/operations/retrieve'
|
17
17
|
require 'delighted/operations/update'
|
18
18
|
|
19
|
+
require 'delighted/resources/bounce'
|
19
20
|
require 'delighted/resources/metrics'
|
20
21
|
require 'delighted/resources/person'
|
21
22
|
require 'delighted/resources/survey_request'
|
data/lib/delighted/client.rb
CHANGED
@@ -70,7 +70,7 @@ module Delighted
|
|
70
70
|
|
71
71
|
def default_headers
|
72
72
|
@default_headers ||= {
|
73
|
-
'Authorization' => "Basic #{["#{@api_key}:"].pack('
|
73
|
+
'Authorization' => "Basic #{["#{@api_key}:"].pack('m').chomp}",
|
74
74
|
'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}"
|
75
75
|
}.freeze
|
76
76
|
end
|
data/lib/delighted/version.rb
CHANGED
data/test/delighted_test.rb
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
class Delighted::MetricsTest < Delighted::TestCase
|
11
11
|
def test_retrieving_metrics
|
12
12
|
uri = URI.parse("https://api.delightedapp.com/v1/metrics")
|
13
|
-
headers = { 'Authorization' =>
|
13
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
14
14
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :nps => 10 }))
|
15
15
|
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
16
16
|
|
@@ -25,7 +25,7 @@ end
|
|
25
25
|
class Delighted::PeopleTest < Delighted::TestCase
|
26
26
|
def test_creating_or_updating_a_person
|
27
27
|
uri = URI.parse("https://api.delightedapp.com/v1/people")
|
28
|
-
headers = { 'Authorization' =>
|
28
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
29
29
|
data = Delighted::JSON.dump({ :email => 'foo@bar.com' })
|
30
30
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '123', :email => 'foo@bar.com' }))
|
31
31
|
mock_http_adapter.expects(:request).with(:post, uri, headers, data).once.returns(response)
|
@@ -41,7 +41,7 @@ class Delighted::PeopleTest < Delighted::TestCase
|
|
41
41
|
person_email = 'person@example.com'
|
42
42
|
uri = URI.parse('https://api.delightedapp.com/v1/unsubscribes')
|
43
43
|
headers = {
|
44
|
-
'Authorization' =>
|
44
|
+
'Authorization' => @auth_header,
|
45
45
|
'Accept' => 'application/json',
|
46
46
|
'Content-Type' => 'application/json',
|
47
47
|
'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}"
|
@@ -57,7 +57,7 @@ class Delighted::PeopleTest < Delighted::TestCase
|
|
57
57
|
|
58
58
|
def test_deleting_pending_survey_requests_for_a_person
|
59
59
|
uri = URI.parse("https://api.delightedapp.com/v1/people/foo%40bar.com/survey_requests/pending")
|
60
|
-
headers = { 'Authorization' =>
|
60
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
61
61
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :ok => true }))
|
62
62
|
mock_http_adapter.expects(:request).with(:delete, uri, headers, nil).once.returns(response)
|
63
63
|
|
@@ -70,7 +70,7 @@ end
|
|
70
70
|
class Delighted::SurveyResponseTest < Delighted::TestCase
|
71
71
|
def test_creating_a_survey_response
|
72
72
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses")
|
73
|
-
headers = { 'Authorization' =>
|
73
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
74
74
|
data = Delighted::JSON.dump({ :person => '123', :score => 10 })
|
75
75
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => '123', :score => 10 }))
|
76
76
|
mock_http_adapter.expects(:request).with(:post, uri, headers, data).once.returns(response)
|
@@ -132,7 +132,7 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
132
132
|
|
133
133
|
def test_listing_all_survey_responses
|
134
134
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses?order=desc")
|
135
|
-
headers = { 'Authorization' =>
|
135
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
136
136
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([{ :id => '123', :comment => 'One' }, { :id => '456', :comment => 'Two' }]))
|
137
137
|
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
138
138
|
|
@@ -150,7 +150,7 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
150
150
|
|
151
151
|
def test_listing_all_survey_responses_expand_person
|
152
152
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses?expand%5B%5D=person")
|
153
|
-
headers = { 'Authorization' =>
|
153
|
+
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
154
154
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([{ :id => '123', :comment => 'One', :person => { :id => '123', :email => 'foo@bar.com' } }, { :id => '456', :comment => 'Two', :person => { :id => '123', :email => 'foo@bar.com' } }]))
|
155
155
|
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
156
156
|
|
@@ -170,3 +170,39 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
170
170
|
assert_equal({ :email => 'foo@bar.com' }, survey_responses[1].person.to_hash)
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
class Delighted::UnsubscribesTest < Delighted::TestCase
|
175
|
+
def test_listing_unsubscribes
|
176
|
+
uri = URI.parse("https://api.delightedapp.com/v1/unsubscribes")
|
177
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
178
|
+
example_unsub = {:person_id => '4945', :email => 'foo@example.com', :name => nil, :unsubscribed_at => 1440621400}
|
179
|
+
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([example_unsub]))
|
180
|
+
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
181
|
+
|
182
|
+
unsubscribes = Delighted::Unsubscribe.all
|
183
|
+
assert_equal 1, unsubscribes.size
|
184
|
+
first_unsub = unsubscribes.first
|
185
|
+
assert_kind_of Delighted::Unsubscribe, first_unsub
|
186
|
+
assert_equal '4945', first_unsub.person_id
|
187
|
+
assert_equal example_unsub, first_unsub.to_hash
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
class Delighted::BouncesTest < Delighted::TestCase
|
193
|
+
def test_listing_bounces
|
194
|
+
uri = URI.parse("https://api.delightedapp.com/v1/bounces")
|
195
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
196
|
+
example_bounce = {:person_id => '4945', :email => 'foo@example.com', :name => nil, :bounced_at => 1440621400}
|
197
|
+
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([example_bounce]))
|
198
|
+
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
199
|
+
|
200
|
+
bounces = Delighted::Bounce.all
|
201
|
+
assert_equal 1, bounces.size
|
202
|
+
first_bounce = bounces.first
|
203
|
+
assert_kind_of Delighted::Bounce, first_bounce
|
204
|
+
assert_equal '4945', first_bounce.person_id
|
205
|
+
assert_equal example_bounce, first_bounce.to_hash
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delighted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Dodwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -66,9 +66,9 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Delighted API
|
69
|
+
description: Delighted API Ruby Client.
|
70
70
|
email:
|
71
|
-
- mark@
|
71
|
+
- mark@delighted.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- LICENSE
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
-
- USAGE.md
|
84
83
|
- delighted.gemspec
|
85
84
|
- lib/delighted.rb
|
86
85
|
- lib/delighted/client.rb
|
@@ -94,6 +93,7 @@ files:
|
|
94
93
|
- lib/delighted/operations/retrieve.rb
|
95
94
|
- lib/delighted/operations/update.rb
|
96
95
|
- lib/delighted/resource.rb
|
96
|
+
- lib/delighted/resources/bounce.rb
|
97
97
|
- lib/delighted/resources/metrics.rb
|
98
98
|
- lib/delighted/resources/person.rb
|
99
99
|
- lib/delighted/resources/survey_request.rb
|
@@ -118,16 +118,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - '
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
123
|
+
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.4.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
|
-
summary: Delighted is the
|
130
|
-
|
129
|
+
summary: Delighted is the fastest and easiest way to gather actionable feedback from
|
130
|
+
your customers.
|
131
131
|
test_files:
|
132
132
|
- test/delighted_test.rb
|
133
133
|
- test/test_helper.rb
|
data/USAGE.md
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
## Installation
|
2
|
-
|
3
|
-
Add `gem 'delighted'` to your application's Gemfile, and then run `bundle` to install.
|
4
|
-
|
5
|
-
## Configuration
|
6
|
-
|
7
|
-
To get started, you need to configure the client with your secret API key. If you're using Rails, you should add the following to new initializer file in `config/initializers/delighted.rb`.
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
require 'delighted'
|
11
|
-
Delighted.api_key = 'YOUR_API_KEY'
|
12
|
-
```
|
13
|
-
|
14
|
-
For further options, read the [advanced configuration section](#advanced-configuration).
|
15
|
-
|
16
|
-
**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* > *API*.
|
17
|
-
|
18
|
-
## Usage
|
19
|
-
|
20
|
-
### Adding/updating people and scheduling surveys
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
# Add a new person, and schedule a survey immediately
|
24
|
-
person1 = Delighted::Person.create(:email => "foo+testing1@delightedapp.com")
|
25
|
-
|
26
|
-
# Add a new person, and schedule a survey after 1 minute (60 seconds)
|
27
|
-
person2 = Delighted::Person.create(:email => "foo+testing2@delightedapp.com", :delay => 60)
|
28
|
-
|
29
|
-
# Add a new person, but do not schedule a survey
|
30
|
-
person3 = Delighted::Person.create(:email => "foo+testing3@delightedapp.com", :send => false)
|
31
|
-
|
32
|
-
# Add a new person with full set of attributes, including a custom question product name,
|
33
|
-
# and schedule a survey with a 30 second delay
|
34
|
-
person4 = Delighted::Person.create(:email => "foo+testing4@delightedapp.com", :name => "Joe Bloggs",
|
35
|
-
:properties => { :customer_id => 123, :country => "USA", :question_product_name => "Apple Genius Bar" },
|
36
|
-
:delay => 30)
|
37
|
-
|
38
|
-
# Update an existing person (identified by email), adding a name, without scheduling a survey
|
39
|
-
updated_person1 = Delighted::Person.create(:email => "foo+testing1@delightedapp.com",
|
40
|
-
:name => "James Scott", :send => false)
|
41
|
-
```
|
42
|
-
|
43
|
-
### Unsubscribing people
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
# Unsubscribe an existing person
|
47
|
-
Delighted::Unsubscribe.create(:person_email => "foo+testing1@delightedapp.com")
|
48
|
-
```
|
49
|
-
|
50
|
-
### Deleting pending survey requests
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
# Delete all pending (scheduled but unsent) survey requests for a person, by email.
|
54
|
-
Delighted::SurveyRequest.delete_pending(:person_email => "foo+testing1@delightedapp.com")
|
55
|
-
```
|
56
|
-
|
57
|
-
### Adding survey responses
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
# Add a survey response, score only
|
61
|
-
survey_response1 = Delighted::SurveyResponse.create(:person => person1.id, :score => 10)
|
62
|
-
|
63
|
-
# Add *another* survey response (for the same person), score and comment
|
64
|
-
survey_response2 = Delighted::SurveyResponse.create(:person => person1.id, :score => 5,
|
65
|
-
:comment => "Really nice.")
|
66
|
-
```
|
67
|
-
|
68
|
-
### Retrieving a survey response
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
# Retrieve an existing survey response
|
72
|
-
survey_response3 = Delighted::SurveyResponse.retrieve('123')
|
73
|
-
```
|
74
|
-
|
75
|
-
### Updating survey responses
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
# Update a survey response score
|
79
|
-
survey_response4 = Delighted::SurveyResponse.retrieve('234')
|
80
|
-
survey_response4.score = 10
|
81
|
-
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
82
|
-
|
83
|
-
# Update (or add) survey response properties
|
84
|
-
survey_response4.person_properties = { :segment => "Online" }
|
85
|
-
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
86
|
-
|
87
|
-
# Update person who recorded the survey response
|
88
|
-
survey_response4.person = '321'
|
89
|
-
survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
90
|
-
```
|
91
|
-
|
92
|
-
### Listing survey responses
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
# List all survey responses, 20 per page, first 2 pages
|
96
|
-
survey_responses_page_1 = Delighted::SurveyResponse.all
|
97
|
-
survey_responses_page_2 = Delighted::SurveyResponse.all(:page => 2)
|
98
|
-
|
99
|
-
# List all survey responses, 20 per page, expanding person object
|
100
|
-
survey_responses_page_1_expanded = Delighted::SurveyResponse.all(:expand => ['person'])
|
101
|
-
survey_responses_page_1_expanded[0].person #=> #<Delighted::Person:...>
|
102
|
-
|
103
|
-
# List all survey responses, 20 per page, for a specific trend (ID: 123)
|
104
|
-
survey_responses_page_1_trend = Delighted::SurveyResponse.all(:trend => "123")
|
105
|
-
|
106
|
-
# List all survey responses, 20 per page, in reverse chronological order (newest first)
|
107
|
-
survey_responses_page_1_desc = Delighted::SurveyResponse.all(:order => 'desc')
|
108
|
-
|
109
|
-
# List all survey responses, 100 per page, page 5, with a time range
|
110
|
-
filtered_survey_responses = Delighted::SurveyResponse.all(:page => 5, :per_page => 100,
|
111
|
-
:since => Time.utc(2013, 10, 01), :until => Time.utc(2013, 11, 01))
|
112
|
-
```
|
113
|
-
|
114
|
-
### Retrieving metrics
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
# Get current metrics, 30-day simple moving average, from most recent response
|
118
|
-
metrics = Delighted::Metrics.retrieve
|
119
|
-
|
120
|
-
# Get current metrics, 30-day simple moving average, from most recent response, for a specific trend (ID: 123)
|
121
|
-
metrics = Delighted::Metrics.retrieve(:trend => "123")
|
122
|
-
|
123
|
-
# Get metrics, for given range
|
124
|
-
metrics = Delighted::Metrics.retrieve(:since => Time.utc(2013, 10, 01),
|
125
|
-
:until => Time.utc(2013, 11, 01))
|
126
|
-
```
|
127
|
-
|
128
|
-
## <a name="advanced-configuration"></a> Advanced configuration
|
129
|
-
|
130
|
-
The following options are configurable for the client:
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
Delighted.api_key
|
134
|
-
Delighted.api_base_url # default: 'https://api.delightedapp.com/v1'
|
135
|
-
Delighted.http_adapter # default: Delighted::HTTPAdapter.new
|
136
|
-
```
|
137
|
-
|
138
|
-
By default, a shared instance of `Delighted::Client` is created lazily in `Delighted.shared_client`. If you want to create your own client, perhaps for testing or if you have multiple API keys, you can:
|
139
|
-
|
140
|
-
```ruby
|
141
|
-
# Create an custom client instance, and pass as last argument to resource actions
|
142
|
-
client = Delighted::Client.new(:api_key => 'API_KEY',
|
143
|
-
:api_base_url => 'https://api.delightedapp.com/v1', :http_adapter => Delighted::HTTPAdapter.new)
|
144
|
-
metrics_from_custom_client = Delighted::Metrics.retrieve({}, client)
|
145
|
-
|
146
|
-
# Or, you can set Delighted.shared_client yourself
|
147
|
-
Delighted.shared_client = Delighted::Client.new(:api_key => 'API_KEY',
|
148
|
-
:api_base_url => 'https://api.delightedapp.com/v1', :http_adapter => Delighted::HTTPAdapter.new)
|
149
|
-
metrics_from_custom_shared_client = Delighted::Metrics.retrieve
|
150
|
-
```
|