restify 0.5.0 → 1.0.0

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: 056a4caf86fd6f8b72c420b0ecc705a74147c5a1
4
- data.tar.gz: ce0ea38d4c1bdd4c9e0c08eac752eeb0669a16db
3
+ metadata.gz: 9f5b0ad969a7b5ab4889aa69bd9c5d0dde4a7e5f
4
+ data.tar.gz: 57fb5334cfbdba973c5df3569450c18413b3884b
5
5
  SHA512:
6
- metadata.gz: 6a64dc7d022c4d6abc168886bcc3ef329abfee0279a47230c6457d9f9f41e6c30962ac8af0edd5211d82e5c4fcd8cb4571e0339362a53ae531a2b2eae569eb58
7
- data.tar.gz: a551b3a408e99647ba3c0a12b452e7caf9fba94d6d49a94791d080c02ce0e26c6393c25a64b14f69b25e41bc4f37c83d3754c6c0b2429b3cee9c4c2789541b6b
6
+ metadata.gz: 6a8cb08d62f1b91d7087e1e1ae75c0afd4278280c1334e072db3673d8388c341f957362019d81d92aa6832bcd9d04ae6c59ed5f578ef09edea486d497dfc9176
7
+ data.tar.gz: 78668d83c4b4d6867ab6e25663de52ab5804da8380019bd3bf39f4bacb5f667499c20a421ca0049ef323395da7605b99ee7d2eadb07b1fbb25f2124a1fa27e21
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
- ## master
1
+ # Changelog
2
2
 
3
+ ## 1.0.0
4
+
5
+ * Experimental cache API doing nothing for now
6
+ * Use `~> 1.0` of `concurrent-ruby`
7
+
8
+ ## 0.5.0
9
+
10
+ * Add `sync` option to typhoeus adapter
11
+ * Add registry for storing entry points
12
+ * Make eventmachine based adapter default
13
+
14
+ ## 0.4.0
15
+
16
+ * Add method to explicit access resource data
3
17
  * Drop obligation in favor of simple Concurrent::IVar based promise class.
4
18
  Notable changes:
5
19
  - Returned object us of type `Restify::Promise` now.
6
20
  - `value` will not raise exception but return `nil` in case of failure. Use `value!` for old behavior.
21
+ * Use typhoeus as default adapter
22
+ * `Restify.new` returns relation now instead of resource
data/README.md CHANGED
@@ -8,12 +8,13 @@ Restify can be used to consume hypermedia REST APIs (like GitHubs), to build a s
8
8
 
9
9
  Restify is build upon the following libraries:
10
10
 
11
+ * [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby)
11
12
  * [addressable](https://github.com/sporkmonger/addressable)
12
- * [typhoeus](https://github.com/typhoeus/typhoeus)
13
+ * [em-http-request](https://github.com/igrigorik/em-http-request)
13
14
 
14
15
  It has optional HTTP adapters using:
15
16
 
16
- * [em-http-request](https://github.com/igrigorik/em-http-request)
17
+ * [typhoeus](https://github.com/typhoeus/typhoeus)
17
18
 
18
19
  The HTTP adapters are mostly run in a background thread and may not survive mid-application forks.
19
20
 
data/lib/restify.rb CHANGED
@@ -12,6 +12,7 @@ module Restify
12
12
  require 'restify/registry'
13
13
  require 'restify/global'
14
14
 
15
+ require 'restify/cache'
15
16
  require 'restify/context'
16
17
  require 'restify/resource'
17
18
  require 'restify/relation'
@@ -20,6 +21,10 @@ module Restify
20
21
  require 'restify/request'
21
22
  require 'restify/response'
22
23
 
24
+ module Adapter
25
+ require 'restify/adapter/base'
26
+ end
27
+
23
28
  module Processors
24
29
  require 'restify/processors/base'
25
30
  require 'restify/processors/json'
@@ -0,0 +1,15 @@
1
+ module Restify
2
+ module Adapter
3
+ class Base
4
+ def call(request)
5
+ Promise.create do |writer|
6
+ call_native request, writer
7
+ end
8
+ end
9
+
10
+ def call_native(request, writer)
11
+ throw NotImplementedError.new '#call_native not implemented. Subclass responsibility.'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,10 +2,8 @@ require 'eventmachine'
2
2
  require 'em-http-request'
3
3
 
4
4
  module Restify
5
- #
6
5
  module Adapter
7
- #
8
- class EM
6
+ class EM < Base
9
7
  class Connection
10
8
  class << self
11
9
  def open(uri)
@@ -105,11 +103,9 @@ module Restify
105
103
  end
106
104
  end
107
105
 
108
- def call(request)
109
- Promise.create do |writer|
110
- next_tick do
111
- Connection.open(request.uri).call(request, writer)
112
- end
106
+ def call_native(request, writer)
107
+ next_tick do
108
+ Connection.open(request.uri).call(request, writer)
113
109
  end
114
110
  end
115
111
 
@@ -1,11 +1,8 @@
1
1
  require 'typhoeus'
2
2
 
3
3
  module Restify
4
- #
5
4
  module Adapter
6
- #
7
- class Typhoeus
8
-
5
+ class Typhoeus < Base
9
6
  def initialize(**options)
10
7
  @queue = Queue.new
11
8
  @hydra = ::Typhoeus::Hydra.new
@@ -41,10 +38,8 @@ module Restify
41
38
  end
42
39
  end
43
40
 
44
- def call(request)
45
- Promise.create do |writer|
46
- queue request, writer
47
- end
41
+ def call_native(request, writer)
42
+ queue request, writer
48
43
  end
49
44
 
50
45
  private
@@ -0,0 +1,28 @@
1
+ module Restify
2
+ class Cache
3
+ def initialize(store)
4
+ @store = store
5
+ end
6
+
7
+ def call(request)
8
+ if (response = match(request))
9
+ return response
10
+ end
11
+
12
+ yield(request).then do |response|
13
+ cache(response)
14
+ response
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def match(request)
21
+ false
22
+ end
23
+
24
+ def cache(response)
25
+ # noop
26
+ end
27
+ end
28
+ end
@@ -47,7 +47,8 @@ module Restify
47
47
  data: data,
48
48
  headers: options.fetch(:headers, {})
49
49
 
50
- adapter.call(request).then do |response|
50
+ ret = cache.call(request) {|request| adapter.call(request) }
51
+ ret.then do |response|
51
52
  if response.success?
52
53
  process response
53
54
  else
@@ -62,6 +63,10 @@ module Restify
62
63
  options[:adapter] || Restify.adapter
63
64
  end
64
65
 
66
+ def cache
67
+ options[:cache] || Restify.cache
68
+ end
69
+
65
70
  class << self
66
71
  def raise_response_error(response)
67
72
  case response.code
@@ -19,6 +19,17 @@ module Restify
19
19
  @adapter = adapter
20
20
  end
21
21
 
22
+ def cache
23
+ @cache ||= begin
24
+ require 'active_support/cache'
25
+ Restify::Cache.new store: ActiveSupport::Cache::MemoryStore.new
26
+ end
27
+ end
28
+
29
+ def cache=(cache)
30
+ @cache = cache
31
+ end
32
+
22
33
  private
23
34
 
24
35
  def resolve_context(uri, **opts)
@@ -1,7 +1,7 @@
1
1
  module Restify
2
2
  module VERSION
3
- MAJOR = 0
4
- MINOR = 5
3
+ MAJOR = 1
4
+ MINOR = 0
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
data/restify.gemspec CHANGED
@@ -18,12 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'concurrent-ruby', '~> 0.9.0'
21
+ spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
22
22
  spec.add_runtime_dependency 'addressable', '~> 2.3'
23
23
  spec.add_runtime_dependency 'hashie', '~> 3.3'
24
24
  spec.add_runtime_dependency 'rack'
25
25
  spec.add_runtime_dependency 'eventmachine', '>= 1.2'
26
26
  spec.add_runtime_dependency 'em-http-request', '~> 1.1.3'
27
+ spec.add_runtime_dependency 'activesupport'
27
28
 
28
29
  spec.add_development_dependency 'bundler', '~> 1.5'
29
30
 
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restify::Cache do
4
+ let(:store) { double 'store' }
5
+ let(:cache) { described_class.new store }
6
+
7
+ subject { cache }
8
+
9
+ describe '#call' do
10
+ let(:request) { double 'request' }
11
+ let(:promise0) { double 'promise0' }
12
+ let(:promise1) { double 'promise1' }
13
+ let(:response) { double 'response' }
14
+
15
+ it 'yields with promises' do
16
+ expect(promise0).to receive(:then).and_yield(response).and_return(promise1)
17
+
18
+ expect(subject.call(request) { promise0 }).to eq promise1
19
+ end
20
+
21
+ it 'caches new responses' do
22
+ expect(promise0).to receive(:then).and_yield(response)
23
+ expect(cache).to receive(:cache).with(response)
24
+
25
+ subject.call(request) { promise0 }
26
+ end
27
+
28
+ it 'returns with match' do
29
+ expect(cache).to receive(:match).with(request).and_return(response)
30
+
31
+ expect(subject.call(request)).to eq response
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.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: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: '1.0'
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: 0.9.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.1.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -120,8 +134,10 @@ files:
120
134
  - LICENSE.txt
121
135
  - README.md
122
136
  - lib/restify.rb
137
+ - lib/restify/adapter/base.rb
123
138
  - lib/restify/adapter/em.rb
124
139
  - lib/restify/adapter/typhoeus.rb
140
+ - lib/restify/cache.rb
125
141
  - lib/restify/context.rb
126
142
  - lib/restify/error.rb
127
143
  - lib/restify/global.rb
@@ -136,6 +152,7 @@ files:
136
152
  - lib/restify/response.rb
137
153
  - lib/restify/version.rb
138
154
  - restify.gemspec
155
+ - spec/restify/cache_spec.rb
139
156
  - spec/restify/global_spec.rb
140
157
  - spec/restify/link_spec.rb
141
158
  - spec/restify/processors/json_spec.rb
@@ -169,6 +186,7 @@ signing_key:
169
186
  specification_version: 4
170
187
  summary: An experimental hypermedia REST client.
171
188
  test_files:
189
+ - spec/restify/cache_spec.rb
172
190
  - spec/restify/global_spec.rb
173
191
  - spec/restify/link_spec.rb
174
192
  - spec/restify/processors/json_spec.rb
@@ -177,4 +195,3 @@ test_files:
177
195
  - spec/restify/resource_spec.rb
178
196
  - spec/restify_spec.rb
179
197
  - spec/spec_helper.rb
180
- has_rdoc: