hyperclient 0.8.1 → 0.8.2

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: f2daa0c1ea450238670cb824e5d1d7dd07a5b956
4
- data.tar.gz: 2a70fee311b942248162d688afd7f1c301eb4b68
3
+ metadata.gz: 1bde74927d1e402d1db9cfd3860e36d692bcba2b
4
+ data.tar.gz: f65e61030043163822906124088bfba6ff47b72e
5
5
  SHA512:
6
- metadata.gz: 4090176fce80ffdeb57dca157f28896e261aa77e35ff863f992ee566248c71ba78820138b0b5f010e867865073d6044b8a151bda612f1a8f722fa217c02ee69c
7
- data.tar.gz: ac16dcb963df0b148761d94b4d9cc0cca1ff60334449a3d172d8bb972550cf80ad8aef0bd2dcb58e7a12c89916769dcd35daa8ae8d84c79a3d9fec36296675c5
6
+ metadata.gz: 5b4716aad58beaeb9566564ba214afc7d69e31f8ea080ae12c26e10d3322e602d72c552e66bcd5d5653dc2c683499178fc34e0802b47c019848b97c6f35be617
7
+ data.tar.gz: c1cd3c5ecbf2ed9112da1a7a6a4cea0f11abcdbb51c0473bed46c15b5f3be299456c7675b10fe9b51dba6c3fbb690b5517331ef4c05e5a8c9302fbd866107075
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-03-15 15:48:04 -0400 using RuboCop version 0.33.0.
3
+ # on 2016-12-21 20:00:37 +0000 using RuboCop version 0.42.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -9,14 +9,15 @@
9
9
  # Offense count: 1
10
10
  # Configuration parameters: CountComments.
11
11
  Metrics/ClassLength:
12
- Max: 103
12
+ Max: 109
13
13
 
14
- # Offense count: 85
15
- # Configuration parameters: AllowURI, URISchemes.
14
+ # Offense count: 89
15
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
16
+ # URISchemes: http, https
16
17
  Metrics/LineLength:
17
18
  Max: 142
18
19
 
19
- # Offense count: 3
20
+ # Offense count: 4
20
21
  # Configuration parameters: CountComments.
21
22
  Metrics/MethodLength:
22
23
  Max: 25
@@ -24,7 +25,7 @@ Metrics/MethodLength:
24
25
  # Offense count: 3
25
26
  # Configuration parameters: CountComments.
26
27
  Metrics/ModuleLength:
27
- Max: 258
28
+ Max: 391
28
29
 
29
30
  # Offense count: 1
30
31
  Style/AsciiComments:
@@ -33,28 +34,21 @@ Style/AsciiComments:
33
34
 
34
35
  # Offense count: 2
35
36
  # Configuration parameters: EnforcedStyle, SupportedStyles.
37
+ # SupportedStyles: nested, compact
36
38
  Style/ClassAndModuleChildren:
37
39
  Exclude:
38
40
  - 'features/steps/api_navigation.rb'
39
41
  - 'features/steps/default_config.rb'
40
42
 
41
- # Offense count: 14
43
+ # Offense count: 4
42
44
  Style/Documentation:
43
45
  Exclude:
46
+ - 'spec/**/*'
47
+ - 'test/**/*'
44
48
  - 'features/steps/api_navigation.rb'
45
49
  - 'features/steps/default_config.rb'
46
50
  - 'features/support/api.rb'
47
51
  - 'features/support/fixtures.rb'
48
- - 'lib/hyperclient/version.rb'
49
- - 'test/faraday/connection_test.rb'
50
- - 'test/hyperclient/attributes_test.rb'
51
- - 'test/hyperclient/collection_test.rb'
52
- - 'test/hyperclient/curie_test.rb'
53
- - 'test/hyperclient/entry_point_test.rb'
54
- - 'test/hyperclient/link_collection_test.rb'
55
- - 'test/hyperclient/link_test.rb'
56
- - 'test/hyperclient/resource_collection_test.rb'
57
- - 'test/hyperclient/resource_test.rb'
58
52
 
59
53
  # Offense count: 2
60
54
  Style/DoubleNegation:
@@ -64,15 +58,23 @@ Style/DoubleNegation:
64
58
 
65
59
  # Offense count: 5
66
60
  # Cop supports --auto-correct.
61
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
62
+ # SupportedStyles: line_count_dependent, lambda, literal
67
63
  Style/Lambda:
68
64
  Exclude:
69
65
  - 'test/hyperclient/entry_point_test.rb'
70
66
  - 'test/hyperclient/link_test.rb'
71
67
  - 'test/hyperclient/resource_test.rb'
72
68
 
69
+ # Offense count: 1
70
+ Style/MethodMissing:
71
+ Exclude:
72
+ - 'lib/hyperclient/collection.rb'
73
+
73
74
  # Offense count: 1
74
75
  # Cop supports --auto-correct.
75
76
  # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
77
+ # SupportedStyles: slashes, percent_r, mixed
76
78
  Style/RegexpLiteral:
77
79
  Exclude:
78
80
  - 'features/support/api.rb'
data/.travis.yml CHANGED
@@ -1,19 +1,22 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- - 2.1
5
- - 2.2
6
- - 2.3.0
7
- - rbx-2
8
- - jruby-19mode
9
- - ruby-head
10
- - jruby-head
1
+ language: ruby
2
+
3
+ sudo: false
11
4
 
12
5
  matrix:
6
+ include:
7
+ - rvm: 2.3.1
8
+ script:
9
+ - bundle exec danger
10
+ - rvm: 2.3.1
11
+ - rvm: 2.3.0
12
+ - rvm: 2.2.5
13
+ - rvm: rbx-2
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
16
+ - rvm: jruby-9.1.6.0
13
17
  allow_failures:
14
18
  - rvm: ruby-head
15
19
  - rvm: jruby-head
16
20
  - rvm: rbx-2
17
21
 
18
- before_install:
19
- - gem install bundler
22
+ bundler_args: --without development
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ### 0.8.1 (MArch 15, 2016)
1
+ ### 0.8.2 (December 31, 2016)
2
+
3
+ #### This version is no longer tested with Ruby < 2.2.
4
+
5
+ * [#105](https://github.com/codegram/hyperclient/pull/105), [#108](https://github.com/codegram/hyperclient/pull/108): Added Danger, PR linter - [@dblock](https://github.com/dblock).
6
+ * [#109](https://github.com/codegram/hyperclient/pull/109): Allow disabling asynchronous behavior per-instance - [@Talkdesk](https://github.com/Talkdesk).
7
+ * [#110](https://github.com/codegram/hyperclient/pull/110): Fixed ruby warnings - [@ivoanjo](https://github.com/ivoanjo).
8
+
9
+ ### 0.8.1 (March 15, 2016)
2
10
 
3
11
  * [#97](https://github.com/codegram/hyperclient/issues/97): Fix: curies are no longer used as link shorteners - [@joshco](https://github.com/joshco), [@dblock](https://github.com/dblock).
4
12
  * [#95](https://github.com/codegram/hyperclient/issues/95): Fix: re-add eager delegation for `resource.each` - [@dblock](https://github.com/dblock).
@@ -14,14 +22,14 @@
14
22
 
15
23
  ### 0.7.0 (February 23, 2015)
16
24
 
17
- This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
25
+ #### This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
18
26
 
19
27
  * [#80](https://github.com/codegram/hyperclient/pull/80): Faraday options can be passed to the connection on initialization - [@koenpunt](https://github.com/koenpunt).
20
28
  * [#81](https://github.com/codegram/hyperclient/pull/81): The default Content-Type is now `application/hal+json` - [@koenpunt](https://github.com/koenpunt).
21
29
 
22
30
  ### 0.6.1 (October 17, 2014)
23
31
 
24
- This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
32
+ #### This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
25
33
 
26
34
  * [#51](https://github.com/codegram/hyperclient/issues/51), [#75](https://github.com/codegram/hyperclient/pull/75): Added support for setting headers and overriding or extending the default Faraday connection block before a connection is constructed - [@dblock](https://github.com/dblock).
27
35
  * [#41](https://github.com/codegram/hyperclient/issues/41), [#73](https://github.com/codegram/hyperclient/pull/73): All Link HTTP methods now return a Resource, including `_get`, which has been aliased to `_resource`, `_post`, `_put`, `_patch`, `_head` and `_options` - [@dblock](https://github.com/dblock).
@@ -30,7 +38,7 @@ This version introduces several backwards incompatible changes. See [UPGRADING](
30
38
 
31
39
  ### 0.5.0 (October 1, 2014)
32
40
 
33
- This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
41
+ #### This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details.
34
42
 
35
43
  * [#63](https://github.com/codegram/hyperclient/pull/63): Navigational methods, including `links`, `get` or `post`, have been renamed to `_links`, `_get`, or `_post` respectively - [@dblock](https://github.com/dblock).
36
44
  * [#64](https://github.com/codegram/hyperclient/issues/64): Added support for curies - [@dblock](https://github.com/dblock).
data/Dangerfile ADDED
@@ -0,0 +1,2 @@
1
+ # check for changes in CHANGELOG
2
+ changelog.check
data/Gemfile CHANGED
@@ -2,14 +2,29 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake'
6
- gem 'growl'
7
- gem 'guard'
8
- gem 'guard-minitest'
9
- gem 'guard-spinach'
10
- gem 'pry'
11
-
12
- gem 'yard', '~> 0.8'
13
- gem 'yard-tomdoc'
14
- gem 'simplecov', require: false
15
- gem 'rubocop', '~> 0.33.0', require: false
5
+ group :development do
6
+ gem 'growl'
7
+ gem 'guard'
8
+ gem 'guard-minitest'
9
+ gem 'guard-spinach'
10
+ gem 'pry'
11
+ end
12
+
13
+ group :development, :test do
14
+ gem 'yard', '~> 0.8'
15
+ gem 'yard-tomdoc'
16
+ gem 'rake'
17
+ gem 'simplecov', require: false
18
+ gem 'rubocop', '~> 0.42.0', require: false
19
+ end
20
+
21
+ group :test do
22
+ gem 'futuroscope', github: 'codegram/futuroscope'
23
+ gem 'danger-changelog', '~> 0.1'
24
+ gem 'minitest'
25
+ gem 'turn'
26
+ gem 'webmock'
27
+ gem 'mocha'
28
+ gem 'rack-test'
29
+ gem 'spinach'
30
+ end
data/README.md CHANGED
@@ -187,6 +187,23 @@ spline._delete
187
187
 
188
188
  HTTP methods always return a new instance of Resource.
189
189
 
190
+ ### Asynchronous requests
191
+
192
+ By default, Hyperclient requests are performed asynchronously in a background thread pool via the [Futuroscope](https://github.com/codegram/futuroscope) gem. You can control the size of this pool by setting the `min_workers` and `max_workers` settings:
193
+
194
+ ```ruby
195
+ Futuroscope.default_pool.min_workers = 10
196
+ Futuroscope.default_pool.max_workers = 20
197
+ ```
198
+
199
+ If you want to disable this behavior and have all requests performed synchronously, you can use the client `options` to disable this behavior:
200
+
201
+ ```ruby
202
+ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
203
+ client.options[:async] = false
204
+ end
205
+ ```
206
+
190
207
  ## Testing Using Hyperclient
191
208
 
192
209
  You can combine RSpec, Faraday::Adapter::Rack and Hyperclient to test your HAL API without having to ever examine the raw JSON response.
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup :default, :test, :development
5
+
6
+ Bundler::GemHelper.install_tasks
7
7
 
8
8
  if ENV['COVERAGE']
9
9
  require 'simplecov'
@@ -29,6 +29,7 @@ Rake::TestTask.new(:test) do |t|
29
29
  t.libs << 'test'
30
30
  t.pattern = 'test/**/*_test.rb'
31
31
  t.verbose = false
32
+ t.warning = true
32
33
  end
33
34
 
34
35
  desc 'runs the whole spinach suite'
@@ -7,7 +7,7 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
7
7
 
8
8
  # enumerate splines
9
9
  api.splines.each do |spline|
10
- puts "#{spline.uuid}"
10
+ puts spline.uuid.to_s
11
11
  puts " reticulated: #{spline.reticulated ? 'yes' : 'no'}"
12
12
  puts " thumbnail: #{spline['images:thumbnail']}"
13
13
  end
@@ -1,4 +1,4 @@
1
1
  require 'minitest/spec'
2
2
  require 'webmock'
3
+ WebMock.enable!
3
4
  require 'hyperclient'
4
- require 'pry'
data/hyperclient.gemspec CHANGED
@@ -21,11 +21,4 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'uri_template'
22
22
  gem.add_dependency 'net-http-digest_auth'
23
23
  gem.add_dependency 'faraday-digestauth'
24
-
25
- gem.add_development_dependency 'minitest'
26
- gem.add_development_dependency 'turn'
27
- gem.add_development_dependency 'webmock'
28
- gem.add_development_dependency 'mocha'
29
- gem.add_development_dependency 'rack-test'
30
- gem.add_development_dependency 'spinach'
31
24
  end
data/lib/hyperclient.rb CHANGED
@@ -1,4 +1,11 @@
1
+ require 'hyperclient/collection'
2
+ require 'hyperclient/link'
3
+ require 'hyperclient/attributes'
4
+ require 'hyperclient/curie'
1
5
  require 'hyperclient/entry_point'
6
+ require 'hyperclient/link_collection'
7
+ require 'hyperclient/resource'
8
+ require 'hyperclient/resource_collection'
2
9
  require 'hyperclient/version'
3
10
 
4
11
  # Public: Hyperclient namespace.
@@ -1,5 +1,3 @@
1
- require 'hyperclient/collection'
2
-
3
1
  module Hyperclient
4
2
  # Public: A wrapper class to easily acces the attributes in a Resource.
5
3
  #
@@ -9,7 +7,7 @@ module Hyperclient
9
7
  # resource.attributes.title
10
8
  #
11
9
  class Attributes < Collection
12
- RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/] # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1
10
+ RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/].freeze # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1
13
11
 
14
12
  # Public: Initializes the Attributes of a Resource.
15
13
  #
@@ -62,7 +62,7 @@ module Hyperclient
62
62
  def to_h
63
63
  @collection.to_hash
64
64
  end
65
- alias_method :to_hash, :to_h
65
+ alias to_hash to_h
66
66
 
67
67
  def to_s
68
68
  to_hash
@@ -76,7 +76,7 @@ module Hyperclient
76
76
  # Returns an Object.
77
77
  def method_missing(method_name, *_args, &_block)
78
78
  @collection.fetch(method_name.to_s) do
79
- fail "Could not find `#{method_name}` in #{self.class.name}"
79
+ raise "Could not find `#{method_name}` in #{self.class.name}"
80
80
  end
81
81
  end
82
82
 
@@ -1,5 +1,3 @@
1
- require 'hyperclient/resource'
2
-
3
1
  module Hyperclient
4
2
  # Internal: Curies are named tokens that you can define in the document and use
5
3
  # to express curie relation URIs in a friendlier, more compact fashion.
@@ -1,4 +1,3 @@
1
- require 'hyperclient/link'
2
1
  require 'faraday_middleware'
3
2
  require 'faraday_hal_middleware'
4
3
  require_relative '../faraday/connection'
@@ -31,7 +30,7 @@ module Hyperclient
31
30
  extend Forwardable
32
31
 
33
32
  # Public: Delegates common methods to be used with the Faraday connection.
34
- def_delegators :connection, :basic_auth, :digest_auth, :token_auth, :headers, :headers=, :params, :params=
33
+ def_delegators :connection, :basic_auth, :digest_auth, :token_auth, :params, :params=
35
34
 
36
35
  # Public: Initializes an EntryPoint.
37
36
  #
@@ -39,6 +38,8 @@ module Hyperclient
39
38
  def initialize(url, &_block)
40
39
  @link = { 'href' => url }
41
40
  @entry_point = self
41
+ @options = { async: true }
42
+ @connection = nil
42
43
  yield self if block_given?
43
44
  end
44
45
 
@@ -52,15 +53,15 @@ module Hyperclient
52
53
  def connection(options = {}, &block)
53
54
  @faraday_options ||= options.dup
54
55
  if block_given?
55
- fail ConnectionAlreadyInitializedError if @connection
56
- if @faraday_options.delete(:default) == false
57
- @faraday_block = block
58
- else
59
- @faraday_block = lambda do |conn|
60
- default_faraday_block.call conn
61
- block.call conn
62
- end
63
- end
56
+ raise ConnectionAlreadyInitializedError if @connection
57
+ @faraday_block = if @faraday_options.delete(:default) == false
58
+ block
59
+ else
60
+ lambda do |conn|
61
+ default_faraday_block.call conn
62
+ yield conn
63
+ end
64
+ end
64
65
  else
65
66
  @connection ||= Faraday.new(_url, faraday_options, &faraday_block)
66
67
  end
@@ -78,7 +79,7 @@ module Hyperclient
78
79
  #
79
80
  # value - A Hash containing headers to include with every API request.
80
81
  def headers=(value)
81
- fail ConnectionAlreadyInitializedError if @connection
82
+ raise ConnectionAlreadyInitializedError if @connection
82
83
  @headers = value
83
84
  end
84
85
 
@@ -93,7 +94,7 @@ module Hyperclient
93
94
  #
94
95
  # value - A Hash containing options to pass to Faraday
95
96
  def faraday_options=(value)
96
- fail ConnectionAlreadyInitializedError if @connection
97
+ raise ConnectionAlreadyInitializedError if @connection
97
98
  @faraday_options = value
98
99
  end
99
100
 
@@ -108,10 +109,17 @@ module Hyperclient
108
109
  #
109
110
  # value - A Proc accepting a Faraday::Connection.
110
111
  def faraday_block=(value)
111
- fail ConnectionAlreadyInitializedError if @connection
112
+ raise ConnectionAlreadyInitializedError if @connection
112
113
  @faraday_block = value
113
114
  end
114
115
 
116
+ # Public: Read/Set options.
117
+ #
118
+ # value - A Hash containing the client options. Use { async: false } to
119
+ # to disable the default behavior of performing requests asynchronously
120
+ # using futures.
121
+ attr_accessor :options
122
+
115
123
  private
116
124
 
117
125
  # Internal: Returns a block to initialize the Faraday connection. The
@@ -1,4 +1,3 @@
1
- require 'hyperclient/resource'
2
1
  require 'uri_template'
3
2
  require 'futuroscope'
4
3
 
@@ -18,6 +17,7 @@ module Hyperclient
18
17
  @link = link
19
18
  @entry_point = entry_point
20
19
  @uri_variables = uri_variables
20
+ @resource = nil
21
21
  end
22
22
 
23
23
  # Public: Indicates if the link is an URITemplate or a regular URI.
@@ -167,9 +167,15 @@ module Hyperclient
167
167
 
168
168
  def http_method(method, body = nil)
169
169
  @resource = begin
170
- response = Futuroscope::Future.new do
171
- @entry_point.connection.run_request(method, _url, body, nil)
172
- end
170
+ response =
171
+ if @entry_point.options[:async]
172
+ Futuroscope::Future.new do
173
+ @entry_point.connection.run_request(method, _url, body, nil)
174
+ end
175
+ else
176
+ @entry_point.connection.run_request(method, _url, body, nil)
177
+ end
178
+
173
179
  Resource.new(response.body, @entry_point, response)
174
180
  end
175
181
  end
@@ -1,7 +1,3 @@
1
- require 'hyperclient/collection'
2
- require 'hyperclient/link'
3
- require 'hyperclient/curie'
4
-
5
1
  module Hyperclient
6
2
  # Public: A wrapper class to easily acces the links in a Resource.
7
3
  #
@@ -19,7 +15,7 @@ module Hyperclient
19
15
  # curies - The Hash with link curies.
20
16
  # entry_point - The EntryPoint object to inject the configuration.
21
17
  def initialize(collection, curies, entry_point)
22
- fail "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)
18
+ raise "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)
23
19
 
24
20
  @_curies = (curies || {}).reduce({}) do |hash, curie_hash|
25
21
  curie = build_curie(curie_hash, entry_point)
@@ -1,7 +1,4 @@
1
1
  require 'forwardable'
2
- require 'hyperclient/attributes'
3
- require 'hyperclient/link_collection'
4
- require 'hyperclient/resource_collection'
5
2
 
6
3
  module Hyperclient
7
4
  # Public: Represents a resource from your API. Its responsability is to
@@ -65,7 +62,7 @@ module Hyperclient
65
62
  elsif block_given?
66
63
  yield key
67
64
  else
68
- fail KeyError
65
+ raise KeyError
69
66
  end
70
67
  end
71
68
 
@@ -1,6 +1,3 @@
1
- require 'hyperclient/collection'
2
- require 'hyperclient/resource'
3
-
4
1
  module Hyperclient
5
2
  # Public: A wrapper class to easily acces the embedded resources in a
6
3
  # Resource.
@@ -1,3 +1,3 @@
1
1
  module Hyperclient
2
- VERSION = '0.8.1'
2
+ VERSION = '0.8.2'.freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/attributes'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe Attributes do
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/resource'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe Collection do
@@ -1,6 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/curie'
3
- require 'hyperclient/entry_point'
2
+ require 'hyperclient'
4
3
 
5
4
  module Hyperclient
6
5
  describe Curie do
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/entry_point'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe EntryPoint do
@@ -56,6 +56,12 @@ module Hyperclient
56
56
  entry_point._url.must_equal 'http://my.api.org'
57
57
  end
58
58
  end
59
+
60
+ describe 'options' do
61
+ it 'enables the async option by default' do
62
+ entry_point.options[:async].must_equal true
63
+ end
64
+ end
59
65
  end
60
66
 
61
67
  describe 'faraday_options' do
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/link_collection'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe LinkCollection do
@@ -1,6 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/link'
3
- require 'hyperclient/entry_point'
2
+ require 'hyperclient'
4
3
 
5
4
  module Hyperclient
6
5
  describe Link do
@@ -164,6 +163,34 @@ module Hyperclient
164
163
 
165
164
  lambda { link._get }.must_raise Faraday::ClientError
166
165
  end
166
+
167
+ it 'executes requests asynchronously using futuroscope' do
168
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
169
+
170
+ stub_request(entry_point.connection) do |stub|
171
+ stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
172
+ end
173
+
174
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
175
+
176
+ link._get
177
+ end
178
+
179
+ describe 'when entry_point.options is set to { async: false }' do
180
+ it 'executes requests synchronously without futuroscope' do
181
+ entry_point.options = { async: false }
182
+
183
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
184
+
185
+ stub_request(entry_point.connection) do |stub|
186
+ stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
187
+ end
188
+
189
+ Futuroscope::Future.expects(:new).never
190
+
191
+ link._get
192
+ end
193
+ end
167
194
  end
168
195
 
169
196
  describe '_options' do
@@ -176,6 +203,34 @@ module Hyperclient
176
203
 
177
204
  link._options.must_be_kind_of Resource
178
205
  end
206
+
207
+ it 'executes requests asynchronously using futuroscope' do
208
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
209
+
210
+ stub_request(entry_point.connection) do |stub|
211
+ stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
212
+ end
213
+
214
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
215
+
216
+ link._options
217
+ end
218
+
219
+ describe 'when entry_point.options is set to { async: false }' do
220
+ it 'executes requests synchronously without futuroscope' do
221
+ entry_point.options = { async: false }
222
+
223
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
224
+
225
+ stub_request(entry_point.connection) do |stub|
226
+ stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
227
+ end
228
+
229
+ Futuroscope::Future.expects(:new).never
230
+
231
+ link._options
232
+ end
233
+ end
179
234
  end
180
235
 
181
236
  describe '_head' do
@@ -188,6 +243,34 @@ module Hyperclient
188
243
 
189
244
  link._head.must_be_kind_of Resource
190
245
  end
246
+
247
+ it 'executes requests asynchronously using futuroscope' do
248
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
249
+
250
+ stub_request(entry_point.connection) do |stub|
251
+ stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
252
+ end
253
+
254
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
255
+
256
+ link._head
257
+ end
258
+
259
+ describe 'when entry_point.options is set to { async: false }' do
260
+ it 'executes requests synchronously without futuroscope' do
261
+ entry_point.options = { async: false }
262
+
263
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
264
+
265
+ stub_request(entry_point.connection) do |stub|
266
+ stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
267
+ end
268
+
269
+ Futuroscope::Future.expects(:new).never
270
+
271
+ link._head
272
+ end
273
+ end
191
274
  end
192
275
 
193
276
  describe '_delete' do
@@ -200,6 +283,34 @@ module Hyperclient
200
283
 
201
284
  link._delete.must_be_kind_of Resource
202
285
  end
286
+
287
+ it 'executes requests asynchronously using futuroscope' do
288
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
289
+
290
+ stub_request(entry_point.connection) do |stub|
291
+ stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
292
+ end
293
+
294
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
295
+
296
+ link._delete
297
+ end
298
+
299
+ describe 'when entry_point.options is set to { async: false }' do
300
+ it 'executes requests synchronously without futuroscope' do
301
+ entry_point.options = { async: false }
302
+
303
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
304
+
305
+ stub_request(entry_point.connection) do |stub|
306
+ stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
307
+ end
308
+
309
+ Futuroscope::Future.expects(:new).never
310
+
311
+ link._delete
312
+ end
313
+ end
203
314
  end
204
315
 
205
316
  describe '_post' do
@@ -220,6 +331,34 @@ module Hyperclient
220
331
 
221
332
  link._post.must_be_kind_of Resource
222
333
  end
334
+
335
+ it 'executes requests asynchronously using futuroscope' do
336
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
337
+
338
+ stub_request(entry_point.connection) do |stub|
339
+ stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
340
+ end
341
+
342
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
343
+
344
+ link._post
345
+ end
346
+
347
+ describe 'when entry_point.options is set to { async: false }' do
348
+ it 'executes requests synchronously without futuroscope' do
349
+ entry_point.options = { async: false }
350
+
351
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
352
+
353
+ stub_request(entry_point.connection) do |stub|
354
+ stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
355
+ end
356
+
357
+ Futuroscope::Future.expects(:new).never
358
+
359
+ link._post
360
+ end
361
+ end
223
362
  end
224
363
 
225
364
  describe '_put' do
@@ -240,6 +379,34 @@ module Hyperclient
240
379
 
241
380
  link._put.must_be_kind_of Resource
242
381
  end
382
+
383
+ it 'executes requests asynchronously using futuroscope' do
384
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
385
+
386
+ stub_request(entry_point.connection) do |stub|
387
+ stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
388
+ end
389
+
390
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
391
+
392
+ link._put
393
+ end
394
+
395
+ describe 'when entry_point.options is set to { async: false }' do
396
+ it 'executes requests synchronously without futuroscope' do
397
+ entry_point.options = { async: false }
398
+
399
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
400
+
401
+ stub_request(entry_point.connection) do |stub|
402
+ stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
403
+ end
404
+
405
+ Futuroscope::Future.expects(:new).never
406
+
407
+ link._put
408
+ end
409
+ end
243
410
  end
244
411
 
245
412
  describe '_patch' do
@@ -260,6 +427,34 @@ module Hyperclient
260
427
 
261
428
  link._patch.must_be_kind_of Resource
262
429
  end
430
+
431
+ it 'executes requests asynchronously using futuroscope' do
432
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
433
+
434
+ stub_request(entry_point.connection) do |stub|
435
+ stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
436
+ end
437
+
438
+ Futuroscope::Future.expects(:new).returns(stub(body: nil))
439
+
440
+ link._patch
441
+ end
442
+
443
+ describe 'when entry_point.options is set to { async: false }' do
444
+ it 'executes requests synchronously without futuroscope' do
445
+ entry_point.options = { async: false }
446
+
447
+ link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
448
+
449
+ stub_request(entry_point.connection) do |stub|
450
+ stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
451
+ end
452
+
453
+ Futuroscope::Future.expects(:new).never
454
+
455
+ link._patch
456
+ end
457
+ end
263
458
  end
264
459
 
265
460
  describe 'inspect' do
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/resource_collection'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe ResourceCollection do
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
- require 'hyperclient/resource'
2
+ require 'hyperclient'
3
3
 
4
4
  module Hyperclient
5
5
  describe Resource do
data/test/test_helper.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  $LOAD_PATH << 'lib'
2
- gem 'minitest'
3
2
 
4
3
  require 'minitest/spec'
5
4
  require 'minitest/autorun'
6
5
  require 'mocha/setup'
7
6
  require 'turn'
8
7
  require 'json'
9
- require 'pry'
10
8
 
11
9
  MiniTest::Unit::TestCase.class_eval do
12
10
  def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
@@ -14,3 +12,7 @@ MiniTest::Unit::TestCase.class_eval do
14
12
  conn.builder.swap(adapter_handler, adapter_class, &stubs_block)
15
13
  end
16
14
  end
15
+
16
+ require 'futuroscope'
17
+ require 'futuroscope/pools/no_pool'
18
+ Futuroscope.default_pool = Futuroscope::Pools::NoPool.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oriol Gual
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -108,90 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: minitest
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: turn
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: webmock
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
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: mocha
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rack-test
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: spinach
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
111
  description: HyperClient is a Ruby Hypermedia API client.
196
112
  email:
197
113
  - oriol.gual@gmail.com
@@ -206,6 +122,7 @@ files:
206
122
  - ".yardopts"
207
123
  - CHANGELOG.md
208
124
  - CONTRIBUTING.md
125
+ - Dangerfile
209
126
  - Gemfile
210
127
  - Guardfile
211
128
  - LICENSE
@@ -266,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
183
  version: '0'
267
184
  requirements: []
268
185
  rubyforge_project:
269
- rubygems_version: 2.4.6
186
+ rubygems_version: 2.5.1
270
187
  signing_key:
271
188
  specification_version: 4
272
189
  summary: ''
@@ -292,4 +209,3 @@ test_files:
292
209
  - test/hyperclient/resource_test.rb
293
210
  - test/hyperclient_test.rb
294
211
  - test/test_helper.rb
295
- has_rdoc: