delighted 1.2.0 → 1.3.0.rc1
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/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/USAGE.md +12 -2
- data/lib/delighted/resource.rb +8 -2
- data/lib/delighted/resources/survey_response.rb +20 -0
- data/lib/delighted/utils.rb +1 -1
- data/lib/delighted/version.rb +1 -1
- data/test/delighted_test.rb +22 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0398185f79509fb4bd2b35e4e25ba8b4b9653d
|
4
|
+
data.tar.gz: 25ecde8c4fc548fc4571a8c25244c0930c833e14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8e06cd8ce9df39d61a0257bcd7ba4fa6db2b340917b883921b30bee40a051fd757cdd94fbb70166d27a8afa93daec5da570c2995aa7eaadfe1dfefffbf6681
|
7
|
+
data.tar.gz: 913d32f3d9e4fa207c2e40fd314bb85196060302e4c1a457c6b185d99a79a383382e3d3e8147480d04a65ee52d140491601e2dc1aea7a53427151da16c0746cb
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/USAGE.md
CHANGED
@@ -61,13 +61,20 @@ survey_response2 = Delighted::SurveyResponse.create(:person => person1.id, :scor
|
|
61
61
|
### Listing survey responses
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
# List all survey responses, 20 per page
|
64
|
+
# List all survey responses, 20 per page, first 2 pages
|
65
65
|
survey_responses_page_1 = Delighted::SurveyResponse.all
|
66
66
|
survey_responses_page_2 = Delighted::SurveyResponse.all(:page => 2)
|
67
67
|
|
68
|
+
```ruby
|
69
|
+
# List all survey responses, 20 per page, expanding person object
|
70
|
+
survey_responses_page_1_expanded = Delighted::SurveyResponse.all(:expand => ['person'])
|
71
|
+
survey_responses_page_1_expanded[0].person #=> #<Delighted::Person:...>
|
72
|
+
|
73
|
+
# List all survey responses, 20 per page, for a specific trend (ID: 123)
|
74
|
+
survey_responses_page_1_trend = Delighted::SurveyResponse.all(:trend => "123")
|
75
|
+
|
68
76
|
# List all survey responses, 20 per page, in reverse chronological order (newest first)
|
69
77
|
survey_responses_page_1_desc = Delighted::SurveyResponse.all(:order => 'desc')
|
70
|
-
survey_responses_page_2_desc = Delighted::SurveyResponse.all(:order => 'desc', :page => 2)
|
71
78
|
|
72
79
|
# List all survey responses, 100 per page, page 5, with a time range
|
73
80
|
filtered_survey_responses = Delighted::SurveyResponse.all(:page => 5, :per_page => 100,
|
@@ -80,6 +87,9 @@ filtered_survey_responses = Delighted::SurveyResponse.all(:page => 5, :per_page
|
|
80
87
|
# Get current metrics, 30-day simple moving average, from most recent response
|
81
88
|
metrics = Delighted::Metrics.retrieve
|
82
89
|
|
90
|
+
# Get current metrics, 30-day simple moving average, from most recent response, for a specific trend (ID: 123)
|
91
|
+
metrics = Delighted::Metrics.retrieve(:trend => "123")
|
92
|
+
|
83
93
|
# Get metrics, for given range
|
84
94
|
metrics = Delighted::Metrics.retrieve(:since => Time.utc(2013, 10, 01),
|
85
95
|
:until => Time.utc(2013, 11, 01))
|
data/lib/delighted/resource.rb
CHANGED
@@ -25,8 +25,7 @@ module Delighted
|
|
25
25
|
def initialize(attributes = {})
|
26
26
|
@id = attributes[:id]
|
27
27
|
define_id_reader if @id
|
28
|
-
|
29
|
-
define_attribute_accessors(@attributes.keys)
|
28
|
+
build_from_attributes(attributes)
|
30
29
|
end
|
31
30
|
|
32
31
|
def to_hash
|
@@ -34,6 +33,13 @@ module Delighted
|
|
34
33
|
end
|
35
34
|
alias_method :to_h, :to_hash
|
36
35
|
|
36
|
+
protected
|
37
|
+
|
38
|
+
def build_from_attributes(attributes)
|
39
|
+
@attributes = Utils.hash_without_key(attributes, :id)
|
40
|
+
define_attribute_accessors(@attributes.keys)
|
41
|
+
end
|
42
|
+
|
37
43
|
private
|
38
44
|
|
39
45
|
def define_id_reader
|
@@ -4,5 +4,25 @@ module Delighted
|
|
4
4
|
|
5
5
|
include Operations::Create
|
6
6
|
include Operations::All
|
7
|
+
|
8
|
+
def to_hash
|
9
|
+
if Person === attributes[:person]
|
10
|
+
Utils.hash_without_key(attributes, :person)
|
11
|
+
else
|
12
|
+
attributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def build_from_attributes(attributes)
|
19
|
+
attributes_dup = attributes.dup
|
20
|
+
|
21
|
+
if Hash === attributes_dup[:person]
|
22
|
+
attributes_dup[:person] = Person.new(attributes_dup.delete(:person))
|
23
|
+
end
|
24
|
+
|
25
|
+
super(attributes_dup)
|
26
|
+
end
|
7
27
|
end
|
8
28
|
end
|
data/lib/delighted/utils.rb
CHANGED
data/lib/delighted/version.rb
CHANGED
data/test/delighted_test.rb
CHANGED
@@ -82,4 +82,26 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
82
82
|
assert_equal 'Two', survey_responses[1].comment
|
83
83
|
assert_equal '456', survey_responses[1].id
|
84
84
|
end
|
85
|
+
|
86
|
+
def test_listing_all_survey_responses_expand_person
|
87
|
+
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses?expand%5B%5D=person")
|
88
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
89
|
+
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' } }]))
|
90
|
+
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
91
|
+
|
92
|
+
survey_responses = Delighted::SurveyResponse.all(:expand => ['person'])
|
93
|
+
assert_kind_of Delighted::EnumerableResourceCollection, survey_responses
|
94
|
+
assert_kind_of Delighted::SurveyResponse, survey_responses[0]
|
95
|
+
assert_equal({ :comment => 'One' }, survey_responses[0].to_hash)
|
96
|
+
assert_equal 'One', survey_responses[0].comment
|
97
|
+
assert_equal '123', survey_responses[0].id
|
98
|
+
assert_kind_of Delighted::Person, survey_responses[0].person
|
99
|
+
assert_equal({ :email => 'foo@bar.com' }, survey_responses[0].person.to_hash)
|
100
|
+
assert_kind_of Delighted::SurveyResponse, survey_responses[1]
|
101
|
+
assert_equal({ :comment => 'Two' }, survey_responses[1].to_hash)
|
102
|
+
assert_equal 'Two', survey_responses[1].comment
|
103
|
+
assert_equal '456', survey_responses[1].id
|
104
|
+
assert_kind_of Delighted::Person, survey_responses[1].person
|
105
|
+
assert_equal({ :email => 'foo@bar.com' }, survey_responses[1].person.to_hash)
|
106
|
+
end
|
85
107
|
end
|
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.3.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Dodwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -116,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- - '
|
119
|
+
- - '>'
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
121
|
+
version: 1.3.1
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
124
|
rubygems_version: 2.2.2
|