postman-ruby 0.0.1 → 0.1.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/lib/{postman/postman.rb → postman-ruby.rb} +78 -27
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2649293d4a846e8c4f6899dae0fd50e667f8b837
|
4
|
+
data.tar.gz: 744b6436588c5d1f3cb947df143f4d9434d6b30f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1e8925534891860feda6c541bd362b185ada71cfd869131707c91f458c0ce4d03fd4eed5c4496a281ffb9a12df8bcffc409482d6f9fb1b3723a77f04b7b8080
|
7
|
+
data.tar.gz: 5860d7aef44155a1b10beccd43b0af518a00c587f1050f3c4e329342c251f610d91cf5df17162a43742e60abd9c5890a85ea08b044dfe99d04496cf17117a1bd
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'delegate'
|
3
5
|
|
4
6
|
module Postman
|
5
7
|
class URL
|
@@ -8,6 +10,7 @@ module Postman
|
|
8
10
|
# @auth
|
9
11
|
# @host
|
10
12
|
# @path
|
13
|
+
# @query
|
11
14
|
# @variable
|
12
15
|
if url.class == String
|
13
16
|
url = {
|
@@ -33,6 +36,14 @@ module Postman
|
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
39
|
+
def set_var(vars)
|
40
|
+
vars.each { |k, v| @variable[k] = v }
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset_var(vars)
|
44
|
+
@variable = vars
|
45
|
+
end
|
46
|
+
|
36
47
|
def to_s
|
37
48
|
interpolate
|
38
49
|
end
|
@@ -41,9 +52,9 @@ module Postman
|
|
41
52
|
|
42
53
|
def interpolate
|
43
54
|
url = @raw
|
44
|
-
vars = @raw.scan(/:[A-Za-z\-_]
|
55
|
+
vars = @raw.scan(/:([A-Za-z\-_]+)(?:\/|$)/).flatten
|
45
56
|
vars.each do |v|
|
46
|
-
url = url.gsub(v, @variable[v
|
57
|
+
url = url.gsub(':'+v, @variable[v])
|
47
58
|
end
|
48
59
|
url
|
49
60
|
end
|
@@ -51,19 +62,29 @@ module Postman
|
|
51
62
|
|
52
63
|
class Request
|
53
64
|
def initialize(params)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
# @name
|
66
|
+
# @description
|
67
|
+
# @method
|
68
|
+
# @url
|
69
|
+
# @header
|
70
|
+
# @body
|
71
|
+
# @environment
|
61
72
|
params.each do |k,v|
|
62
73
|
instance_variable_set("@#{k}", v)
|
63
74
|
self.class.send(:attr_reader, k.to_sym)
|
64
75
|
end
|
76
|
+
@method = @method.downcase.to_sym
|
65
77
|
@url = URL.new(@url)
|
66
78
|
@env = @environment
|
79
|
+
if @header.nil?
|
80
|
+
@header = {}
|
81
|
+
else
|
82
|
+
header = {}
|
83
|
+
@header.each do |h|
|
84
|
+
header[h['key']] = apply_env(h['value'])
|
85
|
+
end
|
86
|
+
@header = header
|
87
|
+
end
|
67
88
|
end
|
68
89
|
|
69
90
|
def set_env(env)
|
@@ -74,34 +95,61 @@ module Postman
|
|
74
95
|
@env = env.clone
|
75
96
|
end
|
76
97
|
|
77
|
-
def
|
78
|
-
|
98
|
+
def execute
|
99
|
+
if @method == :get
|
100
|
+
new_request(:get).execute
|
101
|
+
else
|
102
|
+
params = {}
|
103
|
+
|
104
|
+
unless @body.nil? && @body.empty?
|
105
|
+
if @body['mode'] == 'raw'
|
106
|
+
params[:payload] = @body['raw']
|
107
|
+
elsif @body['mode'] == 'formdata'
|
108
|
+
f = {}
|
109
|
+
@body['formdata'].each do |d|
|
110
|
+
if d['enabled']
|
111
|
+
if d['type'] == 'file'
|
112
|
+
params[:multipart] = true
|
113
|
+
end
|
114
|
+
f[d['key']] = d['value'] || ""
|
115
|
+
end
|
116
|
+
end
|
117
|
+
params[:payload] = f
|
118
|
+
end
|
119
|
+
end
|
120
|
+
new_request(:post, params).execute
|
121
|
+
end
|
79
122
|
end
|
80
123
|
|
81
124
|
private
|
82
125
|
|
83
126
|
def apply_env(str)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
127
|
+
if !@env.nil?
|
128
|
+
vars = str.scan(/\{{2}[A-Za-z_\-.]+\}{2}/)
|
129
|
+
vars.each do |v|
|
130
|
+
val = @env[v[2..-3]]
|
131
|
+
raise "Request env var is missing: #{v}" if val.nil?
|
132
|
+
str = str.gsub(v, val)
|
133
|
+
end
|
89
134
|
end
|
90
135
|
str
|
91
136
|
end
|
92
137
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
if @header.class == Array
|
97
|
-
@header.each do |h|
|
98
|
-
req[h['key']] = apply_env(h['value'])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
102
|
-
return http.request req # Net::HTTPResponse object
|
138
|
+
class RequestDecorator < SimpleDelegator
|
139
|
+
def execute
|
140
|
+
__getobj__.execute {|response, request, result| response }
|
103
141
|
end
|
104
142
|
end
|
143
|
+
|
144
|
+
|
145
|
+
def new_request(method, params={})
|
146
|
+
params[:method] = method
|
147
|
+
params[:url] = apply_env(@url.to_s)
|
148
|
+
params[:headers] = @header
|
149
|
+
r = RestClient::Request.new(params)
|
150
|
+
RequestDecorator.new(r)
|
151
|
+
end
|
152
|
+
|
105
153
|
end
|
106
154
|
|
107
155
|
FILTER_KEYS=%w(name url method description)
|
@@ -136,7 +184,7 @@ module Postman
|
|
136
184
|
end
|
137
185
|
|
138
186
|
def to_a
|
139
|
-
filter
|
187
|
+
filter
|
140
188
|
end
|
141
189
|
|
142
190
|
private
|
@@ -165,6 +213,9 @@ module Postman
|
|
165
213
|
score = 0
|
166
214
|
flt_hash.each do |k, v|
|
167
215
|
itk = req[k.to_s]
|
216
|
+
if k.to_s == 'url' && itk.class == Hash
|
217
|
+
itk = itk['raw']
|
218
|
+
end
|
168
219
|
if !itk.nil?
|
169
220
|
score+=1 if v.class == Regexp && v =~ itk || v.class == String && v.downcase == itk.downcase
|
170
221
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postman-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Buchma
|
@@ -9,7 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-04-18 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
13
33
|
description: Allows to parse Postman's JSON reqeuests collection dump and make requests
|
14
34
|
from ruby
|
15
35
|
email: josephbuchma@gmail.com
|
@@ -17,7 +37,7 @@ executables: []
|
|
17
37
|
extensions: []
|
18
38
|
extra_rdoc_files: []
|
19
39
|
files:
|
20
|
-
- lib/postman
|
40
|
+
- lib/postman-ruby.rb
|
21
41
|
homepage: http://github.com/josephbuchma/postman-ruby
|
22
42
|
licenses:
|
23
43
|
- MIT
|