grac 2.0.3 → 2.1.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: 7fe42ef3ce727ab81a2c43b7a533d6796a22d13b
4
- data.tar.gz: bd2cef82ac90fd4cd19a1e1150a2ec0d15c4fc92
3
+ metadata.gz: 2b7388a3893226c18a95cf03b7f9c11dada6f6bc
4
+ data.tar.gz: 617dd5a6f749929bbe26277bfd0ae9b26fe91091
5
5
  SHA512:
6
- metadata.gz: a2e94ebfada36c24be7af68a0c1c087d541aea63911d809b107dc0940f7b1defcdef5eb9cb14307756b418b0edecac3e217c162e9e48189b051cafff6da61180
7
- data.tar.gz: 6cf05bd411ae8e12a3234d6e6e8ea218a2f1f14d6764b1e2eb5141936b629199ab74fc3517e89172dd6e3f4191f1d1ecd2072442c59dbc55c9ff6196da247739
6
+ metadata.gz: bf132d0ea4f5d427c36b79c5a3fa124bad63990eef29e8974252b09658cc78e6e3c0df9e95ed914cb9416a144569a942bccdf7a57c25f2076e19c055324640f0
7
+ data.tar.gz: b1dc8341930b7352ff18484f0591c038fc8d4269915195b69b340cbb50bf8a802448f83e9a0c43a18d63e1b30bca32be489d517952d195677ee18c74c81be13c
@@ -18,13 +18,20 @@ module Grac
18
18
  :timeout => options[:timeout] || 15,
19
19
  :params => options[:params] || {},
20
20
  :headers => { "User-Agent" => "Grac v#{Grac::VERSION}" }.merge(options[:headers] || {}),
21
- :postprocessing => options[:postprocessing] || {}
21
+ :postprocessing => options[:postprocessing] || {},
22
+ :middleware => options[:middleware] || []
22
23
  }
24
+ @options.freeze
25
+ [:params, :headers, :postprocessing, :middleware].each do |k|
26
+ @options[k].freeze
27
+ end
28
+ @uri.freeze
23
29
  end
24
30
 
25
31
  def set(options = {})
26
32
  options = options.merge({
27
- headers: @options[:headers].merge(options[:headers] || {})
33
+ headers: @options[:headers].merge(options[:headers] || {}),
34
+ middleware: @options[:middleware] + (options[:middleware] || [])
28
35
  })
29
36
 
30
37
  self.class.new(@uri, @options.merge(options))
@@ -53,16 +60,24 @@ module Grac
53
60
 
54
61
  private
55
62
  def build_request(method, options = {})
56
- body = options[:body].nil? || options[:body].empty? ? nil : options[:body].to_json
63
+ body = options[:body].nil? || options[:body].empty? ? nil : options[:body].to_json
64
+ params = @options[:params].merge(options[:params] || {})
65
+
66
+ opts = @options
67
+ request_uri = uri
68
+
69
+ @options[:middleware].each do |mw|
70
+ opts, request_uri, method, params, body = mw.call(opts, request_uri, method, params, body)
71
+ end
57
72
 
58
73
  request_hash = { :method => method }
59
- request_hash[:params] = @options[:params].merge(options[:params] || {})
74
+ request_hash[:params] = params
60
75
  request_hash[:body] = body
61
- request_hash[:connecttimeout] = @options[:connecttimeout]
62
- request_hash[:timeout] = @options[:timeout]
63
- request_hash[:headers] = @options[:headers]
76
+ request_hash[:connecttimeout] = opts[:connecttimeout]
77
+ request_hash[:timeout] = opts[:timeout]
78
+ request_hash[:headers] = opts[:headers]
64
79
 
65
- return ::Typhoeus::Request.new(uri, request_hash)
80
+ return ::Typhoeus::Request.new(request_uri, request_hash)
66
81
  end
67
82
 
68
83
  def postprocessing(data, processing = nil)
@@ -1,3 +1,3 @@
1
1
  module Grac
2
- VERSION = "2.0.3"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grac
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.2.2
129
+ rubygems_version: 2.4.6
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Very generic client for REST API with basic error handling