delighted 1.4.0.rc1 → 1.4.0.rc2
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/USAGE.md +0 -1
- data/lib/delighted/http_adapter.rb +2 -1
- data/lib/delighted/operations/retrieve.rb +3 -2
- data/lib/delighted/operations/update.rb +2 -1
- data/lib/delighted/resource.rb +34 -13
- data/lib/delighted/resources/survey_response.rb +1 -20
- data/lib/delighted/utils.rb +1 -1
- data/lib/delighted/version.rb +1 -1
- data/test/delighted_test.rb +18 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fa8281430a51548a8010a39f65cdafcdb70019e
|
4
|
+
data.tar.gz: c6c74bef892f5e83bfdb3019fe561480d51363d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3650ee32960f335aa669eec0187dd96d800fba8a95e598cc96bac63247b9892c49a4de59823e592e172589b62d2d8a7d67ab44d2adfa1eaefcba3f9469b3e03
|
7
|
+
data.tar.gz: 0d78aa7a4f04ffd4ac9a7b23d79150466999e6b056027de9ba24cb9794ca8fc9fc51ffdc5f0b7363c27fbd41485ccbc37cd1cd72928f3c6bef302ddf0c2c05fb
|
data/USAGE.md
CHANGED
@@ -96,7 +96,6 @@ survey_response4.save #=> #<Delighted::SurveyResponse:...>
|
|
96
96
|
survey_responses_page_1 = Delighted::SurveyResponse.all
|
97
97
|
survey_responses_page_2 = Delighted::SurveyResponse.all(:page => 2)
|
98
98
|
|
99
|
-
```ruby
|
100
99
|
# List all survey responses, 20 per page, expanding person object
|
101
100
|
survey_responses_page_1_expanded = Delighted::SurveyResponse.all(:expand => ['person'])
|
102
101
|
survey_responses_page_1_expanded[0].person #=> #<Delighted::Person:...>
|
@@ -11,8 +11,9 @@ module Delighted
|
|
11
11
|
|
12
12
|
module Pluralton
|
13
13
|
module ClassMethods
|
14
|
-
def retrieve(id, client = Delighted.shared_client)
|
15
|
-
|
14
|
+
def retrieve(id, opts = {}, client = Delighted.shared_client)
|
15
|
+
opts = Utils.serialize_values(opts)
|
16
|
+
json = client.get_json(path(id), opts)
|
16
17
|
new(json)
|
17
18
|
end
|
18
19
|
|
@@ -8,7 +8,8 @@ module Delighted
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def save(client = Delighted.shared_client)
|
11
|
-
params = Utils.hash_without_key(
|
11
|
+
params = Utils.hash_without_key(to_hash, :id)
|
12
|
+
params = params.merge(:expand => expanded_attribute_names) unless expanded_attribute_names.empty?
|
12
13
|
params = Utils.serialize_values(params)
|
13
14
|
json = client.put_json(self.class.path(id), params)
|
14
15
|
self.class.new(json)
|
data/lib/delighted/resource.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
module Delighted
|
2
2
|
class Resource
|
3
3
|
class << self
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def path
|
9
|
-
@path
|
10
|
-
end
|
4
|
+
attr_accessor :path
|
5
|
+
attr_writer :singleton_resource, :expandable_attributes
|
11
6
|
|
12
|
-
def
|
13
|
-
@
|
7
|
+
def expandable_attributes
|
8
|
+
@expandable_attributes ||= {}
|
14
9
|
end
|
15
10
|
|
16
11
|
def singleton_resource?
|
@@ -28,20 +23,46 @@ module Delighted
|
|
28
23
|
build_from_attributes(attributes)
|
29
24
|
end
|
30
25
|
|
26
|
+
# Attributes used for serialization
|
31
27
|
def to_hash
|
32
|
-
attributes
|
28
|
+
serialized_attributes = attributes.dup
|
29
|
+
|
30
|
+
self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
|
31
|
+
if expanded_class === attributes[attribute_name]
|
32
|
+
serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
serialized_attributes
|
33
37
|
end
|
34
38
|
alias_method :to_h, :to_hash
|
35
39
|
|
36
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def expanded_attribute_names
|
43
|
+
names = Set.new
|
44
|
+
|
45
|
+
self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
|
46
|
+
if expanded_class === attributes[attribute_name]
|
47
|
+
names << attribute_name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
names
|
52
|
+
end
|
37
53
|
|
38
54
|
def build_from_attributes(attributes)
|
39
55
|
@attributes = Utils.hash_without_key(attributes, :id)
|
56
|
+
|
57
|
+
self.class.expandable_attributes.each_pair do |attribute_name, expanded_class|
|
58
|
+
if Hash === @attributes[attribute_name]
|
59
|
+
@attributes[attribute_name] = expanded_class.new(@attributes.delete(attribute_name))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
40
63
|
define_attribute_accessors(@attributes.keys)
|
41
64
|
end
|
42
65
|
|
43
|
-
private
|
44
|
-
|
45
66
|
def define_id_reader
|
46
67
|
Utils.eigenclass(self).instance_eval do
|
47
68
|
attr_reader :id
|
@@ -1,30 +1,11 @@
|
|
1
1
|
module Delighted
|
2
2
|
class SurveyResponse < Resource
|
3
3
|
self.path = "/survey_responses"
|
4
|
+
self.expandable_attributes = { :person => Person }
|
4
5
|
|
5
6
|
include Operations::Create
|
6
7
|
include Operations::All
|
7
8
|
include Operations::Update
|
8
9
|
include Operations::Retrieve
|
9
|
-
|
10
|
-
def to_hash
|
11
|
-
if Person === attributes[:person]
|
12
|
-
Utils.hash_without_key(attributes, :person)
|
13
|
-
else
|
14
|
-
attributes
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def build_from_attributes(attributes)
|
21
|
-
attributes_dup = attributes.dup
|
22
|
-
|
23
|
-
if Hash === attributes_dup[:person]
|
24
|
-
attributes_dup[:person] = Person.new(attributes_dup.delete(:person))
|
25
|
-
end
|
26
|
-
|
27
|
-
super(attributes_dup)
|
28
|
-
end
|
29
10
|
end
|
30
11
|
end
|
data/lib/delighted/utils.rb
CHANGED
data/lib/delighted/version.rb
CHANGED
data/test/delighted_test.rb
CHANGED
@@ -97,6 +97,22 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
97
97
|
assert_equal '456', survey_response.id
|
98
98
|
end
|
99
99
|
|
100
|
+
def test_retrieving_a_survey_response_expand_person
|
101
|
+
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456?expand%5B%5D=person")
|
102
|
+
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
103
|
+
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => { :id => '123', :email => 'foo@bar.com' }, :score => 10 }))
|
104
|
+
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
|
105
|
+
|
106
|
+
survey_response = Delighted::SurveyResponse.retrieve('456', :expand => ['person'])
|
107
|
+
assert_kind_of Delighted::SurveyResponse, survey_response
|
108
|
+
assert_equal({ :person => '123', :score => 10 }, survey_response.to_hash)
|
109
|
+
assert_kind_of Delighted::Person, survey_response.person
|
110
|
+
assert_equal '123', survey_response.person.id
|
111
|
+
assert_equal({ :email => 'foo@bar.com' }, survey_response.person.to_hash)
|
112
|
+
assert_equal 10, survey_response.score
|
113
|
+
assert_equal '456', survey_response.id
|
114
|
+
end
|
115
|
+
|
100
116
|
def test_updating_a_survey_response
|
101
117
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456")
|
102
118
|
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
@@ -141,13 +157,13 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
141
157
|
survey_responses = Delighted::SurveyResponse.all(:expand => ['person'])
|
142
158
|
assert_kind_of Delighted::EnumerableResourceCollection, survey_responses
|
143
159
|
assert_kind_of Delighted::SurveyResponse, survey_responses[0]
|
144
|
-
assert_equal({ :comment => 'One' }, survey_responses[0].to_hash)
|
160
|
+
assert_equal({ :person => '123', :comment => 'One' }, survey_responses[0].to_hash)
|
145
161
|
assert_equal 'One', survey_responses[0].comment
|
146
162
|
assert_equal '123', survey_responses[0].id
|
147
163
|
assert_kind_of Delighted::Person, survey_responses[0].person
|
148
164
|
assert_equal({ :email => 'foo@bar.com' }, survey_responses[0].person.to_hash)
|
149
165
|
assert_kind_of Delighted::SurveyResponse, survey_responses[1]
|
150
|
-
assert_equal({ :comment => 'Two' }, survey_responses[1].to_hash)
|
166
|
+
assert_equal({ :person => '123', :comment => 'Two' }, survey_responses[1].to_hash)
|
151
167
|
assert_equal 'Two', survey_responses[1].comment
|
152
168
|
assert_equal '456', survey_responses[1].id
|
153
169
|
assert_kind_of Delighted::Person, survey_responses[1].person
|
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.0.
|
4
|
+
version: 1.4.0.rc2
|
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-07-
|
11
|
+
date: 2014-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|