evil-client 0.3.2 → 0.3.3

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: 792691363738b2a89d8579cfcdd33e95fcf496bd
4
- data.tar.gz: 5477063a34c23b048748d2a47d9f256f17a9a025
3
+ metadata.gz: d05eb1654246a3c8ebda837f8e292fa356bca35e
4
+ data.tar.gz: 9685ee8ea9bf347a54c794ca7c83b612eb206912
5
5
  SHA512:
6
- metadata.gz: 586b7861e76d8e6f56bdd8f1668cad0e25ba75fd4247dd4e5e810ece64999e882b555b039a194c5c97d80280c46cd49d71ae78d23c83ba87758f59574a762008
7
- data.tar.gz: 5eaada81c8761c9c4bbe40a9be0fc4bb1006b6fea7501a8cd3162ccab6229f03f20c4b7dde6aaff4dc073406be7582ff33c3f6d75219dd110d02d5746fa66038
6
+ metadata.gz: '09241951f999f8909d4000e5b7ec81bab248729125bdd040f23d2162ab2f8739eb55d9c4f736fc72fc63750e7ebe48a62b0b13fecc82deaa01ccbdc839c76813'
7
+ data.tar.gz: eade03b9334d111284a7c08d81a30f0bf5457a24b5ae7bec0a5461fe8f162a6e41fa9ff6833b1fc89db83a5583ab0c3999696e9cdf7cb1f9fb70d539103e93c7
data/.rubocop.yml CHANGED
@@ -15,6 +15,9 @@ Style/FileName:
15
15
  Exclude:
16
16
  - lib/evil-client.rb
17
17
 
18
+ Style/Lambda:
19
+ Enabled: false
20
+
18
21
  Style/LambdaCall:
19
22
  Enabled: false
20
23
 
data/CHANGELOG.md CHANGED
@@ -1,26 +1,38 @@
1
- # v0.3.2 2016-11-29
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog], and this project adheres
5
+ to [Semantic Versioning].
6
+
7
+ ## [0.3.3] - [2017-07-14]
8
+
9
+ On the road to v0.3.3
10
+
11
+ ### Fixed
12
+ - dependency from 'securerandom' standard library (nepalez)
13
+
14
+ ### Added
15
+ - variables for client settings and base_url (nepalez)
16
+
17
+ # [0.3.2] - [2016-11-29]
2
18
 
3
19
  On the road to v0.4.0
4
20
 
5
- ## Fixed
21
+ ### Fixed
6
22
  - Query and body encoding (nepalez)
7
23
 
8
- ## Internal
24
+ ### Internal
9
25
  - Refactoring of some DSL classes (nepalez)
10
26
 
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
27
+ ## [0.3.1] - [2016-11-22]
14
28
 
15
- ## Fixed
29
+ ### Fixed
16
30
  - Loading of 'json' from stdlib (nepalez)
17
31
 
18
- ## Internal
32
+ ### Internal
19
33
  - Class `Evil::Client::Model` is extracted to `evil-struct` gem (nepalez)
20
34
 
21
- [Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-initializer/compare/v0.3.0...v0.3.1)
22
-
23
- # v0.3.0 2016-11-18
35
+ ## [0.3.0] - [2016-11-18]
24
36
 
25
37
  This version changes the way of processing responses. Instead of dealing
26
38
  with raw rake responses, we add opinionated methods to gracefully process
@@ -29,8 +41,8 @@ responses from JSON or plain text.
29
41
  In the next minor versions processors for both "form" and "file" (multipart)
30
42
  formats will be added.
31
43
 
32
- ## BREAKING CHANGES
33
- - Method `DSL#response` was redefined with a new signature (nepalez)
44
+ ### Changed
45
+ - [BREAKING] Method `DSL#response` was redefined with a new signature (nepalez)
34
46
 
35
47
  The method takes 2 _mandatory_ positional params: unique name and
36
48
  integer status. This allows to process responses with the same status,
@@ -52,7 +64,7 @@ formats will be added.
52
64
  Names (the first param) are unique. When several definitions use the same name,
53
65
  only the last one will be applicable.
54
66
 
55
- ## Added
67
+ ### Added
56
68
  - Method `DSL#responses` to share options between response definitions (nepalez)
57
69
 
58
70
  ```ruby
@@ -70,3 +82,9 @@ formats will be added.
70
82
  response :failure, 400, format: "json", raise: true
71
83
  response :not_found, 404, format: "json", raise: true
72
84
  ```
85
+
86
+ [0.3.3]: https://github.com/evilmartians/evil-client/compare/v0.3.2...v0.3.3
87
+ [0.3.2]: https://github.com/evilmartians/evil-client/compare/v0.3.1...v0.3.2
88
+ [0.3.1]: https://github.com/evilmartians/evil-client/compare/v0.3.0...v0.3.1
89
+ [Keep a Changelog]: http://keepachangelog.com/
90
+ [Semantic Versioning]: http://semver.org/
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Andrew Kozin (aka nepalez), andrew.kozin@gmail.com
3
+ Copyright (c) 2016-2017 Andrew Kozin (nepalez), andrew.kozin@gmail.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.2"
3
+ gem.version = "0.3.3"
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"
data/lib/evil/client.rb CHANGED
@@ -2,6 +2,7 @@ require "evil-struct"
2
2
  require "mime-types"
3
3
  require "rack"
4
4
  require "json"
5
+ require "securerandom"
5
6
 
6
7
  # Absctract base class for clients to remote APIs
7
8
  #
@@ -17,7 +17,11 @@ class Evil::Client
17
17
 
18
18
  # Adds [#operations] to a specific client's instances
19
19
  def self.extended(klass)
20
- klass.include Dry::Initializer.define -> { param :operations }
20
+ klass.include Dry::Initializer.define -> do
21
+ param :settings
22
+ param :base_url
23
+ param :operations
24
+ end
21
25
  end
22
26
 
23
27
  # Helper to define params and options a for a client's constructor
@@ -103,7 +107,7 @@ class Evil::Client
103
107
  hash[key] = Evil::Client::Operation.new schema, connection
104
108
  end
105
109
 
106
- super(data)
110
+ super(settings, base_url, data)
107
111
  end
108
112
 
109
113
  private
@@ -72,7 +72,7 @@ module Evil::Client::DSL
72
72
  # ==========================================================================
73
73
 
74
74
  def __valid_format__(format)
75
- formats = %w(json form)
75
+ formats = %w[json form]
76
76
  return format.to_s if formats.include? format.to_s
77
77
  raise ArgumentError.new "Invalid format #{format} for body." \
78
78
  " Use one of formats: #{formats}"
@@ -49,7 +49,7 @@ module Evil::Client::DSL
49
49
  # ==========================================================================
50
50
 
51
51
  def __validate__(part)
52
- parts = %i(body query headers)
52
+ parts = %i[body query headers]
53
53
  return if parts.include? part
54
54
  raise ArgumentError.new "Wrong part '#{part}'. Use one of parts: #{parts}"
55
55
  end
@@ -9,7 +9,7 @@ class Evil::Client::Middleware
9
9
  def build(env)
10
10
  env.dup.tap do |hash|
11
11
  security = hash.delete(:security).to_h
12
- %i(headers body query).each do |key|
12
+ %i[headers body query].each do |key|
13
13
  next unless security[key]
14
14
  hash[key] ||= {}
15
15
  hash[key].update security[key]
@@ -30,7 +30,7 @@ RSpec.describe "instantiation" do
30
30
  let(:client) { Test::Client.new(**options) }
31
31
 
32
32
  it "is rejected" do
33
- expect { client }.to raise_error(KeyError)
33
+ expect { client }.to raise_error(StandardError)
34
34
  end
35
35
  end
36
36
 
@@ -54,7 +54,7 @@ RSpec.describe "instantiation" do
54
54
  before { options.delete :user }
55
55
 
56
56
  it "is rejected" do
57
- expect { client }.to raise_error(KeyError)
57
+ expect { client }.to raise_error(ArgumentError)
58
58
  end
59
59
  end
60
60
 
@@ -140,7 +140,7 @@ RSpec.describe "operation with form body" do
140
140
  end
141
141
 
142
142
  it "requires mandatory arguments" do
143
- expect { operation.call bar: 2, baz: 3 }.to raise_error(KeyError)
143
+ expect { operation.call bar: 2, baz: 3 }.to raise_error(ArgumentError)
144
144
  end
145
145
 
146
146
  it "applies type restrictions" do
@@ -61,7 +61,7 @@ RSpec.describe "operation with headers" do
61
61
 
62
62
  it "requires mandatory headers" do
63
63
  expect { client.operations[:clear_data].call bar: "BAR", baz: "BAZ" }
64
- .to raise_error(KeyError)
64
+ .to raise_error(ArgumentError)
65
65
  end
66
66
 
67
67
  it "applies type constraints" do
@@ -138,7 +138,7 @@ RSpec.describe "operation with json body" do
138
138
  end
139
139
 
140
140
  it "requires mandatory arguments" do
141
- expect { operation.call bar: 2, baz: 3 }.to raise_error(KeyError)
141
+ expect { operation.call bar: 2, baz: 3 }.to raise_error(ArgumentError)
142
142
  end
143
143
 
144
144
  it "applies type restrictions" do
@@ -65,12 +65,12 @@ RSpec.describe "operation with query" do
65
65
 
66
66
  it "applies type restrictuions" do
67
67
  expect { client.operations[:filter].call id: 1, name: "Joe" }
68
- .to raise_error(KeyError)
68
+ .to raise_error(ArgumentError)
69
69
  end
70
70
 
71
71
  it "supports nesting in a Rails style" do
72
72
  client.operations[:search].call name: {
73
- "first": "John", last: "Doe", middle: %w(Juan Andre)
73
+ "first": "John", last: "Doe", middle: %w[Juan Andre]
74
74
  }
75
75
  query = [
76
76
  "name%5Bfirst%5D=John",
@@ -284,7 +284,7 @@ RSpec.describe Evil::Client::DSL::Operation do
284
284
  end
285
285
 
286
286
  it "returns parsed and handled body" do
287
- expect(response_coercer.call(body)).to eq data: %w(foo baz)
287
+ expect(response_coercer.call(body)).to eq data: %w[foo baz]
288
288
  end
289
289
  end
290
290
 
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.2
4
+ version: 0.3.3
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-29 00:00:00.000000000 Z
12
+ date: 2017-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: evil-struct
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  requirements: []
248
248
  rubyforge_project:
249
- rubygems_version: 2.6.4
249
+ rubygems_version: 2.5.2
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Human-friendly DSL for building HTTP(s) clients in Ruby
@@ -282,3 +282,4 @@ test_files:
282
282
  - spec/unit/evil/client/middleware_spec.rb
283
283
  - spec/unit/evil/client/operation/request_spec.rb
284
284
  - spec/unit/evil/client/operation/response_spec.rb
285
+ has_rdoc: