evil-client 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -18
  3. data/CHANGELOG.md +16 -1
  4. data/README.md +17 -15
  5. data/evil-client.gemspec +1 -1
  6. data/lib/evil/client/connection.rb +1 -5
  7. data/lib/evil/client/connection/net_http.rb +1 -1
  8. data/lib/evil/client/dsl.rb +11 -0
  9. data/lib/evil/client/dsl/base.rb +26 -0
  10. data/lib/evil/client/dsl/headers.rb +16 -0
  11. data/lib/evil/client/dsl/http_method.rb +24 -0
  12. data/lib/evil/client/dsl/operation.rb +8 -20
  13. data/lib/evil/client/dsl/operations.rb +3 -3
  14. data/lib/evil/client/dsl/path.rb +25 -0
  15. data/lib/evil/client/dsl/query.rb +16 -0
  16. data/lib/evil/client/dsl/verifier.rb +35 -0
  17. data/lib/evil/client/middleware/base.rb +2 -6
  18. data/lib/evil/client/middleware/merge_security.rb +4 -0
  19. data/lib/evil/client/middleware/normalize_headers.rb +4 -0
  20. data/lib/evil/client/middleware/stringify_form.rb +4 -0
  21. data/lib/evil/client/middleware/stringify_json.rb +4 -0
  22. data/lib/evil/client/middleware/stringify_multipart.rb +4 -0
  23. data/lib/evil/client/middleware/stringify_query.rb +4 -0
  24. data/lib/evil/client/operation.rb +2 -2
  25. data/lib/evil/client/operation/request.rb +8 -19
  26. data/spec/features/middleware_spec.rb +15 -9
  27. data/spec/features/operation_with_path_spec.rb +3 -3
  28. data/spec/unit/evil/client/dsl/operation_spec.rb +1 -1
  29. data/spec/unit/evil/client/dsl/operations_spec.rb +1 -1
  30. data/spec/unit/evil/client/middleware/merge_security_spec.rb +2 -2
  31. data/spec/unit/evil/client/middleware/normalize_headers_spec.rb +2 -2
  32. data/spec/unit/evil/client/middleware/stringify_form_spec.rb +2 -2
  33. data/spec/unit/evil/client/middleware/stringify_json_spec.rb +2 -2
  34. data/spec/unit/evil/client/middleware/stringify_multipart_spec.rb +2 -2
  35. data/spec/unit/evil/client/middleware/stringify_query_spec.rb +1 -1
  36. data/spec/unit/evil/client/operation/request_spec.rb +1 -1
  37. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1993a11c6b8086dec9802e02c4beeb56e8aadef3
4
- data.tar.gz: 273f6c22939793760abc5bbae79681c03490116b
3
+ metadata.gz: 792691363738b2a89d8579cfcdd33e95fcf496bd
4
+ data.tar.gz: 5477063a34c23b048748d2a47d9f256f17a9a025
5
5
  SHA512:
6
- metadata.gz: 2d639bf5c2a2e8e1362df945d6416cc012052ea653ee8103eaeb7548c9e733aeaa400e3d7fa3c6eafee617a496c6edcfc581e22eb2dca31f003c175c716cca1b
7
- data.tar.gz: 07011a575fdbbe193f280fe2cc68c0556547092b752fa617f5d40e1524bb26ee30b207efe4d98f217e1a38997772c8889cc5014ff026be35122e89338e822507
6
+ metadata.gz: 586b7861e76d8e6f56bdd8f1668cad0e25ba75fd4247dd4e5e810ece64999e882b555b039a194c5c97d80280c46cd49d71ae78d23c83ba87758f59574a762008
7
+ data.tar.gz: 5eaada81c8761c9c4bbe40a9be0fc4bb1006b6fea7501a8cd3162ccab6229f03f20c4b7dde6aaff4dc073406be7582ff33c3f6d75219dd110d02d5746fa66038
data/.rubocop.yml CHANGED
@@ -5,16 +5,16 @@ AllCops:
5
5
  StyleGuideCopsOnly: true
6
6
  TargetRubyVersion: 2.3
7
7
 
8
- Style/Alias:
8
+ Style/CaseEquality:
9
+ Enabled: false
10
+
11
+ Style/Documentation:
9
12
  Enabled: false
10
13
 
11
14
  Style/FileName:
12
15
  Exclude:
13
16
  - lib/evil-client.rb
14
17
 
15
- Style/Documentation:
16
- Enabled: false
17
-
18
18
  Style/LambdaCall:
19
19
  Enabled: false
20
20
 
@@ -34,19 +34,5 @@ Style/RaiseArgs:
34
34
  Style/RescueModifier:
35
35
  Enabled: false
36
36
 
37
- Style/SingleLineBlockParams:
38
- Enabled: false
39
-
40
- Style/SingleLineMethods:
41
- Exclude:
42
- - spec/**.rb
43
-
44
37
  Style/StringLiterals:
45
38
  EnforcedStyle: double_quotes
46
-
47
- Style/StringLiteralsInInterpolation:
48
- EnforcedStyle: double_quotes
49
-
50
- Style/SymbolProc:
51
- Exclude:
52
- - spec/**.rb
data/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
- # v0.3.1 2016-11-20
1
+ # v0.3.2 2016-11-29
2
+
3
+ On the road to v0.4.0
4
+
5
+ ## Fixed
6
+ - Query and body encoding (nepalez)
7
+
8
+ ## Internal
9
+ - Refactoring of some DSL classes (nepalez)
10
+
11
+ [Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-initializer/compare/v0.3.1...v0.3.2)
12
+
13
+ # v0.3.1 2016-11-22
14
+
15
+ ## Fixed
16
+ - Loading of 'json' from stdlib (nepalez)
2
17
 
3
18
  ## Internal
4
19
  - Class `Evil::Client::Model` is extracted to `evil-struct` gem (nepalez)
data/README.md CHANGED
@@ -20,8 +20,8 @@ The gem stands away from mutable states and monkey patching when possible. To su
20
20
  For now the DSL supports clients to **json** and **form data** APIs out of the box. Because of high variance of XML-based APIs, building corresponding clients require more efforts on a middleware level.
21
21
 
22
22
  [swagger]: http://swagger.io
23
- [dry-initializer]: http://dry-rb.org/gems./dry-initializer
24
- [dry-types]: http://dry-rb.org/gems./dry-types
23
+ [dry-initializer]: http://dry-rb.org/gems/dry-initializer
24
+ [dry-types]: http://dry-rb.org/gems/dry-types
25
25
 
26
26
  ## Installation
27
27
 
@@ -52,20 +52,20 @@ require "evil-client"
52
52
  require "dry-types"
53
53
 
54
54
  class CatsClient < Evil::Client
55
- # describe a client-specific model of cat (the furry pinnacle of evolution)
55
+ # Prepare client-specific model of cat (the furry pinnacle of evolution)
56
56
  class Cat < Evil::Struct
57
- attribute :name, type: Dry::Types["strict.string"], optional: true
58
- attribute :color, type: Dry::Types["strict.string"]
59
- attribute :age, type: Dry::Types["coercible.int"], default: proc { 0 }
57
+ attribute :name, Dry::Types["strict.string"], optional: true
58
+ attribute :color, Dry::Types["strict.string"]
59
+ attribute :age, Dry::Types["coercible.int"], default: proc { 0 }
60
60
  end
61
61
 
62
62
  # Define settings the client initialized with
63
63
  # The settings parameterizes operations when necessary
64
64
  settings do
65
- param :domain, type: Dry::Types["strict.string"] # required!
66
- option :version, type: Dry::Types["coercible.int"], default: proc { 0 }
67
- option :user, type: Dry::Types["strict.string"] # required!
68
- option :password, type: Dry::Types["strict.string"] # required!
65
+ param :domain, Dry::Types["strict.string"] # required!
66
+ option :version, Dry::Types["coercible.int"], default: proc { 0 }
67
+ option :user, Dry::Types["strict.string"] # required!
68
+ option :password, Dry::Types["strict.string"] # required!
69
69
  end
70
70
 
71
71
  # Define a base url using
@@ -85,15 +85,17 @@ class CatsClient < Evil::Client
85
85
  path { |id:, **| "cats/#{id}" } # id will be taken from request parameters
86
86
 
87
87
  body format: "json" do
88
- attribute :name, optional: true
89
- attribute :color, optional: true
90
- attribute :age, optional: true
88
+ attributes optional: true do
89
+ attribute :name
90
+ attribute :color
91
+ attribute :age
92
+ end
91
93
  end
92
94
 
93
95
  # Parses json response and wraps it into Cat instance with additional
94
96
  # parameter
95
- response 200, format: :json, type: Cat do
96
- attribute :success
97
+ response 200, format: :json, model: Cat do
98
+ attribute :success # add response-specific attribute to the cat
97
99
  end
98
100
 
99
101
  # Parses json response, wraps it into model with [#error] and raises
data/evil-client.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "evil-client"
3
- gem.version = "0.3.1"
3
+ gem.version = "0.3.2"
4
4
  gem.author = ["Andrew Kozin (nepalez)", "Ravil Bairamgalin (brainopia)"]
5
5
  gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/evilmartians/evil-client"
@@ -24,11 +24,7 @@ class Evil::Client
24
24
  end
25
25
 
26
26
  # @abstract Sends request to the server and returns rack-compatible response
27
- #
28
- # @param [Hash] env
29
- # @return [Array]
30
- #
31
- def call(_env)
27
+ def call(_env, *)
32
28
  raise NotImplementedError
33
29
  end
34
30
  end
@@ -12,7 +12,7 @@ class Evil::Client
12
12
  # :http_method, :path, :query_string, :body_string, :headers
13
13
  # @return [Array] Rack-compatible response [status, body, headers]
14
14
  #
15
- def call(env)
15
+ def call(env, *)
16
16
  request = build_request(env)
17
17
  Net::HTTP.start base_uri.host, base_uri.port, opts do |http|
18
18
  handle http.request(request)
@@ -1,6 +1,17 @@
1
1
  class Evil::Client
2
2
  # Defines a DSL to customize class-level settings of the specific client
3
3
  module DSL
4
+ require_relative "dsl/base"
5
+ require_relative "dsl/files"
6
+ require_relative "dsl/headers"
7
+ require_relative "dsl/http_method"
8
+ require_relative "dsl/path"
9
+ require_relative "dsl/query"
10
+ require_relative "dsl/response"
11
+ require_relative "dsl/responses"
12
+ require_relative "dsl/security"
13
+ require_relative "dsl/verifier"
14
+ require_relative "dsl/operation"
4
15
  require_relative "dsl/operations"
5
16
  require_relative "dsl/scope"
6
17
 
@@ -0,0 +1,26 @@
1
+ module Evil::Client::DSL
2
+ class Base
3
+ def self.[](schema, *args, &block)
4
+ new(*args, &block).call(schema)
5
+ end
6
+
7
+ def call(schema)
8
+ schema
9
+ end
10
+
11
+ private
12
+
13
+ def merge(source, target)
14
+ target.inject(source) do |obj, (key, val)|
15
+ obj.merge key => (Hash === val ? merge(obj.fetch(key, {}), val) : val)
16
+ end
17
+ end
18
+
19
+ def coercer
20
+ @coercer ||= if @model && @block then Class.new(@model, &@block)
21
+ elsif @block then Class.new(Evil::Struct, &@block)
22
+ elsif @model then @model
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Evil::Client::DSL
2
+ class Headers < Base
3
+ def call(schema)
4
+ merge schema, headers: coercer
5
+ end
6
+
7
+ private
8
+
9
+ attr_reader :model, :block
10
+
11
+ def initialize(model: Evil::Struct, &block)
12
+ @model = model
13
+ @block = block
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module Evil::Client::DSL
2
+ class HttpMethod < Base
3
+ def call(schema)
4
+ merge schema, method: http_method
5
+ end
6
+
7
+ private
8
+
9
+ attr_reader :block, :string
10
+
11
+ def initialize(string = nil, &block)
12
+ @string = string.to_s.downcase
13
+ @block = block
14
+ end
15
+
16
+ def http_method
17
+ if block
18
+ ->(opts) { block.call(opts).to_s.downcase }
19
+ else
20
+ proc { string }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,19 +1,7 @@
1
1
  module Evil::Client::DSL
2
- require_relative "security"
3
- require_relative "files"
4
- require_relative "response"
5
- require_relative "responses"
6
-
7
- # Builds a schema for single operation
8
2
  class Operation
9
3
  attr_reader :schema
10
4
 
11
- # Builds a schema for a single operation
12
- #
13
- # @param [Object] settings
14
- # @param [Proc] block A block of definitions (should accept settings)
15
- # @return [Hash<Symbol, Object>]
16
- #
17
5
  def finalize(settings)
18
6
  @mutex.synchronize do
19
7
  @schema = @default.dup
@@ -39,12 +27,12 @@ module Evil::Client::DSL
39
27
  @schema[:doc] = value
40
28
  end
41
29
 
42
- def http_method(value)
43
- @schema[:method] = value.to_s.downcase
30
+ def http_method(value = nil, &block)
31
+ @schema = HttpMethod[schema, value, &block]
44
32
  end
45
33
 
46
- def path
47
- @schema[:path] = ->(**opts) { yield(opts).gsub(%r{\A/+|/+\z}, "") }
34
+ def path(value = nil, &block)
35
+ @schema = Path[schema, value, &block]
48
36
  end
49
37
 
50
38
  def security(&block)
@@ -63,12 +51,12 @@ module Evil::Client::DSL
63
51
  @schema.delete :files
64
52
  end
65
53
 
66
- def headers(**options, &block)
67
- @schema[:headers] = __model__(options, &block)
54
+ def headers(model: Evil::Struct, &block)
55
+ @schema = Headers[schema, model: model, &block]
68
56
  end
69
57
 
70
- def query(**options, &block)
71
- @schema[:query] = __model__(options, &block)
58
+ def query(model: Evil::Struct, &block)
59
+ @schema = Query[schema, model: model, &block]
72
60
  end
73
61
 
74
62
  def responses(options = {}, &block)
@@ -1,6 +1,4 @@
1
1
  module Evil::Client::DSL
2
- require_relative "operation"
3
-
4
2
  # Container for operations definitions
5
3
  # Applies settings to definitions and returns a final schema
6
4
  class Operations
@@ -24,12 +22,14 @@ module Evil::Client::DSL
24
22
  default = @schema[nil].finalize(settings)
25
23
  custom = @schema.select { |key| key }
26
24
 
27
- custom.each_with_object({}) do |(key, operation), hash|
25
+ schema = custom.each_with_object({}) do |(key, operation), hash|
28
26
  custom = operation.finalize(settings)
29
27
  hash[key] = default.merge(custom)
30
28
  hash[key][:format] ||= "json"
31
29
  hash[key][:responses] = default[:responses].merge(custom[:responses])
32
30
  end
31
+
32
+ Verifier.call(schema)
33
33
  end
34
34
 
35
35
  private
@@ -0,0 +1,25 @@
1
+ module Evil::Client::DSL
2
+ # Adds path settings to the operation's schema
3
+ class Path < Base
4
+ def call(schema)
5
+ merge schema, path: path
6
+ end
7
+
8
+ private
9
+
10
+ SLASHES = %r{\A/+|/+\z}
11
+
12
+ attr_reader :block, :value
13
+
14
+ def initialize(value = nil, &block)
15
+ @value = value.to_s.gsub(SLASHES, "")
16
+ @block = block
17
+ end
18
+
19
+ def path
20
+ if block then ->(opts) { block.call(opts).to_s.gsub(SLASHES, "") }
21
+ else ->(_) { value }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module Evil::Client::DSL
2
+ class Query < Base
3
+ def call(schema)
4
+ merge schema, query: coercer
5
+ end
6
+
7
+ private
8
+
9
+ attr_reader :model, :block
10
+
11
+ def initialize(model: nil, &block)
12
+ @model = model
13
+ @block = block
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ module Evil::Client::DSL
2
+ SchemaError = Class.new(StandardError)
3
+
4
+ # Verifies a final schema
5
+ class Verifier
6
+ def self.call(schema)
7
+ new(schema).call
8
+ end
9
+
10
+ def call
11
+ @schema.each do |key, schema|
12
+ check_path(key, schema)
13
+ check_method(key, schema)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def initialize(schema)
20
+ @schema = schema
21
+ end
22
+
23
+ def check_path(key, schema)
24
+ return if schema[:path]
25
+ raise SchemaError,
26
+ "Path definition is missed for operation :#{key}"
27
+ end
28
+
29
+ def check_method(key, schema)
30
+ return if schema[:method]
31
+ raise SchemaError,
32
+ "HTTP method definition is missed for operation :#{key}"
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  class Evil::Client::Middleware::Base
2
- def call(env)
3
- @app.call build(env)
2
+ def call(env, schema, options)
3
+ @app.call(env, schema, options)
4
4
  end
5
5
 
6
6
  private
@@ -8,8 +8,4 @@ class Evil::Client::Middleware::Base
8
8
  def initialize(app)
9
9
  @app = app
10
10
  end
11
-
12
- def build(env)
13
- env
14
- end
15
11
  end
@@ -1,5 +1,9 @@
1
1
  class Evil::Client::Middleware
2
2
  class MergeSecurity < Base
3
+ def call(env, schema, options)
4
+ super build(env), schema, options
5
+ end
6
+
3
7
  private
4
8
 
5
9
  def build(env)
@@ -1,5 +1,9 @@
1
1
  class Evil::Client::Middleware
2
2
  class NormalizeHeaders < Base
3
+ def call(env, schema, options)
4
+ super build(env), schema, options
5
+ end
6
+
3
7
  private
4
8
 
5
9
  def build(env)
@@ -1,5 +1,9 @@
1
1
  class Evil::Client::Middleware
2
2
  class StringifyForm < Base
3
+ def call(env, schema, options)
4
+ super build(env), schema, options
5
+ end
6
+
3
7
  private
4
8
 
5
9
  def build(env)
@@ -1,5 +1,9 @@
1
1
  class Evil::Client::Middleware
2
2
  class StringifyJson < Base
3
+ def call(env, schema, options)
4
+ super build(env), schema, options
5
+ end
6
+
3
7
  private
4
8
 
5
9
  def build(env)
@@ -2,6 +2,10 @@ class Evil::Client::Middleware
2
2
  class StringifyMultipart < Base
3
3
  require_relative "stringify_multipart/part"
4
4
 
5
+ def call(env, schema, options)
6
+ super build(env), schema, options
7
+ end
8
+
5
9
  private
6
10
 
7
11
  def build(env)
@@ -1,5 +1,9 @@
1
1
  class Evil::Client::Middleware
2
2
  class StringifyQuery < Base
3
+ def call(env, schema, options)
4
+ super build(env), schema, options
5
+ end
6
+
3
7
  private
4
8
 
5
9
  def build(env)
@@ -16,8 +16,8 @@ class Evil::Client
16
16
  # @return [Object]
17
17
  #
18
18
  def call(**options)
19
- req = request.build(options)
20
- array = connection.call(req)
19
+ env = request.build(options)
20
+ array = connection.call(env, schema, options)
21
21
  response.handle(array)
22
22
  end
23
23
 
@@ -12,26 +12,15 @@ class Evil::Client::Operation
12
12
  #
13
13
  def build(options)
14
14
  {
15
- format: schema[:format],
16
- http_method: extract(:method),
17
- path: extract(:path).call(options),
18
- security: schema[:security]&.call(options),
19
- files: schema[:files]&.call(options),
20
- query: schema[:query]&.new(options).to_h,
21
- body: schema[:body]&.new(options).to_h,
22
- headers: schema[:headers]&.new(options).to_h
15
+ format: schema[:format],
16
+ http_method: schema[:method].call(options),
17
+ path: schema[:path].call(options),
18
+ security: schema[:security]&.call(options),
19
+ files: schema[:files]&.call(options),
20
+ query: schema[:query]&.new(options).to_h,
21
+ body: schema[:body]&.new(options).to_h,
22
+ headers: schema[:headers]&.new(options).to_h
23
23
  }
24
24
  end
25
-
26
- private
27
-
28
- def key
29
- @key ||= schema[:key]
30
- end
31
-
32
- def extract(property)
33
- return schema[property] if schema[property]
34
- raise NotImplementedError, "No #{property} defined for operation '#{key}'"
35
- end
36
25
  end
37
26
  end
@@ -5,13 +5,17 @@ RSpec.describe "middleware" do
5
5
  @app = app
6
6
  end
7
7
 
8
- def call(_env)
9
- @app.call path: "data/1",
10
- http_method: "get",
11
- format: "form",
12
- headers: { "baz" => "BAZ" },
13
- query: { "bar" => "baz" },
14
- body: { "qux" => 2 }
8
+ def call(_env, schema, options)
9
+ env = {
10
+ path: "data/1",
11
+ http_method: "get",
12
+ format: "form",
13
+ headers: { "baz" => "BAZ" },
14
+ query: { "bar" => "baz" },
15
+ body: { "qux" => 2 }
16
+ }
17
+
18
+ @app.call env, schema, options
15
19
  end
16
20
  end
17
21
 
@@ -20,8 +24,10 @@ RSpec.describe "middleware" do
20
24
  @app = app
21
25
  end
22
26
 
23
- def call(env)
24
- @app.call(env).tap { |rack_response| rack_response[2] = ["Hi!"] }
27
+ def call(env, *params)
28
+ response = @app.call(env, *params)
29
+ response[2] = ["Hi!"]
30
+ response
25
31
  end
26
32
  end
27
33
 
@@ -4,8 +4,8 @@ RSpec.describe "operation with path" do
4
4
  class Test::Client < Evil::Client
5
5
  operation do
6
6
  http_method :get
7
- path { "users" }
8
- response :success, 200
7
+ path "users"
8
+ response :success, 200
9
9
  end
10
10
 
11
11
  operation :find_users
@@ -15,7 +15,7 @@ RSpec.describe "operation with path" do
15
15
  end
16
16
 
17
17
  operation :login do |settings|
18
- path { "login/#{settings.token}" }
18
+ path "login/#{settings.token}"
19
19
  end
20
20
  end
21
21
 
@@ -27,7 +27,7 @@ RSpec.describe Evil::Client::DSL::Operation do
27
27
  end
28
28
 
29
29
  it "defines :method" do
30
- expect(subject[:method]).to eq "post"
30
+ expect(subject[:method].call).to eq "post"
31
31
  end
32
32
  end
33
33
 
@@ -21,7 +21,7 @@ describe Evil::Client::DSL::Operations do
21
21
  it "builds a proper schema" do
22
22
  find_user = subject[:find_user]
23
23
 
24
- expect(find_user[:method]).to eq "get"
24
+ expect(find_user[:method].call).to eq "get"
25
25
  expect(find_user[:path].call(id: 7)).to eq "users/7"
26
26
  expect(find_user[:security].call)
27
27
  .to eq headers: { "authorization" => "Basic Zm9vOmJhcg==" }
@@ -6,8 +6,8 @@ RSpec.describe Evil::Client::Middleware::MergeSecurity do
6
6
  @result = env
7
7
  end
8
8
 
9
- before { allow(app).to receive(:call) { |env| update! env } }
10
- subject { stack.call env }
9
+ before { allow(app).to receive(:call) { |env, *| update! env } }
10
+ subject { stack.call env, {}, {} }
11
11
 
12
12
  let(:env) do
13
13
  {
@@ -7,8 +7,8 @@ RSpec.describe Evil::Client::Middleware::NormalizeHeaders do
7
7
  @result = env
8
8
  end
9
9
 
10
- before { allow(app).to receive(:call) { |env| update! env } }
11
- subject { stack.call env }
10
+ before { allow(app).to receive(:call) { |env, *| update! env } }
11
+ subject { stack.call env, {}, {} }
12
12
 
13
13
  it "normalizes headers" do
14
14
  subject
@@ -6,8 +6,8 @@ RSpec.describe Evil::Client::Middleware::StringifyForm do
6
6
  @result = env
7
7
  end
8
8
 
9
- before { allow(app).to receive(:call) { |env| update! env } }
10
- subject { stack.call env }
9
+ before { allow(app).to receive(:call) { |env, *| update! env } }
10
+ subject { stack.call env, {}, {} }
11
11
 
12
12
  context "with a non-empty body:" do
13
13
  let(:env) do
@@ -5,8 +5,8 @@ RSpec.describe Evil::Client::Middleware::StringifyJson do
5
5
 
6
6
  let(:app) { double :app }
7
7
 
8
- before { allow(app).to receive(:call) { |env| update!(env) } }
9
- subject { described_class.new(app).call(env) }
8
+ before { allow(app).to receive(:call) { |env, *| update!(env) } }
9
+ subject { described_class.new(app).call(env, {}, {}) }
10
10
 
11
11
  context "with a body:" do
12
12
  let(:env) { { format: "json", body: { foo: :bar } } }
@@ -20,8 +20,8 @@ RSpec.describe Evil::Client::Middleware::StringifyMultipart do
20
20
  @result = result
21
21
  end
22
22
 
23
- before { allow(app).to receive(:call) { |env| update!(env) } }
24
- subject { described_class.new(app).call(env) }
23
+ before { allow(app).to receive(:call) { |env, *| update!(env) } }
24
+ subject { described_class.new(app).call(env, {}, {}) }
25
25
 
26
26
  context "with a multipart format:" do
27
27
  let(:body_string) { @result[:body_string] }
@@ -7,7 +7,7 @@ RSpec.describe Evil::Client::Middleware::StringifyQuery do
7
7
  end
8
8
 
9
9
  before { allow(app).to receive(:call) { |env| update! env } }
10
- subject { stack.call env }
10
+ subject { stack.call env, {}, {} }
11
11
 
12
12
  context "with a non-empty query:" do
13
13
  let(:env) do
@@ -18,7 +18,7 @@ RSpec.describe Evil::Client::Operation::Request do
18
18
  let(:schema) do
19
19
  {
20
20
  format: "multipart",
21
- method: "patch",
21
+ method: proc { "patch" },
22
22
  path: proc { |id:, **| "users/#{id}" },
23
23
  files: Evil::Client::DSL::Files.new { |file:, **| add file },
24
24
  security: Evil::Client::DSL::Security.new { basic_auth "qux", "abc" },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin (nepalez)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-20 00:00:00.000000000 Z
12
+ date: 2016-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: evil-struct
@@ -167,13 +167,19 @@ files:
167
167
  - lib/evil/client/connection.rb
168
168
  - lib/evil/client/connection/net_http.rb
169
169
  - lib/evil/client/dsl.rb
170
+ - lib/evil/client/dsl/base.rb
170
171
  - lib/evil/client/dsl/files.rb
172
+ - lib/evil/client/dsl/headers.rb
173
+ - lib/evil/client/dsl/http_method.rb
171
174
  - lib/evil/client/dsl/operation.rb
172
175
  - lib/evil/client/dsl/operations.rb
176
+ - lib/evil/client/dsl/path.rb
177
+ - lib/evil/client/dsl/query.rb
173
178
  - lib/evil/client/dsl/response.rb
174
179
  - lib/evil/client/dsl/responses.rb
175
180
  - lib/evil/client/dsl/scope.rb
176
181
  - lib/evil/client/dsl/security.rb
182
+ - lib/evil/client/dsl/verifier.rb
177
183
  - lib/evil/client/middleware.rb
178
184
  - lib/evil/client/middleware/base.rb
179
185
  - lib/evil/client/middleware/merge_security.rb