pipekit-webmock 0.1.0 → 0.2.0
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +6 -0
- data/bin/console +2 -6
- data/lib/pipekit/.#webmock.rb +1 -0
- data/lib/pipekit/webmock/errors.rb +8 -16
- data/lib/pipekit/webmock/request_signature_snippet.rb +37 -0
- data/lib/pipekit/webmock/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc18440ccfa886dbab478f74c42a82a5fdf89f40
|
4
|
+
data.tar.gz: 44d86bad5804feb0dfd3c26cc6c5a7611e081e03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe1d916f1e821098e0f453ca71ab0be95c52fe9b03392c9d6909f1bd878be0e60e428a2bb7b0e93c324f5208e49c8c33faf1b2ce1520f96e2bdc516d5fce81b5
|
7
|
+
data.tar.gz: d349c8c2d44fc115b01edb8ffdf60fa6718c529ec6886058a8aca68c1bcb30b8b381ec9f487624b1176a76d5c00ed0d7039d8b71af722c6c38827a99c79d73c5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,12 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
```ruby
|
26
|
+
# spec/spec_helper.rb
|
27
|
+
|
28
|
+
require "pipekit/webmock"
|
29
|
+
```
|
30
|
+
|
25
31
|
To use `pipekit` you will need a dummy Pipedrive config for your tests. Create a file with Pipedrive field mapping in `spec/support/config.yml`. Then add the following to your `spec_helper`:
|
26
32
|
|
27
33
|
```ruby
|
data/bin/console
CHANGED
@@ -6,9 +6,5 @@ require "pipekit/webmock"
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
@@ -0,0 +1 @@
|
|
1
|
+
jafrog@Irinas-MacBook-Pro.local.30214
|
@@ -1,35 +1,27 @@
|
|
1
1
|
require "rack"
|
2
2
|
require "webmock"
|
3
3
|
|
4
|
+
require "pipekit/webmock/request_signature_snippet"
|
5
|
+
|
4
6
|
module Pipekit
|
5
7
|
module WebMock
|
6
8
|
class UnregisteredPipedriveRequestError < StandardError
|
7
9
|
WebMockNetConnectNotAllowedError = ::WebMock::NetConnectNotAllowedError unless const_defined?(:WebMockNetConnectNotAllowedError)
|
8
10
|
|
9
11
|
def initialize(request_signature)
|
10
|
-
|
12
|
+
request_signature_snippet = RequestSignatureSnippet.new(request_signature)
|
11
13
|
|
12
|
-
|
13
|
-
query = request_signature.uri.query
|
14
|
-
body = request_signature.body
|
14
|
+
return WebMockNetConnectNotAllowedError.new(request_signature) unless request_signature_snippet.pipedrive_request?
|
15
15
|
text = [
|
16
|
-
"Unregistered request to Pipedrive: #{request_signature
|
16
|
+
"Unregistered request to Pipedrive: #{request_signature}",
|
17
17
|
"with params:",
|
18
|
-
|
18
|
+
request_signature_snippet.params,
|
19
19
|
"and body:",
|
20
|
-
|
20
|
+
request_signature_snippet.body,
|
21
21
|
"="*60
|
22
22
|
].compact.join("\n\n")
|
23
|
-
super(text)
|
24
|
-
end
|
25
23
|
|
26
|
-
|
27
|
-
params = Rack::Utils.parse_nested_query(query)
|
28
|
-
params.reduce({}) do |result, (field, value)|
|
29
|
-
field = Config.field_name(resource, field)
|
30
|
-
value = Config.field_value(resource, field, value)
|
31
|
-
result.tap { |result| result[field] = value }
|
32
|
-
end.map { |k, v| "#{k}: #{v}" }.join("\n")
|
24
|
+
super(text)
|
33
25
|
end
|
34
26
|
end
|
35
27
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Pipekit
|
2
|
+
module WebMock
|
3
|
+
class RequestSignatureSnippet
|
4
|
+
def initialize(request_signature)
|
5
|
+
@uri = request_signature.uri
|
6
|
+
@body = request_signature.body
|
7
|
+
end
|
8
|
+
|
9
|
+
def pipedrive_request?
|
10
|
+
@uri.hostname == "api.pipedrive.com"
|
11
|
+
end
|
12
|
+
|
13
|
+
def params
|
14
|
+
extract_params(@uri.query)
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
extract_params(@body)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def resource
|
24
|
+
@uri.path.split("/")[2][0..-2]
|
25
|
+
end
|
26
|
+
|
27
|
+
def extract_params(query)
|
28
|
+
params = Rack::Utils.parse_nested_query(query)
|
29
|
+
params.reduce({}) do |result, (field, value)|
|
30
|
+
field = Config.field_name(resource, field)
|
31
|
+
value = Config.field_value(resource, field, value)
|
32
|
+
result.tap { |result| result[field] = value }
|
33
|
+
end.map { |k, v| "#{k}: #{v}" }.join("\n")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipekit-webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jafrog
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|
@@ -126,9 +126,11 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- bin/console
|
128
128
|
- bin/setup
|
129
|
+
- lib/pipekit/.#webmock.rb
|
129
130
|
- lib/pipekit/webmock.rb
|
130
131
|
- lib/pipekit/webmock/api.rb
|
131
132
|
- lib/pipekit/webmock/errors.rb
|
133
|
+
- lib/pipekit/webmock/request_signature_snippet.rb
|
132
134
|
- lib/pipekit/webmock/version.rb
|
133
135
|
- pipekit-webmock.gemspec
|
134
136
|
homepage: https://github.com/makersacademy/pipekit-webmock
|