acfs 0.50.0 → 1.0.0.dev.1.b297

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +13 -5
  2. data/CHANGELOG.md +0 -80
  3. data/README.md +9 -8
  4. data/acfs.gemspec +7 -7
  5. data/lib/acfs.rb +5 -7
  6. data/lib/acfs/adapter/base.rb +2 -0
  7. data/lib/acfs/adapter/typhoeus.rb +13 -17
  8. data/lib/acfs/collections/paginatable.rb +10 -10
  9. data/lib/acfs/configuration.rb +5 -4
  10. data/lib/acfs/errors.rb +9 -10
  11. data/lib/acfs/global.rb +7 -16
  12. data/lib/acfs/location.rb +11 -11
  13. data/lib/acfs/middleware/base.rb +2 -1
  14. data/lib/acfs/middleware/json_decoder.rb +16 -0
  15. data/lib/acfs/middleware/json_encoder.rb +20 -0
  16. data/lib/acfs/middleware/logger.rb +2 -0
  17. data/lib/acfs/middleware/msgpack_decoder.rb +26 -0
  18. data/lib/acfs/middleware/msgpack_encoder.rb +19 -0
  19. data/lib/acfs/middleware/print.rb +2 -0
  20. data/lib/acfs/operation.rb +5 -5
  21. data/lib/acfs/request.rb +4 -4
  22. data/lib/acfs/request/callbacks.rb +3 -2
  23. data/lib/acfs/resource.rb +2 -2
  24. data/lib/acfs/resource/attributes.rb +38 -11
  25. data/lib/acfs/resource/attributes/base.rb +19 -10
  26. data/lib/acfs/resource/attributes/boolean.rb +8 -10
  27. data/lib/acfs/resource/attributes/date_time.rb +9 -6
  28. data/lib/acfs/resource/attributes/float.rb +5 -11
  29. data/lib/acfs/resource/attributes/integer.rb +5 -7
  30. data/lib/acfs/resource/attributes/list.rb +6 -13
  31. data/lib/acfs/resource/attributes/string.rb +5 -3
  32. data/lib/acfs/resource/attributes/uuid.rb +17 -8
  33. data/lib/acfs/resource/dirty.rb +15 -3
  34. data/lib/acfs/resource/loadable.rb +1 -0
  35. data/lib/acfs/resource/locatable.rb +4 -0
  36. data/lib/acfs/resource/operational.rb +2 -0
  37. data/lib/acfs/resource/persistence.rb +17 -17
  38. data/lib/acfs/resource/query_methods.rb +7 -8
  39. data/lib/acfs/resource/service.rb +2 -0
  40. data/lib/acfs/resource/validation.rb +4 -4
  41. data/lib/acfs/response.rb +2 -1
  42. data/lib/acfs/response/formats.rb +3 -2
  43. data/lib/acfs/response/status.rb +5 -3
  44. data/lib/acfs/runner.rb +11 -21
  45. data/lib/acfs/service.rb +6 -4
  46. data/lib/acfs/service/middleware.rb +30 -20
  47. data/lib/acfs/singleton_resource.rb +2 -0
  48. data/lib/acfs/stub.rb +21 -30
  49. data/lib/acfs/util.rb +1 -1
  50. data/lib/acfs/version.rb +4 -6
  51. data/spec/acfs/adapter/typhoeus_spec.rb +4 -12
  52. data/spec/acfs/collection_spec.rb +33 -45
  53. data/spec/acfs/configuration_spec.rb +1 -9
  54. data/spec/acfs/global_spec.rb +3 -21
  55. data/spec/acfs/middleware/json_decoder_spec.rb +45 -0
  56. data/spec/acfs/middleware/msgpack_decoder_spec.rb +36 -0
  57. data/spec/acfs/request/callbacks_spec.rb +8 -8
  58. data/spec/acfs/request_spec.rb +5 -5
  59. data/spec/acfs/resource/attributes/boolean_spec.rb +9 -40
  60. data/spec/acfs/resource/attributes/date_time_spec.rb +35 -29
  61. data/spec/acfs/resource/attributes/float_spec.rb +9 -48
  62. data/spec/acfs/resource/attributes/list_spec.rb +19 -43
  63. data/spec/acfs/resource/attributes/uuid_spec.rb +54 -31
  64. data/spec/acfs/resource/attributes_spec.rb +31 -17
  65. data/spec/acfs/resource/locatable_spec.rb +2 -2
  66. data/spec/acfs/resource/persistance_spec.rb +34 -65
  67. data/spec/acfs/resource/query_methods_spec.rb +90 -97
  68. data/spec/acfs/resource/validation_spec.rb +5 -4
  69. data/spec/acfs/response/formats_spec.rb +4 -4
  70. data/spec/acfs/response/status_spec.rb +1 -1
  71. data/spec/acfs/runner_spec.rb +3 -28
  72. data/spec/acfs/service/middleware_spec.rb +20 -4
  73. data/spec/acfs/service_spec.rb +5 -3
  74. data/spec/acfs/singleton_resource_spec.rb +2 -1
  75. data/spec/acfs/stub_spec.rb +22 -137
  76. data/spec/acfs_spec.rb +19 -22
  77. data/spec/spec_helper.rb +2 -3
  78. data/spec/support/service.rb +6 -10
  79. data/spec/support/shared/find_callbacks.rb +7 -7
  80. metadata +36 -43
  81. data/lib/acfs/middleware/json.rb +0 -27
  82. data/lib/acfs/middleware/msgpack.rb +0 -30
  83. data/lib/acfs/middleware/serializer.rb +0 -39
  84. data/lib/acfs/resource/attributes/dict.rb +0 -37
  85. data/lib/acfs/service/middleware/stack.rb +0 -63
  86. data/spec/acfs/middleware/json_spec.rb +0 -63
  87. data/spec/acfs/middleware/msgpack_spec.rb +0 -60
  88. data/spec/acfs/operation_spec.rb +0 -10
  89. data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
  90. data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.0
4
+ version: 1.0.0.dev.1.b297
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: '3.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '4.2'
47
+ version: '3.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '4.2'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: multi_json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: typhoeus
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '1.0'
75
+ version: 0.6.5
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
- version: '1.0'
82
+ version: 0.6.5
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.3'
111
111
  description: API Client For Services
@@ -129,11 +129,12 @@ files:
129
129
  - lib/acfs/global.rb
130
130
  - lib/acfs/location.rb
131
131
  - lib/acfs/middleware/base.rb
132
- - lib/acfs/middleware/json.rb
132
+ - lib/acfs/middleware/json_decoder.rb
133
+ - lib/acfs/middleware/json_encoder.rb
133
134
  - lib/acfs/middleware/logger.rb
134
- - lib/acfs/middleware/msgpack.rb
135
+ - lib/acfs/middleware/msgpack_decoder.rb
136
+ - lib/acfs/middleware/msgpack_encoder.rb
135
137
  - lib/acfs/middleware/print.rb
136
- - lib/acfs/middleware/serializer.rb
137
138
  - lib/acfs/operation.rb
138
139
  - lib/acfs/request.rb
139
140
  - lib/acfs/request/callbacks.rb
@@ -142,7 +143,6 @@ files:
142
143
  - lib/acfs/resource/attributes/base.rb
143
144
  - lib/acfs/resource/attributes/boolean.rb
144
145
  - lib/acfs/resource/attributes/date_time.rb
145
- - lib/acfs/resource/attributes/dict.rb
146
146
  - lib/acfs/resource/attributes/float.rb
147
147
  - lib/acfs/resource/attributes/integer.rb
148
148
  - lib/acfs/resource/attributes/list.rb
@@ -164,7 +164,6 @@ files:
164
164
  - lib/acfs/runner.rb
165
165
  - lib/acfs/service.rb
166
166
  - lib/acfs/service/middleware.rb
167
- - lib/acfs/service/middleware/stack.rb
168
167
  - lib/acfs/singleton_resource.rb
169
168
  - lib/acfs/stub.rb
170
169
  - lib/acfs/util.rb
@@ -174,16 +173,13 @@ files:
174
173
  - spec/acfs/collection_spec.rb
175
174
  - spec/acfs/configuration_spec.rb
176
175
  - spec/acfs/global_spec.rb
177
- - spec/acfs/middleware/json_spec.rb
178
- - spec/acfs/middleware/msgpack_spec.rb
179
- - spec/acfs/operation_spec.rb
176
+ - spec/acfs/middleware/json_decoder_spec.rb
177
+ - spec/acfs/middleware/msgpack_decoder_spec.rb
180
178
  - spec/acfs/request/callbacks_spec.rb
181
179
  - spec/acfs/request_spec.rb
182
180
  - spec/acfs/resource/attributes/boolean_spec.rb
183
181
  - spec/acfs/resource/attributes/date_time_spec.rb
184
- - spec/acfs/resource/attributes/dict_spec.rb
185
182
  - spec/acfs/resource/attributes/float_spec.rb
186
- - spec/acfs/resource/attributes/integer_spec.rb
187
183
  - spec/acfs/resource/attributes/list_spec.rb
188
184
  - spec/acfs/resource/attributes/uuid_spec.rb
189
185
  - spec/acfs/resource/attributes_spec.rb
@@ -218,17 +214,17 @@ require_paths:
218
214
  - lib
219
215
  required_ruby_version: !ruby/object:Gem::Requirement
220
216
  requirements:
221
- - - ">="
217
+ - - ! '>='
222
218
  - !ruby/object:Gem::Version
223
219
  version: '0'
224
220
  required_rubygems_version: !ruby/object:Gem::Requirement
225
221
  requirements:
226
- - - ">="
222
+ - - ! '>'
227
223
  - !ruby/object:Gem::Version
228
- version: '0'
224
+ version: 1.3.1
229
225
  requirements: []
230
226
  rubyforge_project:
231
- rubygems_version: 2.7.3
227
+ rubygems_version: 2.2.2
232
228
  signing_key:
233
229
  specification_version: 4
234
230
  summary: An abstract API base client for service oriented application.
@@ -237,16 +233,13 @@ test_files:
237
233
  - spec/acfs/collection_spec.rb
238
234
  - spec/acfs/configuration_spec.rb
239
235
  - spec/acfs/global_spec.rb
240
- - spec/acfs/middleware/json_spec.rb
241
- - spec/acfs/middleware/msgpack_spec.rb
242
- - spec/acfs/operation_spec.rb
236
+ - spec/acfs/middleware/json_decoder_spec.rb
237
+ - spec/acfs/middleware/msgpack_decoder_spec.rb
243
238
  - spec/acfs/request/callbacks_spec.rb
244
239
  - spec/acfs/request_spec.rb
245
240
  - spec/acfs/resource/attributes/boolean_spec.rb
246
241
  - spec/acfs/resource/attributes/date_time_spec.rb
247
- - spec/acfs/resource/attributes/dict_spec.rb
248
242
  - spec/acfs/resource/attributes/float_spec.rb
249
- - spec/acfs/resource/attributes/integer_spec.rb
250
243
  - spec/acfs/resource/attributes/list_spec.rb
251
244
  - spec/acfs/resource/attributes/uuid_spec.rb
252
245
  - spec/acfs/resource/attributes_spec.rb
@@ -1,27 +0,0 @@
1
- require 'multi_json'
2
-
3
- module Acfs
4
- module Middleware
5
- # A middleware to encore request data using JSON.
6
- #
7
- class JSON < Serializer
8
- def mime
9
- ::Mime[:json]
10
- end
11
-
12
- def encode(data)
13
- ::MultiJson.dump data
14
- end
15
-
16
- def decode(body)
17
- ::MultiJson.load body
18
- end
19
- end
20
-
21
- # @deprecated
22
- JsonDecoder = JSON
23
-
24
- # @deprecated
25
- JsonEncoder = JSON
26
- end
27
- end
@@ -1,30 +0,0 @@
1
- require 'msgpack'
2
- require 'action_dispatch'
3
-
4
- module Acfs
5
- module Middleware
6
- class MessagePack < Serializer
7
- unless defined?(::Mime::MSGPACK)
8
- ::Mime::Type.register 'application/x-msgpack', :msgpack
9
- end
10
-
11
- def mime
12
- ::Mime[:msgpack]
13
- end
14
-
15
- def encode(data)
16
- ::MessagePack.pack data
17
- end
18
-
19
- def decode(body)
20
- ::MessagePack.unpack body
21
- end
22
- end
23
-
24
- # @deprecated
25
- MessagePackEncoder = MessagePack
26
-
27
- # @deprecated
28
- MessagePackDecoder = MessagePack
29
- end
30
- end
@@ -1,39 +0,0 @@
1
- module Acfs
2
- module Middleware
3
- # A base middleware that does not modify request or response.
4
- # Can be used as super class for custom middleware implementations.
5
- #
6
- class Serializer < Base
7
- def encode(_data)
8
- raise NotImplementedError
9
- end
10
-
11
- def decode(_data)
12
- raise NotImplementedError
13
- end
14
-
15
- def mime
16
- raise NotImplementedError
17
- end
18
-
19
- def call(request)
20
- unless request.headers['Content-Type']
21
- request.body = encode request.data
22
- request.headers['Content-Type'] = mime
23
- end
24
-
25
- accept = request.headers['Accept'].to_s.split(',')
26
- accept << "#{mime};q=#{options.fetch(:q, 1)}"
27
- request.headers['Accept'] = accept.join(',')
28
-
29
- request.on_complete do |response, nxt|
30
- response.data = decode response.body if mime == response.content_type
31
-
32
- nxt.call response
33
- end
34
-
35
- app.call(request)
36
- end
37
- end
38
- end
39
- end
@@ -1,37 +0,0 @@
1
- module Acfs::Resource::Attributes
2
- # @api public
3
- #
4
- # Dict attribute type. Use it in your model as an attribute type:
5
- #
6
- # @example
7
- # class User
8
- # include Acfs::Model
9
- # attribute :opts, :dict
10
- # end
11
- #
12
- class Dict < Base
13
- # @api public
14
- #
15
- # Cast given object to a dict/hash.
16
- #
17
- # @param [Object] value Object to cast.
18
- # @return [Hash] Casted object as hash.
19
- # @raise [TypeError] If object cannot be casted to a hash.
20
- #
21
- def cast_value(value)
22
- return {} if value.blank?
23
-
24
- if value.is_a?(Hash)
25
- value
26
- elsif value.respond_to?(:serializable_hash)
27
- value.serializable_hash
28
- elsif value.respond_to?(:to_hash)
29
- value.to_hash
30
- elsif value.respond_to?(:to_h)
31
- value.to_h
32
- else
33
- Hash(value)
34
- end
35
- end
36
- end
37
- end
@@ -1,63 +0,0 @@
1
- module Acfs
2
- class Service
3
- module Middleware
4
- class Stack
5
- include Enumerable
6
-
7
- MUTEX = Mutex.new
8
- IDENTITY = -> (i) { i }
9
-
10
- attr_reader :middlewares
11
-
12
- def initialize
13
- @middlewares = []
14
- end
15
-
16
- def call(request)
17
- build! unless @app
18
-
19
- @app.call request
20
- end
21
-
22
- def build!
23
- return if @app
24
-
25
- MUTEX.synchronize do
26
- return if @app
27
-
28
- @app = build
29
- end
30
- end
31
-
32
- def build(app = IDENTITY)
33
- middlewares.reverse.inject(app) do |next_middleware, current_middleware|
34
- klass, args, block = current_middleware
35
- args ||= []
36
-
37
- if klass.is_a?(Class)
38
- klass.new(next_middleware, *args, &block)
39
- elsif klass.respond_to?(:call)
40
- lambda do |env|
41
- next_middleware.call(klass.call(env, *args))
42
- end
43
- else
44
- fail "Invalid middleware, doesn't respond to `call`: #{klass.inspect}"
45
- end
46
- end
47
- end
48
-
49
- def insert(index, klass, *args, &block)
50
- middlewares.insert(index, [klass, args, block])
51
- end
52
-
53
- def each
54
- middlewares.each { |x| yield x.first }
55
- end
56
-
57
- def clear
58
- middlewares.clear
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Middleware::JSON do
4
- let(:data) { [{id: 1, name: 'Anon'}, {id: 2, name: 'John', friends: [1]}] }
5
- let(:body) { '' }
6
- let(:headers) { {} }
7
- let(:request) { Acfs::Request.new 'url', method: 'GET', data: data }
8
- let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
9
- let(:decoder) { Acfs::Middleware::JSON.new ->(req) { req } }
10
-
11
- before do
12
- decoder.call request
13
- end
14
-
15
- describe 'encode' do
16
- context 'with not serialized request' do
17
- it 'should set Content-Type' do
18
- expect(request.headers['Content-Type']).to eq 'application/json'
19
- end
20
-
21
- it 'should append Accept header' do
22
- expect(request.headers['Accept']).to eq 'application/json;q=1'
23
- end
24
-
25
- it 'should serialize data to JSON' do
26
- expect(JSON.parse(request.body)).to eq data.map(&:stringify_keys)
27
- end
28
- end
29
- end
30
-
31
- describe 'decode' do
32
- context 'with JSON response' do
33
- let(:headers) { {'Content-Type' => 'application/json; charset=utf-8'} }
34
- let(:body) { data.to_json }
35
-
36
- it 'should decode body data' do
37
- request.complete! response
38
-
39
- expect(response.data).to be == data.map(&:stringify_keys)
40
- end
41
- end
42
-
43
- context 'with invalid JSON response' do
44
- let(:headers) { {'Content-Type' => 'application/json'} }
45
- let(:body) { data.to_json[4..-4] }
46
-
47
- it 'should raise an error' do
48
- expect { request.complete! response }.to raise_error(MultiJson::LoadError)
49
- end
50
- end
51
-
52
- context 'without JSON response' do
53
- let(:headers) { {'Content-Type' => 'application/text'} }
54
- let(:body) { data.to_json }
55
-
56
- it 'should not decode non-JSON encoded responses' do
57
- request.complete! response
58
-
59
- expect(response.data).to be_nil
60
- end
61
- end
62
- end
63
- end