active_rest_client 0.9.58

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.simplecov +4 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +585 -0
  9. data/Rakefile +3 -0
  10. data/active_rest_client.gemspec +34 -0
  11. data/lib/active_rest_client.rb +23 -0
  12. data/lib/active_rest_client/base.rb +128 -0
  13. data/lib/active_rest_client/caching.rb +84 -0
  14. data/lib/active_rest_client/configuration.rb +69 -0
  15. data/lib/active_rest_client/connection.rb +76 -0
  16. data/lib/active_rest_client/connection_manager.rb +21 -0
  17. data/lib/active_rest_client/headers_list.rb +47 -0
  18. data/lib/active_rest_client/instrumentation.rb +62 -0
  19. data/lib/active_rest_client/lazy_association_loader.rb +95 -0
  20. data/lib/active_rest_client/lazy_loader.rb +23 -0
  21. data/lib/active_rest_client/logger.rb +67 -0
  22. data/lib/active_rest_client/mapping.rb +65 -0
  23. data/lib/active_rest_client/proxy_base.rb +143 -0
  24. data/lib/active_rest_client/recording.rb +24 -0
  25. data/lib/active_rest_client/request.rb +412 -0
  26. data/lib/active_rest_client/request_filtering.rb +52 -0
  27. data/lib/active_rest_client/result_iterator.rb +66 -0
  28. data/lib/active_rest_client/validation.rb +60 -0
  29. data/lib/active_rest_client/version.rb +3 -0
  30. data/spec/lib/base_spec.rb +245 -0
  31. data/spec/lib/caching_spec.rb +179 -0
  32. data/spec/lib/configuration_spec.rb +105 -0
  33. data/spec/lib/connection_manager_spec.rb +36 -0
  34. data/spec/lib/connection_spec.rb +73 -0
  35. data/spec/lib/headers_list_spec.rb +61 -0
  36. data/spec/lib/instrumentation_spec.rb +59 -0
  37. data/spec/lib/lazy_association_loader_spec.rb +118 -0
  38. data/spec/lib/lazy_loader_spec.rb +25 -0
  39. data/spec/lib/logger_spec.rb +63 -0
  40. data/spec/lib/mapping_spec.rb +48 -0
  41. data/spec/lib/proxy_spec.rb +154 -0
  42. data/spec/lib/recording_spec.rb +34 -0
  43. data/spec/lib/request_filtering_spec.rb +72 -0
  44. data/spec/lib/request_spec.rb +471 -0
  45. data/spec/lib/result_iterator_spec.rb +104 -0
  46. data/spec/lib/validation_spec.rb +113 -0
  47. data/spec/spec_helper.rb +22 -0
  48. metadata +265 -0
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveRestClient::ResultIterator do
4
+ it "should be able to have a status set during creation" do
5
+ result = ActiveRestClient::ResultIterator.new(200)
6
+ expect(result._status).to eq(200)
7
+ end
8
+
9
+ it "should be able to have a status set after creation" do
10
+ result = ActiveRestClient::ResultIterator.new
11
+ result._status = 200
12
+ expect(result._status).to eq(200)
13
+ end
14
+
15
+ it "should remember objects given to it" do
16
+ result = ActiveRestClient::ResultIterator.new
17
+ result << "a"
18
+ result.each do |element|
19
+ expect(element).to eq("a")
20
+ end
21
+ end
22
+
23
+ it "should implement first" do
24
+ result = ActiveRestClient::ResultIterator.new
25
+ result << "a"
26
+ result << "z"
27
+ expect(result.first).to eq("a")
28
+ end
29
+
30
+ it "should implement any?" do
31
+ result = ActiveRestClient::ResultIterator.new
32
+ expect(result.any?).to be_false
33
+ result << "a"
34
+ expect(result.any?).to be_true
35
+ end
36
+
37
+ it "should implement items" do
38
+ result = ActiveRestClient::ResultIterator.new
39
+ result << "a"
40
+ result << "ab"
41
+ expect(result.items).to eq(["a","ab"])
42
+ end
43
+
44
+ it "should implement last" do
45
+ result = ActiveRestClient::ResultIterator.new
46
+ result << "a"
47
+ result << "z"
48
+ expect(result.last).to eq("z")
49
+ end
50
+
51
+ it "should implement size" do
52
+ result = ActiveRestClient::ResultIterator.new
53
+ result << "a"
54
+ result << "z"
55
+ expect(result.size).to eq(2)
56
+ end
57
+
58
+ it "should implement index" do
59
+ result = ActiveRestClient::ResultIterator.new
60
+ result << "a"
61
+ result << "z"
62
+ expect(result.index("z")).to eq(1)
63
+ end
64
+
65
+ it "should implement empty?" do
66
+ result = ActiveRestClient::ResultIterator.new
67
+ expect(result.empty?).to be_true
68
+ result << "a"
69
+ result << "z"
70
+ expect(result.empty?).to be_false
71
+ end
72
+
73
+ it "should implement direct index access" do
74
+ result = ActiveRestClient::ResultIterator.new
75
+ result << "a"
76
+ result << "z"
77
+ expect(result[0]).to eq("a")
78
+ expect(result[1]).to eq("z")
79
+ end
80
+
81
+ it "should implement shuffle" do
82
+ result = ActiveRestClient::ResultIterator.new
83
+ 100.times do |n|
84
+ result << n
85
+ end
86
+ expect(result.shuffle.first == result.shuffle.first && result.shuffle.first == result.shuffle.first).to_not be_true
87
+ end
88
+
89
+ it "can parallelise calls to each item" do
90
+ result = ActiveRestClient::ResultIterator.new
91
+ result << 3
92
+ result << 2
93
+ result << 1
94
+ delay = 0.05
95
+ start_time = Time.now
96
+ response = result.parallelise do |item|
97
+ sleep(delay * item)
98
+ item*2
99
+ end
100
+ end_time = Time.now
101
+ expect(end_time-start_time).to be < (4*delay)
102
+ expect(response).to eq([6,4,2])
103
+ end
104
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ActiveRestClient::Validation" do
4
+ class SimpleValidationExample < OpenStruct
5
+ include ActiveRestClient::Validation
6
+ validates :first_name, presence:true
7
+ validates :password, length:{within:6..12}
8
+ validates :post_code, length:{minimum:6, maximum:8}
9
+ validates :salary, numericality:true, minimum:20_000, maximum:50_000
10
+ end
11
+
12
+ it "should be able to register a validation" do
13
+ expect(SimpleValidationExample._validations.size).to eq(4)
14
+ end
15
+
16
+ it "should be invalid if a required value isn't present" do
17
+ a = SimpleValidationExample.new
18
+ a.first_name = nil
19
+ a.valid?
20
+ expect(a.errors[:first_name].size).to eq(1)
21
+ end
22
+
23
+ it "should be valid if a required value is present" do
24
+ a = SimpleValidationExample.new
25
+ a.first_name = "John"
26
+ a.valid?
27
+ expect(a.errors[:first_name]).to be_empty
28
+ end
29
+
30
+ it "should be invalid if a length within value is outside the range" do
31
+ a = SimpleValidationExample.new(password:"12345")
32
+ a.valid?
33
+ expect(a.errors[:password].size).to eq(1)
34
+ end
35
+
36
+ it "should be valid if a length within value is inside the range" do
37
+ a = SimpleValidationExample.new(password:"123456")
38
+ a.valid?
39
+ expect(a.errors[:password].size).to eq(0)
40
+ end
41
+
42
+ it "should be invalid if a length is below the minimum" do
43
+ a = SimpleValidationExample.new(post_code:"12345")
44
+ a.valid?
45
+ expect(a.errors[:post_code].size).to eq(1)
46
+ end
47
+
48
+ it "should be valid if a length is above or equal to the minimum and below the maximum" do
49
+ a = SimpleValidationExample.new(post_code:"123456")
50
+ a.valid?
51
+ expect(a.errors[:post_code].size).to eq(0)
52
+ end
53
+
54
+ it "should be invalid if a length is above the maximum" do
55
+ a = SimpleValidationExample.new(post_code:"123456789")
56
+ a.valid?
57
+ expect(a.errors[:post_code].size).to eq(1)
58
+ end
59
+
60
+ it "should be able to validate that a field is numeric" do
61
+ a = SimpleValidationExample.new(salary:"Bob")
62
+ a.valid?
63
+ expect(a.errors[:salary].size).to be > 0
64
+ end
65
+
66
+ it "should be able to validate that a numeric field is above or equal to a minimum" do
67
+ a = SimpleValidationExample.new(salary:10_000)
68
+ a.valid?
69
+ expect(a.errors[:salary].size).to be > 0
70
+ end
71
+
72
+ it "should be able to validate that a numeric field is above or equal to a minimum" do
73
+ a = SimpleValidationExample.new(salary:100_000)
74
+ a.valid?
75
+ expect(a.errors[:salary].size).to be > 0
76
+ end
77
+
78
+ it "should be invalid when a block adds an error" do
79
+ class ValidationExample1 < OpenStruct
80
+ include ActiveRestClient::Validation
81
+ validates :first_name do |object, name, value|
82
+ object.errors[name] << "must be over 4 chars long" if value.length <= 4
83
+ end
84
+ end
85
+ a = ValidationExample1.new(first_name:"John")
86
+ a.valid?
87
+ expect(a.errors[:first_name].size).to eq(1)
88
+ end
89
+
90
+ it "should be valid when a block doesn't add an error" do
91
+ class ValidationExample2 < OpenStruct
92
+ include ActiveRestClient::Validation
93
+ validates :first_name do |object, name, value|
94
+ object.errors[name] << "must be over 4 chars long" if value.length <= 4
95
+ end
96
+ end
97
+ a = ValidationExample2.new(first_name:"Johnny")
98
+ a.valid?
99
+ expect(a.errors[:first_name]).to be_empty
100
+ end
101
+
102
+ it "should call valid? before making a request" do
103
+ class ValidationExample3 < ActiveRestClient::Base
104
+ whiny_missing true
105
+ post :create, '/'
106
+ validates :name, presence:true
107
+ end
108
+
109
+ ValidationExample3.any_instance.should_receive(:valid?)
110
+ object = ValidationExample3.new
111
+ expect { object.create }.to raise_exception(ActiveRestClient::ValidationFailedException)
112
+ end
113
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ require 'active_rest_client'
4
+ require "ostruct"
5
+
6
+ if ENV["JENKINS"]
7
+ require 'simplecov-rcov'
8
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.color_enabled = true
13
+ # config.formatter = 'documentation'
14
+
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,265 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_rest_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.58
5
+ platform: ruby
6
+ authors:
7
+ - Andy Jeffries
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-rcov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: terminal-notifier-guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: oj
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.1.4
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.1.4
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: patron
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.4.9
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.4.9
167
+ description: Accessing REST services in an ActiveRecord style
168
+ email:
169
+ - andy.jeffries@which.co.uk
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".simplecov"
177
+ - Gemfile
178
+ - Guardfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - active_rest_client.gemspec
183
+ - lib/active_rest_client.rb
184
+ - lib/active_rest_client/base.rb
185
+ - lib/active_rest_client/caching.rb
186
+ - lib/active_rest_client/configuration.rb
187
+ - lib/active_rest_client/connection.rb
188
+ - lib/active_rest_client/connection_manager.rb
189
+ - lib/active_rest_client/headers_list.rb
190
+ - lib/active_rest_client/instrumentation.rb
191
+ - lib/active_rest_client/lazy_association_loader.rb
192
+ - lib/active_rest_client/lazy_loader.rb
193
+ - lib/active_rest_client/logger.rb
194
+ - lib/active_rest_client/mapping.rb
195
+ - lib/active_rest_client/proxy_base.rb
196
+ - lib/active_rest_client/recording.rb
197
+ - lib/active_rest_client/request.rb
198
+ - lib/active_rest_client/request_filtering.rb
199
+ - lib/active_rest_client/result_iterator.rb
200
+ - lib/active_rest_client/validation.rb
201
+ - lib/active_rest_client/version.rb
202
+ - spec/lib/base_spec.rb
203
+ - spec/lib/caching_spec.rb
204
+ - spec/lib/configuration_spec.rb
205
+ - spec/lib/connection_manager_spec.rb
206
+ - spec/lib/connection_spec.rb
207
+ - spec/lib/headers_list_spec.rb
208
+ - spec/lib/instrumentation_spec.rb
209
+ - spec/lib/lazy_association_loader_spec.rb
210
+ - spec/lib/lazy_loader_spec.rb
211
+ - spec/lib/logger_spec.rb
212
+ - spec/lib/mapping_spec.rb
213
+ - spec/lib/proxy_spec.rb
214
+ - spec/lib/recording_spec.rb
215
+ - spec/lib/request_filtering_spec.rb
216
+ - spec/lib/request_spec.rb
217
+ - spec/lib/result_iterator_spec.rb
218
+ - spec/lib/validation_spec.rb
219
+ - spec/spec_helper.rb
220
+ homepage: http://www.which.co.uk/
221
+ licenses:
222
+ - MIT
223
+ metadata: {}
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.2.0
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: This gem is for accessing REST services in an ActiveRecord style. ActiveResource
244
+ already exists for this, but it doesn't work where the resource naming doesn't follow
245
+ Rails conventions, it doesn't have in-built caching and it's not as flexible in
246
+ general.
247
+ test_files:
248
+ - spec/lib/base_spec.rb
249
+ - spec/lib/caching_spec.rb
250
+ - spec/lib/configuration_spec.rb
251
+ - spec/lib/connection_manager_spec.rb
252
+ - spec/lib/connection_spec.rb
253
+ - spec/lib/headers_list_spec.rb
254
+ - spec/lib/instrumentation_spec.rb
255
+ - spec/lib/lazy_association_loader_spec.rb
256
+ - spec/lib/lazy_loader_spec.rb
257
+ - spec/lib/logger_spec.rb
258
+ - spec/lib/mapping_spec.rb
259
+ - spec/lib/proxy_spec.rb
260
+ - spec/lib/recording_spec.rb
261
+ - spec/lib/request_filtering_spec.rb
262
+ - spec/lib/request_spec.rb
263
+ - spec/lib/result_iterator_spec.rb
264
+ - spec/lib/validation_spec.rb
265
+ - spec/spec_helper.rb