delighted 1.0.0.beta2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/README.md +4 -3
- data/USAGE.md +99 -0
- data/lib/delighted.rb +1 -0
- data/lib/delighted/client.rb +2 -1
- data/lib/delighted/version.rb +1 -1
- data/test/delighted_test.rb +4 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbd30413c6cbb1ddf012ba06c1e4360d14f4713e
|
4
|
+
data.tar.gz: c936317dfc07e80425b559384aeef161c98ea364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2318fd1929ee0e18781c50a98758af693fffa390b39511aa7a6522cb50df751de823d418c541ecd06f09c1a648a1c3aae714aa155a91c028db4bf0289f264ad
|
7
|
+
data.tar.gz: 7980888bf830ed0777ff63d6bc56a7a304caa7a9c2028792ba1c2b2c9edbf06792f7540b99893975d7673f08e901d97058fb298758e58c5f298ba96544a4a89d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# Delighted API client for Ruby [![Build Status](https://travis-ci.org/delighted/delighted-ruby.png)](https://travis-ci.org/delighted/delighted-ruby)
|
2
2
|
|
3
|
-
|
4
3
|
Official Ruby client for the [Delighted](https://delightedapp.com) API.
|
5
4
|
|
6
|
-
For installation and usage instructions, please [sign in to your Delighted account](https://delightedapp.com/signin) and follow the API documentation under Settings.
|
5
|
+
For basic installation and usage instructions, please [sign in to your Delighted account](https://delightedapp.com/signin) and follow the API documentation under Settings.
|
6
|
+
|
7
|
+
For more detailed examples, please see [USAGE.md](https://github.com/delighted/delighted-ruby/blob/master/USAGE.md).
|
7
8
|
|
8
9
|
## Supported Rubies
|
9
10
|
|
10
11
|
- Ruby MRI (1.8.7+)
|
11
12
|
- JRuby (1.8 + 1.9 modes)
|
12
|
-
- RBX (1.
|
13
|
+
- RBX (2.1.1)
|
13
14
|
- REE (1.8.7-2012.02)
|
14
15
|
|
15
16
|
## Contributing
|
data/USAGE.md
ADDED
@@ -0,0 +1,99 @@
|
|
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 30 seconds
|
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
|
+
### Adding survey responses
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# Add a survey response, score only
|
47
|
+
survey_response1 = Delighted::SurveyResponse.create(:person => person1.id, :score => 10)
|
48
|
+
|
49
|
+
# Add *another* survey response (for the same person), score and comment
|
50
|
+
survey_response2 = Delighted::SurveyResponse.create(:person => person1.id, :score => 5,
|
51
|
+
:comment => "Really nice.")
|
52
|
+
```
|
53
|
+
|
54
|
+
### Listing survey responses
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# List all survey responses, 20 per page
|
58
|
+
survey_responses_page_1 = Delighted::SurveyResponse.all
|
59
|
+
survey_responses_page_2 = Delighted::SurveyResponse.all(:page => 2)
|
60
|
+
|
61
|
+
# List all survey responses, 100 per page, page 5, with a time range
|
62
|
+
filtered_survey_responses = Delighted::SurveyResponse.all(:page => 5, :per_page => 100,
|
63
|
+
:since => Time.utc(2013, 10, 01), :until => Time.utc(2013, 11, 01))
|
64
|
+
```
|
65
|
+
|
66
|
+
### Retrieving metrics
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# Get current metrics, 30-day simple moving average, from most recent response
|
70
|
+
metrics = Delighted::Metrics.retrieve
|
71
|
+
|
72
|
+
# Get metrics, for given range
|
73
|
+
metrics = Delighted::Metrics.retrieve(:since => Time.utc(2013, 10, 01),
|
74
|
+
:until => Time.utc(2013, 11, 01))
|
75
|
+
```
|
76
|
+
|
77
|
+
## <a name="advanced-configuration"></a> Advanced configuration
|
78
|
+
|
79
|
+
The following options are configurable for the client:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Delighted.api_key
|
83
|
+
Delighted.api_base_url # default: 'https://api.delightedapp.com/v1'
|
84
|
+
Delighted.http_adapter # default: Delighted::HTTPAdapter.new
|
85
|
+
```
|
86
|
+
|
87
|
+
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:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# Create an custom client instance, and pass as last argument to resource actions
|
91
|
+
client = Delighted::Client.new(:api_key => 'API_KEY',
|
92
|
+
:api_base_url => 'https://api.delightedapp.com/v1', :http_adapter => Delighted::HTTPAdapter.new)
|
93
|
+
metrics_from_custom_client = Delighted::Metrics.retrieve({}, client)
|
94
|
+
|
95
|
+
# Or, you can set Delighted.shared_client yourself
|
96
|
+
Delighed.shared_client = Delighted::Client.new(:api_key => 'API_KEY',
|
97
|
+
:api_base_url => 'https://api.delightedapp.com/v1', :http_adapter => Delighted::HTTPAdapter.new)
|
98
|
+
metrics_from_custom_shared_client = Delighted::Metrics.retrieve
|
99
|
+
```
|
data/lib/delighted.rb
CHANGED
data/lib/delighted/client.rb
CHANGED
@@ -50,7 +50,8 @@ module Delighted
|
|
50
50
|
|
51
51
|
def default_headers
|
52
52
|
@default_headers ||= {
|
53
|
-
'Authorization' => "Basic #{["#{@api_key}:"].pack('m0')}"
|
53
|
+
'Authorization' => "Basic #{["#{@api_key}:"].pack('m0')}",
|
54
|
+
'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}"
|
54
55
|
}.freeze
|
55
56
|
end
|
56
57
|
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' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json" }
|
13
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "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' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json' }
|
28
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "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 @@ end
|
|
41
41
|
class Delighted::SurveyResponseTest < Delighted::TestCase
|
42
42
|
def test_creating_a_survey_response
|
43
43
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses")
|
44
|
-
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json' }
|
44
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
45
45
|
data = Delighted::JSON.dump({ :person => '123', :score => 10 })
|
46
46
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => '123', :score => 10 }))
|
47
47
|
mock_http_adapter.expects(:request).with(:post, uri, headers, data).once.returns(response)
|
@@ -56,7 +56,7 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
56
56
|
|
57
57
|
def test_listing_all_survey_responses
|
58
58
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses")
|
59
|
-
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json" }
|
59
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
60
60
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([{ :id => '123', :comment => 'One' }, { :id => '456', :comment => 'Two' }]))
|
61
61
|
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
62
62
|
|
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.0.0
|
4
|
+
version: 1.0.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: 2013-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- LICENSE
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
|
+
- USAGE.md
|
82
83
|
- delighted.gemspec
|
83
84
|
- lib/delighted.rb
|
84
85
|
- lib/delighted/client.rb
|
@@ -113,12 +114,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
116
|
requirements:
|
116
|
-
- - '
|
117
|
+
- - '>='
|
117
118
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
119
|
+
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.1.11
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Delighted is the easiest and most beautiful way to measure customer happiness.
|