delighted 1.7.0.rc2 → 1.7.0
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/.travis.yml +0 -1
- data/CHANGELOG.md +2 -2
- data/README.md +14 -1
- data/lib/delighted/version.rb +1 -1
- data/test/delighted_test.rb +8 -2
- data/test/support/ordered_hash.rb +192 -0
- data/test/test_helper.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24e928b7535e1d51f72461238850e824b27b3920
|
4
|
+
data.tar.gz: 86001bae9ecc475902d0ce5f2d4ed1cc15d6f686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c62db83772abc00c2a6c1524c8a18f998b953ca227d8f521eaf2a3cb10e7457b078eac3d8d8473668e83c646e8f515a32700435fbc7a59edf715585f87e4eb7
|
7
|
+
data.tar.gz: 0cfa475365360aa17f5e7b81c215e07607eed6d10f867ba5269ef840c62aa88ca032944d613d11d7159b224593cbf0e2b67282aa1da5acdcad9621a7a99904fe
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -153,6 +153,20 @@ metrics = Delighted::Metrics.retrieve(:since => Time.utc(2013, 10, 01),
|
|
153
153
|
:until => Time.utc(2013, 11, 01))
|
154
154
|
```
|
155
155
|
|
156
|
+
## Rate limits
|
157
|
+
|
158
|
+
If a request is rate limited, a `Delighted::RateLimitedError` exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a `#retry_after` method to tell you how many seconds you should wait before retrying. For example:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
begin
|
162
|
+
metrics = Delighted::Metrics.retrieve
|
163
|
+
rescue Delighted::RateLimitedError => e
|
164
|
+
retry_after_seconds = e.retry_after
|
165
|
+
# wait for retry_after_seconds before retrying
|
166
|
+
# add your retry strategy here ...
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
156
170
|
## <a name="advanced-configuration"></a> Advanced configuration & testing
|
157
171
|
|
158
172
|
The following options are configurable for the client:
|
@@ -183,7 +197,6 @@ metrics_from_custom_shared_client = Delighted::Metrics.retrieve
|
|
183
197
|
|
184
198
|
- Ruby MRI (1.8.7+)
|
185
199
|
- JRuby (1.8 + 1.9 modes)
|
186
|
-
- RBX (2.1.1)
|
187
200
|
- REE (1.8.7-2012.02)
|
188
201
|
|
189
202
|
## Contributing
|
data/lib/delighted/version.rb
CHANGED
data/test/delighted_test.rb
CHANGED
@@ -86,7 +86,10 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
86
86
|
def test_creating_a_survey_response
|
87
87
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses")
|
88
88
|
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
89
|
-
data =
|
89
|
+
data = OrderedHash.new
|
90
|
+
data[:person] = '123'
|
91
|
+
data[:score] = 10
|
92
|
+
data = Delighted::JSON.dump(data)
|
90
93
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => '123', :score => 10 }))
|
91
94
|
mock_http_adapter.expects(:request).with(:post, uri, headers, data).once.returns(response)
|
92
95
|
|
@@ -131,7 +134,10 @@ class Delighted::SurveyResponseTest < Delighted::TestCase
|
|
131
134
|
def test_updating_a_survey_response
|
132
135
|
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456")
|
133
136
|
headers = { 'Authorization' => @auth_header, "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
|
134
|
-
data =
|
137
|
+
data = OrderedHash.new
|
138
|
+
data[:person] = '123'
|
139
|
+
data[:score] = 10
|
140
|
+
data = Delighted::JSON.dump(data)
|
135
141
|
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => '123', :score => 10 }))
|
136
142
|
mock_http_adapter.expects(:request).with(:put, uri, headers, data).once.returns(response)
|
137
143
|
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# From https://raw.githubusercontent.com/rails/rails/3-0-stable/activesupport/lib/active_support/ordered_hash.rb
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'psych'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
YAML.add_builtin_type("omap") do |type, val|
|
11
|
+
OrderedHash[val.map(&:to_a).map(&:first)]
|
12
|
+
end
|
13
|
+
|
14
|
+
# OrderedHash is namespaced to prevent conflicts with other implementations
|
15
|
+
class OrderedHash < ::Hash #:nodoc:
|
16
|
+
def to_yaml_type
|
17
|
+
"!tag:yaml.org,2002:omap"
|
18
|
+
end
|
19
|
+
|
20
|
+
def encode_with(coder)
|
21
|
+
coder.represent_seq '!omap', map { |k,v| { k => v } }
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_yaml(opts = {})
|
25
|
+
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
|
26
|
+
return super
|
27
|
+
end
|
28
|
+
|
29
|
+
YAML.quick_emit(self, opts) do |out|
|
30
|
+
out.seq(taguri) do |seq|
|
31
|
+
each do |k, v|
|
32
|
+
seq.add(k => v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Hash is ordered in Ruby 1.9!
|
39
|
+
if RUBY_VERSION < '1.9'
|
40
|
+
|
41
|
+
# In MRI the Hash class is core and written in C. In particular, methods are
|
42
|
+
# programmed with explicit C function calls and polymorphism is not honored.
|
43
|
+
#
|
44
|
+
# For example, []= is crucial in this implementation to maintain the @keys
|
45
|
+
# array but hash.c invokes rb_hash_aset() originally. This prevents method
|
46
|
+
# reuse through inheritance and forces us to reimplement stuff.
|
47
|
+
#
|
48
|
+
# For instance, we cannot use the inherited #merge! because albeit the algorithm
|
49
|
+
# itself would work, our []= is not being called at all by the C code.
|
50
|
+
|
51
|
+
def initialize(*args, &block)
|
52
|
+
super
|
53
|
+
@keys = []
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.[](*args)
|
57
|
+
ordered_hash = new
|
58
|
+
|
59
|
+
if (args.length == 1 && args.first.is_a?(Array))
|
60
|
+
args.first.each do |key_value_pair|
|
61
|
+
next unless (key_value_pair.is_a?(Array))
|
62
|
+
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
63
|
+
end
|
64
|
+
|
65
|
+
return ordered_hash
|
66
|
+
end
|
67
|
+
|
68
|
+
unless (args.size % 2 == 0)
|
69
|
+
raise ArgumentError.new("odd number of arguments for Hash")
|
70
|
+
end
|
71
|
+
|
72
|
+
args.each_with_index do |val, ind|
|
73
|
+
next if (ind % 2 != 0)
|
74
|
+
ordered_hash[val] = args[ind + 1]
|
75
|
+
end
|
76
|
+
|
77
|
+
ordered_hash
|
78
|
+
end
|
79
|
+
|
80
|
+
def initialize_copy(other)
|
81
|
+
super
|
82
|
+
# make a deep copy of keys
|
83
|
+
@keys = other.keys
|
84
|
+
end
|
85
|
+
|
86
|
+
def []=(key, value)
|
87
|
+
@keys << key if !has_key?(key)
|
88
|
+
super
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete(key)
|
92
|
+
if has_key? key
|
93
|
+
index = @keys.index(key)
|
94
|
+
@keys.delete_at index
|
95
|
+
end
|
96
|
+
super
|
97
|
+
end
|
98
|
+
|
99
|
+
def delete_if
|
100
|
+
super
|
101
|
+
sync_keys!
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
def reject!
|
106
|
+
super
|
107
|
+
sync_keys!
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
def reject(&block)
|
112
|
+
dup.reject!(&block)
|
113
|
+
end
|
114
|
+
|
115
|
+
def keys
|
116
|
+
@keys.dup
|
117
|
+
end
|
118
|
+
|
119
|
+
def values
|
120
|
+
@keys.collect { |key| self[key] }
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_hash
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_a
|
128
|
+
@keys.map { |key| [ key, self[key] ] }
|
129
|
+
end
|
130
|
+
|
131
|
+
def each_key
|
132
|
+
@keys.each { |key| yield key }
|
133
|
+
end
|
134
|
+
|
135
|
+
def each_value
|
136
|
+
@keys.each { |key| yield self[key]}
|
137
|
+
end
|
138
|
+
|
139
|
+
def each
|
140
|
+
@keys.each {|key| yield [key, self[key]]}
|
141
|
+
end
|
142
|
+
|
143
|
+
alias_method :each_pair, :each
|
144
|
+
|
145
|
+
def clear
|
146
|
+
super
|
147
|
+
@keys.clear
|
148
|
+
self
|
149
|
+
end
|
150
|
+
|
151
|
+
def shift
|
152
|
+
k = @keys.first
|
153
|
+
v = delete(k)
|
154
|
+
[k, v]
|
155
|
+
end
|
156
|
+
|
157
|
+
def merge!(other_hash)
|
158
|
+
if block_given?
|
159
|
+
other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
|
160
|
+
else
|
161
|
+
other_hash.each { |k, v| self[k] = v }
|
162
|
+
end
|
163
|
+
self
|
164
|
+
end
|
165
|
+
|
166
|
+
alias_method :update, :merge!
|
167
|
+
|
168
|
+
def merge(other_hash, &block)
|
169
|
+
dup.merge!(other_hash, &block)
|
170
|
+
end
|
171
|
+
|
172
|
+
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
|
173
|
+
def replace(other)
|
174
|
+
super
|
175
|
+
@keys = other.keys
|
176
|
+
self
|
177
|
+
end
|
178
|
+
|
179
|
+
def invert
|
180
|
+
OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
|
181
|
+
end
|
182
|
+
|
183
|
+
def inspect
|
184
|
+
"#<OrderedHash #{super}>"
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
def sync_keys!
|
189
|
+
@keys.delete_if {|k| !has_key?(k)}
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
data/test/test_helper.rb
CHANGED
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.7.0
|
4
|
+
version: 1.7.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: 2017-10-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/delighted/utils.rb
|
103
103
|
- lib/delighted/version.rb
|
104
104
|
- test/delighted_test.rb
|
105
|
+
- test/support/ordered_hash.rb
|
105
106
|
- test/test_helper.rb
|
106
107
|
homepage: https://github.com/delighted/delighted-ruby
|
107
108
|
licenses:
|
@@ -118,9 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
121
|
requirements:
|
121
|
-
- - "
|
122
|
+
- - ">="
|
122
123
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
124
|
+
version: '0'
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
127
|
rubygems_version: 2.6.13
|
@@ -130,4 +131,5 @@ summary: Delighted is the fastest and easiest way to gather actionable feedback
|
|
130
131
|
your customers.
|
131
132
|
test_files:
|
132
133
|
- test/delighted_test.rb
|
134
|
+
- test/support/ordered_hash.rb
|
133
135
|
- test/test_helper.rb
|