delighted 1.2.0 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a8edfb2d7af0d3cd4ebfbb48ad1871934e57a80
4
- data.tar.gz: a6a42c011ee59d7b2058bba2d639b23b39a11cf2
3
+ metadata.gz: 4d0398185f79509fb4bd2b35e4e25ba8b4b9653d
4
+ data.tar.gz: 25ecde8c4fc548fc4571a8c25244c0930c833e14
5
5
  SHA512:
6
- metadata.gz: a070f88c21c96ebcdd9205f515b893e89220c78040eea67e686a2762e187bc31d20cb6b7392f6923d0d44ed0370c7fb273dc6448d0a3503d452ca483a3c5fd24
7
- data.tar.gz: ea4e20e9d3532b26cd8c0eb5e60722da2a9dae05b70fa3c9862a2871c95aa64a7fd229c8c79e64ae256b8894868e573801b04a2ea8d523e4efcc8b7ead216866
6
+ metadata.gz: 5e8e06cd8ce9df39d61a0257bcd7ba4fa6db2b340917b883921b30bee40a051fd757cdd94fbb70166d27a8afa93daec5da570c2995aa7eaadfe1dfefffbf6681
7
+ data.tar.gz: 913d32f3d9e4fa207c2e40fd314bb85196060302e4c1a457c6b185d99a79a383382e3d3e8147480d04a65ee52d140491601e2dc1aea7a53427151da16c0746cb
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
+ .bundle
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.3.0.rc1 (2014-03-14)
2
+
3
+ Features:
4
+
5
+ - Add support expanding person on SurveyResponses
6
+
1
7
  ## 1.2.0 (2014-02-28)
2
8
 
3
9
  Features:
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))
@@ -25,8 +25,7 @@ module Delighted
25
25
  def initialize(attributes = {})
26
26
  @id = attributes[:id]
27
27
  define_id_reader if @id
28
- @attributes = Utils.hash_without_key(attributes, :id)
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
@@ -12,7 +12,7 @@ module Delighted
12
12
  hash_or_array.map { |object|
13
13
  k, v = case hash_or_array
14
14
  when Hash then object
15
- when Array then [nil, object[0]]
15
+ when Array then [nil, object]
16
16
  else raise ArgumentError, "must pass Hash or Array"
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module Delighted
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0.rc1"
3
3
  end
@@ -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.2.0
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-02-28 00:00:00.000000000 Z
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: '0'
121
+ version: 1.3.1
122
122
  requirements: []
123
123
  rubyforge_project:
124
124
  rubygems_version: 2.2.2