delighted 1.3.1 → 1.4.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: 37805cf1e7b0836ab7a522aa3e886cc2c82cb0f4
4
- data.tar.gz: bb1dc6a443bc57aa8784f91dfc75d95d07326b7a
3
+ metadata.gz: d8beec1cb9744f320e1fc4f9616446777b36310f
4
+ data.tar.gz: 119d1aa1d03033a91984a59408d430a6bf45688b
5
5
  SHA512:
6
- metadata.gz: 3e5aecf2f1cbb700dc8acb92232e754384809681817450e73a69a6ea2eac219957d112e350e1e0ac6305d0f04ad79fccce921688d1e94d75f4eeb74d03ad48a2
7
- data.tar.gz: 265dfdeed0e7d351bf21f44dde3d6416ca725b4917eb43ed1334a10466b7af808c0ab5522318c6eaf755422d3e8d42a7e2c375e39f65d504c7910fd0ad4fd909
6
+ metadata.gz: 108ff82e7a3c7f4be0ade2b17d6319d197038952c169b2ad779cf729726944d0557cebea63d5a4c2c04d22dcadb9297cafd5cfb173742f1e30d6e4f1396dc2af
7
+ data.tar.gz: 72efad36ac7309e3f232309badfdc1cb2ce81d66c59b0cfc3dbe51ca11e7cc850f0d3a09c77a9bb048fa598fe00308b5c76d08288830704625f9d3dc7d89d597
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
- ## 1.3.1 (2015-09-14)
1
+ ## 1.4.0 (Unreleased)
2
2
 
3
3
  Features:
4
4
 
5
- - Fix authentication header on 1.8.7
5
+ - Add support for retrieving a SurveyResponse
6
+ - Add support for updating a SurveyResponse
6
7
 
7
8
  ## 1.3.0 (2014-06-03)
8
9
 
data/USAGE.md CHANGED
@@ -65,6 +65,30 @@ survey_response2 = Delighted::SurveyResponse.create(:person => person1.id, :scor
65
65
  :comment => "Really nice.")
66
66
  ```
67
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
+
68
92
  ### Listing survey responses
69
93
 
70
94
  ```ruby
data/lib/delighted.rb CHANGED
@@ -14,6 +14,7 @@ require 'delighted/resource'
14
14
  require 'delighted/operations/all'
15
15
  require 'delighted/operations/create'
16
16
  require 'delighted/operations/retrieve'
17
+ require 'delighted/operations/update'
17
18
 
18
19
  require 'delighted/resources/metrics'
19
20
  require 'delighted/resources/person'
@@ -29,6 +29,16 @@ module Delighted
29
29
  handle_json_response(response)
30
30
  end
31
31
 
32
+ def put_json(path, params = {})
33
+ headers = default_headers.dup.merge('Accept' => 'application/json', 'Content-Type' => 'application/json')
34
+
35
+ uri = URI.parse(File.join(@api_base_url, path))
36
+ data = JSON.dump(params) unless params.empty?
37
+
38
+ response = @http_adapter.request(:put, uri, headers, data)
39
+ handle_json_response(response)
40
+ end
41
+
32
42
  def delete_json(path, params = {})
33
43
  headers = default_headers.dup.merge('Accept' => 'application/json', 'Content-Type' => 'application/json')
34
44
 
@@ -60,7 +70,7 @@ module Delighted
60
70
 
61
71
  def default_headers
62
72
  @default_headers ||= {
63
- 'Authorization' => "Basic #{["#{@api_key}:"].pack('m').chomp}",
73
+ 'Authorization' => "Basic #{["#{@api_key}:"].pack('m0')}",
64
74
  'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}"
65
75
  }.freeze
66
76
  end
@@ -0,0 +1,26 @@
1
+ module Delighted
2
+ module Operations
3
+ module Update
4
+ def self.included(klass)
5
+ unless klass.singleton_resource?
6
+ klass.extend(Pluralton::ClassMethods)
7
+ end
8
+ end
9
+
10
+ def save(client = Delighted.shared_client)
11
+ params = Utils.hash_without_key(attributes, :id)
12
+ params = Utils.serialize_values(params)
13
+ json = client.put_json(self.class.path(id), params)
14
+ self.class.new(json)
15
+ end
16
+
17
+ module Pluralton
18
+ module ClassMethods
19
+ def path(id = nil)
20
+ id ? "#{@path}/#{id}" : @path
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -54,6 +54,10 @@ module Delighted
54
54
  define_method(key) do
55
55
  attributes[key]
56
56
  end
57
+
58
+ define_method("#{key}=") do |value|
59
+ attributes[key] = value
60
+ end
57
61
  end
58
62
  end
59
63
  end
@@ -4,6 +4,8 @@ module Delighted
4
4
 
5
5
  include Operations::Create
6
6
  include Operations::All
7
+ include Operations::Update
8
+ include Operations::Retrieve
7
9
 
8
10
  def to_hash
9
11
  if Person === attributes[:person]
@@ -1,3 +1,3 @@
1
1
  module Delighted
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0.rc1"
3
3
  end
@@ -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' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
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' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
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 @@ 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' => @auth_header,
44
+ 'Authorization' => "Basic #{["123abc:"].pack('m0')}",
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' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
60
+ headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "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' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
73
+ headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "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)
@@ -83,9 +83,40 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
83
83
  assert_equal '456', survey_response.id
84
84
  end
85
85
 
86
+ def test_retrieving_a_survey_response
87
+ uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456")
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 => '456', :person => '123', :score => 10 }))
90
+ mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
91
+
92
+ survey_response = Delighted::SurveyResponse.retrieve('456')
93
+ assert_kind_of Delighted::SurveyResponse, survey_response
94
+ assert_equal({ :person => '123', :score => 10 }, survey_response.to_hash)
95
+ assert_equal '123', survey_response.person
96
+ assert_equal 10, survey_response.score
97
+ assert_equal '456', survey_response.id
98
+ end
99
+
100
+ def test_updating_a_survey_response
101
+ uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456")
102
+ headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
103
+ data = Delighted::JSON.dump({ :person => '123', :score => 10 })
104
+ response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => '123', :score => 10 }))
105
+ mock_http_adapter.expects(:request).with(:put, uri, headers, data).once.returns(response)
106
+
107
+ survey_response = Delighted::SurveyResponse.new(:id => '456', :person => '321', :score => 1)
108
+ survey_response.person = '123'
109
+ survey_response.score = 10
110
+ assert_kind_of Delighted::SurveyResponse, survey_response.save
111
+ assert_equal({ :person => '123', :score => 10 }, survey_response.to_hash)
112
+ assert_equal '123', survey_response.person
113
+ assert_equal 10, survey_response.score
114
+ assert_equal '456', survey_response.id
115
+ end
116
+
86
117
  def test_listing_all_survey_responses
87
118
  uri = URI.parse("https://api.delightedapp.com/v1/survey_responses?order=desc")
88
- headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
119
+ headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
89
120
  response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump([{ :id => '123', :comment => 'One' }, { :id => '456', :comment => 'Two' }]))
90
121
  mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
91
122
 
@@ -103,7 +134,7 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
103
134
 
104
135
  def test_listing_all_survey_responses_expand_person
105
136
  uri = URI.parse("https://api.delightedapp.com/v1/survey_responses?expand%5B%5D=person")
106
- headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
137
+ headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
107
138
  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' } }]))
108
139
  mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)
109
140
 
data/test/test_helper.rb CHANGED
@@ -8,7 +8,6 @@ class Delighted::TestCase < Minitest::Test
8
8
  def setup
9
9
  super
10
10
  Delighted.shared_client = Delighted::Client.new(:api_key => '123abc', :http_adapter => mock_http_adapter)
11
- @auth_header = "Basic #{["123abc:"].pack('m').chomp}"
12
11
  end
13
12
 
14
13
  def mock_http_adapter
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.3.1
4
+ version: 1.4.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: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -92,6 +92,7 @@ files:
92
92
  - lib/delighted/operations/all.rb
93
93
  - lib/delighted/operations/create.rb
94
94
  - lib/delighted/operations/retrieve.rb
95
+ - lib/delighted/operations/update.rb
95
96
  - lib/delighted/resource.rb
96
97
  - lib/delighted/resources/metrics.rb
97
98
  - lib/delighted/resources/person.rb
@@ -117,12 +118,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  requirements:
120
- - - '>='
121
+ - - '>'
121
122
  - !ruby/object:Gem::Version
122
- version: '0'
123
+ version: 1.3.1
123
124
  requirements: []
124
125
  rubyforge_project:
125
- rubygems_version: 2.0.14
126
+ rubygems_version: 2.2.2
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: Delighted is the easiest and most beautiful way to measure customer happiness.