acfs 0.15.0 → 0.16.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 +1 -0
- data/CHANGELOG.md +78 -0
- data/README.md +1 -1
- data/lib/acfs.rb +3 -1
- data/lib/acfs/configuration.rb +63 -0
- data/lib/acfs/errors.rb +1 -1
- data/lib/acfs/global.rb +4 -0
- data/lib/acfs/service.rb +16 -1
- data/lib/acfs/stub.rb +1 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/configuration_spec.rb +44 -0
- data/spec/acfs/service_spec.rb +12 -4
- data/spec/acfs/stub_spec.rb +1 -1
- data/spec/fixtures/config.yml +14 -0
- data/spec/support/service.rb +5 -2
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5f03951ec6374b76946211e390bfc2c0ff6f1f
|
4
|
+
data.tar.gz: af8cf339ce2bc9e4a5542a55bb1b8d1e8b63793b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66728dbe0550a7d8585d1d47b615c60534417d176125ddca78b572e11e13f6611b4ec16877db10096c4752f9d24f1323ea01da8bfc5f0b97fd9bcd83e530a85f
|
7
|
+
data.tar.gz: 55f211e28b344c2c5245161d76c12826cd6c89d36132a7838fdfa1402ac5e1dde1618851e3a1e9d6c1c40b5b17ff6bbdef5c6101b464d1cd7196a46d66418a3c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.16.0
|
4
|
+
|
5
|
+
* Add YAML configuration
|
6
|
+
* Add external configuration for services
|
7
|
+
* Add Rubinius support
|
8
|
+
|
9
|
+
## 0.15.0
|
10
|
+
|
11
|
+
* Add stubbing capabilities for resources
|
12
|
+
|
13
|
+
## 0.14.0 & 0.13.0
|
14
|
+
|
15
|
+
* Fix response attributes
|
16
|
+
|
17
|
+
## 0.12.0
|
18
|
+
|
19
|
+
* Add JRuby support
|
20
|
+
* Improve handling of error respones (422)
|
21
|
+
|
22
|
+
## 0.11.0
|
23
|
+
|
24
|
+
* Add Logger Middleware
|
25
|
+
* Add handling of error responses
|
26
|
+
|
27
|
+
## 0.10.0
|
28
|
+
|
29
|
+
* Return hash with indifferent access for resource attributes
|
30
|
+
|
31
|
+
## 0.9.0
|
32
|
+
|
33
|
+
* Add create operation
|
34
|
+
|
35
|
+
## 0.8.0
|
36
|
+
|
37
|
+
* Add save operation (PUT and POST)
|
38
|
+
* Add JSON and MessagePack encoder middlewares for encoding request data
|
39
|
+
* ActiveModel::Dirty
|
40
|
+
* Add persistant state methods
|
41
|
+
|
42
|
+
## 0.7.0
|
43
|
+
|
44
|
+
* Per-service middleware stack
|
45
|
+
|
46
|
+
## 0.6.0
|
47
|
+
|
48
|
+
* Add support for multiple ids for .find
|
49
|
+
* Add MessagePack support
|
50
|
+
|
51
|
+
## 0.5.1
|
52
|
+
|
53
|
+
* Fix mime type parsing for mime types with aditional parameters (ActionPack < 4.0)
|
54
|
+
|
55
|
+
## 0.5.0
|
56
|
+
|
57
|
+
* Add mime type support for respones
|
58
|
+
|
59
|
+
## 0.4.0
|
60
|
+
|
61
|
+
* Improve JSON response detection
|
62
|
+
* Add bool attribute type
|
63
|
+
|
64
|
+
## 0.3.0
|
65
|
+
|
66
|
+
* Add tracking for loading state (if resource is loaded or queued)
|
67
|
+
* Add JSON middleware to decode respones
|
68
|
+
* Add middleware support
|
69
|
+
* Add method to fetch single resources or list of resources
|
70
|
+
* Use typhoeus as http library for parallel request processing
|
71
|
+
|
72
|
+
## 0.2.0
|
73
|
+
|
74
|
+
* Allow to define resources and attributes
|
75
|
+
|
76
|
+
## 0.1.0
|
77
|
+
|
78
|
+
* Project start
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Acfs covers model and service abstraction, convenient query and filter methods,
|
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
gem 'acfs', '~> 0.
|
13
|
+
gem 'acfs', '~> 0.16.0'
|
14
14
|
|
15
15
|
**Note:** Acfs is under development. I'll try to avoid changes to the public API but internal APIs may change quite often.
|
16
16
|
|
data/lib/acfs.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_support'
|
2
|
-
require 'active_support/core_ext/class'
|
3
2
|
require 'active_support/core_ext/hash'
|
3
|
+
require 'active_support/core_ext/class'
|
4
|
+
require 'active_support/core_ext/string'
|
4
5
|
require 'active_support/core_ext/module'
|
5
6
|
|
6
7
|
require 'acfs/version'
|
@@ -19,6 +20,7 @@ module Acfs
|
|
19
20
|
autoload :Stub
|
20
21
|
autoload :Operation
|
21
22
|
autoload :Runner
|
23
|
+
autoload :Configuration
|
22
24
|
|
23
25
|
module Middleware
|
24
26
|
extend ActiveSupport::Autoload
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Acfs
|
5
|
+
|
6
|
+
#
|
7
|
+
#
|
8
|
+
class Configuration
|
9
|
+
attr_reader :locations
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@locations = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(&block)
|
16
|
+
if block.arity > 0
|
17
|
+
block.call self
|
18
|
+
else
|
19
|
+
instance_eval &block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def locate(service, uri = nil)
|
24
|
+
service = service.to_s.underscore.to_sym
|
25
|
+
if uri.nil?
|
26
|
+
locations[service]
|
27
|
+
else
|
28
|
+
locations[service] = URI.parse uri
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def load(filename)
|
33
|
+
config = YAML::load File.read filename
|
34
|
+
env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
35
|
+
|
36
|
+
config = config[env] if config.has_key? env
|
37
|
+
config.each do |key, value|
|
38
|
+
case key
|
39
|
+
when 'services' then load_services value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_services(services)
|
45
|
+
services.each do |service, data|
|
46
|
+
if (val = data).is_a?(String) || (val = data['locate'])
|
47
|
+
locate service.to_sym, val
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
|
54
|
+
def current
|
55
|
+
@configuration ||= new
|
56
|
+
end
|
57
|
+
|
58
|
+
def set(configuration)
|
59
|
+
@configuration = configuration if configuration.is_a? Configuration
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/acfs/errors.rb
CHANGED
data/lib/acfs/global.rb
CHANGED
data/lib/acfs/service.rb
CHANGED
@@ -6,7 +6,6 @@ module Acfs
|
|
6
6
|
#
|
7
7
|
class Service
|
8
8
|
attr_accessor :options
|
9
|
-
class_attribute :base_url
|
10
9
|
|
11
10
|
include Service::Middleware
|
12
11
|
|
@@ -26,5 +25,21 @@ module Acfs
|
|
26
25
|
url += "/#{options[:suffix].to_s}" if options[:suffix]
|
27
26
|
url
|
28
27
|
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
def identity(identity = nil)
|
32
|
+
@identity = identity.to_s.to_sym unless identity.nil?
|
33
|
+
@identity ||= name.to_sym
|
34
|
+
end
|
35
|
+
|
36
|
+
def base_url
|
37
|
+
unless (base = Acfs::Configuration.current.locate identity)
|
38
|
+
raise ArgumentError, "#{identity} not configured. Add `locate '#{identity.to_s.underscore}', 'http://service.url/'` to your configuration."
|
39
|
+
end
|
40
|
+
|
41
|
+
base.to_s
|
42
|
+
end
|
43
|
+
end
|
29
44
|
end
|
30
45
|
end
|
data/lib/acfs/stub.rb
CHANGED
@@ -60,7 +60,7 @@ module Acfs
|
|
60
60
|
stub = stub_for op
|
61
61
|
unless stub
|
62
62
|
return false if allow_requests?
|
63
|
-
raise
|
63
|
+
raise RealRequestsNotAllowedError, "No stub found for `#{op.resource.name}` with params `#{op.params}`"
|
64
64
|
end
|
65
65
|
|
66
66
|
if (data = stub[:return])
|
data/lib/acfs/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Acfs::Configuration do
|
4
|
+
|
5
|
+
let(:cfg) { Acfs::Configuration.new }
|
6
|
+
before { @configuration = Acfs::Configuration.current.dup }
|
7
|
+
after { Acfs::Configuration.set @configuration }
|
8
|
+
|
9
|
+
describe 'Acfs.configure' do
|
10
|
+
|
11
|
+
it 'should invoke configure on current configuration' do
|
12
|
+
Acfs::Configuration.current.should_receive(:configure).once.and_call_original
|
13
|
+
|
14
|
+
Acfs.configure do |c|
|
15
|
+
expect(c).to be_a Acfs::Configuration
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.load' do
|
21
|
+
it 'should be able to load YAML' do
|
22
|
+
cfg.configure do
|
23
|
+
load 'spec/fixtures/config.yml'
|
24
|
+
end
|
25
|
+
|
26
|
+
expect(cfg.locate(UserService).to_s).to be == 'http://localhost:3001/'
|
27
|
+
expect(cfg.locate(CommentService).to_s).to be == 'http://localhost:3002/'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with RACK_ENV' do
|
31
|
+
before { @env = ENV['RACK_ENV']; ENV['RACK_ENV'] = 'production' }
|
32
|
+
after { ENV['RACK_ENV'] = @env }
|
33
|
+
|
34
|
+
it 'should load ENV block' do
|
35
|
+
cfg.configure do
|
36
|
+
load 'spec/fixtures/config.yml'
|
37
|
+
end
|
38
|
+
|
39
|
+
expect(cfg.locate(UserService).to_s).to be == 'http://user.example.org/'
|
40
|
+
expect(cfg.locate(CommentService).to_s).to be == 'http://comment.example.org/'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/acfs/service_spec.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Service do
|
4
|
-
let(:srv_class) { Class.new(Acfs::Service) }
|
4
|
+
let(:srv_class) { Class.new(Acfs::Service) { identity :test } }
|
5
5
|
let(:options) { {} }
|
6
6
|
let(:service) { srv_class.new options }
|
7
7
|
|
8
|
+
before do
|
9
|
+
Acfs::Configuration.current.locate :test, ''
|
10
|
+
end
|
11
|
+
|
8
12
|
describe '#initialize' do
|
9
13
|
let(:options) { { path: 'abc', key: 'value' } }
|
10
14
|
|
11
|
-
it
|
15
|
+
it 'should set options' do
|
12
16
|
expect(service.options).to eq(options)
|
13
17
|
end
|
14
18
|
end
|
@@ -28,8 +32,12 @@ describe Acfs::Service do
|
|
28
32
|
end
|
29
33
|
|
30
34
|
describe '.base_url' do
|
31
|
-
|
32
|
-
|
35
|
+
|
36
|
+
before do
|
37
|
+
Acfs::Configuration.current.locate :test, 'http://abc.de/api/v1'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return configured URI for service' do
|
33
41
|
|
34
42
|
expect(srv_class.base_url).to eq('http://abc.de/api/v1')
|
35
43
|
end
|
data/spec/acfs/stub_spec.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
development: &dev
|
2
|
+
services:
|
3
|
+
user_service: http://localhost:3001/
|
4
|
+
comment_service:
|
5
|
+
locate: http://localhost:3002/
|
6
|
+
|
7
|
+
production:
|
8
|
+
services:
|
9
|
+
user_service:
|
10
|
+
locate: http://user.example.org/
|
11
|
+
comment_service: http://comment.example.org/
|
12
|
+
|
13
|
+
test:
|
14
|
+
<<: *dev
|
data/spec/support/service.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
|
2
|
+
Acfs.configure do
|
3
|
+
locate :user_service, 'http://users.example.org'
|
4
|
+
locate :comment_service, 'http://comments.example.org'
|
5
|
+
end
|
6
|
+
|
2
7
|
class UserService < Acfs::Service
|
3
|
-
self.base_url = 'http://users.example.org'
|
4
8
|
use Acfs::Middleware::MessagePackDecoder
|
5
9
|
use Acfs::Middleware::JsonDecoder
|
6
10
|
use Acfs::Middleware::JsonEncoder
|
7
11
|
end
|
8
12
|
|
9
13
|
class CommentService < Acfs::Service
|
10
|
-
self.base_url = 'http://comments.example.org'
|
11
14
|
use Acfs::Middleware::JsonDecoder
|
12
15
|
end
|
13
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- .gitignore
|
119
119
|
- .rspec
|
120
120
|
- .travis.yml
|
121
|
+
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- Guardfile
|
123
124
|
- LICENSE
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- lib/acfs/adapter/base.rb
|
131
132
|
- lib/acfs/adapter/typhoeus.rb
|
132
133
|
- lib/acfs/collection.rb
|
134
|
+
- lib/acfs/configuration.rb
|
133
135
|
- lib/acfs/errors.rb
|
134
136
|
- lib/acfs/global.rb
|
135
137
|
- lib/acfs/middleware/base.rb
|
@@ -164,6 +166,7 @@ files:
|
|
164
166
|
- lib/acfs/service/middleware.rb
|
165
167
|
- lib/acfs/stub.rb
|
166
168
|
- lib/acfs/version.rb
|
169
|
+
- spec/acfs/configuration_spec.rb
|
167
170
|
- spec/acfs/middleware/json_decoder_spec.rb
|
168
171
|
- spec/acfs/middleware/msgpack_decoder_spec.rb
|
169
172
|
- spec/acfs/model/attributes_spec.rb
|
@@ -181,6 +184,7 @@ files:
|
|
181
184
|
- spec/acfs/service_spec.rb
|
182
185
|
- spec/acfs/stub_spec.rb
|
183
186
|
- spec/acfs_spec.rb
|
187
|
+
- spec/fixtures/config.yml
|
184
188
|
- spec/spec_helper.rb
|
185
189
|
- spec/support/response.rb
|
186
190
|
- spec/support/service.rb
|
@@ -209,6 +213,7 @@ signing_key:
|
|
209
213
|
specification_version: 4
|
210
214
|
summary: An abstract API base client for service oriented application.
|
211
215
|
test_files:
|
216
|
+
- spec/acfs/configuration_spec.rb
|
212
217
|
- spec/acfs/middleware/json_decoder_spec.rb
|
213
218
|
- spec/acfs/middleware/msgpack_decoder_spec.rb
|
214
219
|
- spec/acfs/model/attributes_spec.rb
|
@@ -226,6 +231,7 @@ test_files:
|
|
226
231
|
- spec/acfs/service_spec.rb
|
227
232
|
- spec/acfs/stub_spec.rb
|
228
233
|
- spec/acfs_spec.rb
|
234
|
+
- spec/fixtures/config.yml
|
229
235
|
- spec/spec_helper.rb
|
230
236
|
- spec/support/response.rb
|
231
237
|
- spec/support/service.rb
|