rest-core 3.5.6 → 3.5.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22b1bd4e98e62b8b87bbe2021020e0fc3897d429
4
- data.tar.gz: 15f1a45e675881ad5a2de3c10fd56ffd2d0837e3
3
+ metadata.gz: 92e289bb3e825b93385443dade7adf26959b90b8
4
+ data.tar.gz: 5861deec728b6d154f582702c5b2643ad7797b07
5
5
  SHA512:
6
- metadata.gz: ecf7a1ec80da7bc369bd49985f5c43eac6c298050f7b2777790c170e2f80cf0062725320a41efe268605faaab212f34c84b662bd563195c561dfd900d25f92d4
7
- data.tar.gz: d4203a3a72e2c511d4e0b0312942e9155dc5ef440c8e4de76ef45a8ee1e16660a69aad3c0b8e4d38cb5688d9926db466b193932b27999365b1d74138d3f30d2f
6
+ metadata.gz: 6a33744abd434667196c62f2066c0fecfa0315d0d397239964d16d13d7726cd94d0aa98dc3581924e84912decbb6f32040106d42cdeaafd5b962d3ba75382c94
7
+ data.tar.gz: d6f3fe16efe1d82931cbb88cd9053509e2ca064e7d693365d963c5aefe154ef04e8e08d154aa3b79c4f4f3035e3795c6e14022d526a03a9624cdeff84e5e06c1
data/CHANGES.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-core 3.5.7 -- 2015-09-10
4
+
5
+ ### Incompatible changes
6
+
7
+ * JSON_REQUEST_METHOD was removed.
8
+
9
+ ### Bugs fixed
10
+
11
+ * GET/DELETE/HEAD/OPTIONS would no longer try to attach any payload.
12
+
13
+ ### Enhancements
14
+
15
+ * Introduced Middleware.has_payload? which would detect if the request
16
+ should attach a payload or not.
17
+
3
18
  ## rest-core 3.5.6 -- 2015-07-23
4
19
 
5
20
  ### Bugs fixed
@@ -15,7 +15,12 @@ class RestCore::Engine
15
15
 
16
16
  private
17
17
  def payload_and_headers env
18
- Payload.generate_with_headers(env[REQUEST_PAYLOAD], env[REQUEST_HEADERS])
18
+ if has_payload?(env)
19
+ Payload.generate_with_headers(env[REQUEST_PAYLOAD],
20
+ env[REQUEST_HEADERS])
21
+ else
22
+ [{}, env[REQUEST_HEADERS]]
23
+ end
19
24
  end
20
25
 
21
26
  def normalize_headers headers
@@ -4,6 +4,7 @@ require 'rest-core'
4
4
 
5
5
  module RestCore::Middleware
6
6
  include RestCore
7
+ METHODS_WITH_PAYLOAD = [:post, :put, :patch]
7
8
 
8
9
  def self.included mod
9
10
  mod.send(:include, RestCore)
@@ -96,6 +97,11 @@ module RestCore::Middleware
96
97
  end
97
98
  public :escape
98
99
 
100
+ def has_payload? env
101
+ METHODS_WITH_PAYLOAD.include?(env[REQUEST_METHOD])
102
+ end
103
+ public :has_payload?
104
+
99
105
  def contain_binary? payload
100
106
  return false unless payload
101
107
  return true if payload.respond_to?(:read)
@@ -7,12 +7,10 @@ class RestCore::JsonRequest
7
7
  include RestCore::Middleware
8
8
 
9
9
  JSON_REQUEST_HEADER = {'Content-Type' => 'application/json'}.freeze
10
- JSON_REQUEST_METHOD = [:post, :put, :patch]
11
10
 
12
11
  def call env, &k
13
12
  return app.call(env, &k) unless json_request(env)
14
- return app.call(env, &k) unless
15
- JSON_REQUEST_METHOD.include?(env[REQUEST_METHOD])
13
+ return app.call(env, &k) unless has_payload?(env)
16
14
 
17
15
  app.call(env.merge(
18
16
  REQUEST_HEADERS => JSON_REQUEST_HEADER.merge(env[REQUEST_HEADERS]||{}),
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestCore
3
- VERSION = '3.5.6'
3
+ VERSION = '3.5.7'
4
4
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-core 3.5.6 ruby lib
2
+ # stub: rest-core 3.5.7 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rest-core"
6
- s.version = "3.5.6"
6
+ s.version = "3.5.7"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2015-07-23"
11
+ s.date = "2015-09-10"
12
12
  s.description = "Modular Ruby clients interface for REST APIs.\n\nThere has been an explosion in the number of REST APIs available today.\nTo address the need for a way to access these APIs easily and elegantly,\nwe have developed rest-core, which consists of composable middleware\nthat allows you to build a REST client for any REST API. Or in the case of\ncommon APIs such as Facebook, Github, and Twitter, you can simply use the\ndedicated clients provided by [rest-more][].\n\n[rest-more]: https://github.com/godfat/rest-more"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.files = [
@@ -79,6 +79,11 @@ module Gemgem
79
79
  end
80
80
 
81
81
  def gem_check
82
+ unless git('status', '--porcelain').empty?
83
+ puts("\e[35mWorking copy is not clean.\e[0m")
84
+ exit(3)
85
+ end
86
+
82
87
  ver = spec.version.to_s
83
88
 
84
89
  if ENV['VERSION'].nil?
@@ -8,6 +8,22 @@ describe RC::Universal do
8
8
  WebMock.reset!
9
9
  end
10
10
 
11
+ would 'only send payload for post, put, patch' do
12
+ c = RC::Universal.new(:log_method => false, :payload => '$payload')
13
+ [:get, :delete, :head, :options].each do |method|
14
+ stub_request(method, url)
15
+ c.send(method, url).tap{}
16
+ assert_requested(method, url, :body => nil)
17
+ end
18
+
19
+ [:put, :post, :patch].each do |method|
20
+ stub_request(method, url).with(:body => '$payload')
21
+ c.send(method, url).tap{}
22
+ assert_requested(method, url, :body => '$payload')
23
+ end
24
+ ok
25
+ end
26
+
11
27
  would 'send Authorization header' do
12
28
  u = RC::Universal.new(:log_method => false)
13
29
  u.username = 'Aladdin'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.6
4
+ version: 3.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient