api_tester 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +6 -0
- data/README.md +1 -1
- data/api_tester.gemspec +1 -0
- data/lib/api_tester/connection.rb +23 -11
- data/lib/api_tester/version.rb +1 -1
- data/lib/api_tester.rb +2 -2
- data/spec/api_tester/connection_spec.rb +29 -0
- data/spec/api_tester_spec.rb +14 -0
- data/spec/spec_helper.rb +5 -0
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87533e89491fb00373e6444fc9c3d4a541bed0cd
|
4
|
+
data.tar.gz: 3f1fcf1fed9e4bf025bd1f4b8a089a862eae7bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e23497cbfc815b3204cc705892e522fe166d588a4441a42123e14afdca11aea761220f8789e65063f1d3e7f9893c3031cc2cb5e41d5fc0ef07d015d1ab4b027
|
7
|
+
data.tar.gz: f4c4fd0e235707f97446c77f92316615bf5529964a7db9742232155e7138f1163d163fba6684d59c2a037e5cb72e141b228738ebb5f0dd3a30a2b04609206052
|
data/.rspec
ADDED
data/README.md
CHANGED
data/api_tester.gemspec
CHANGED
@@ -11,21 +11,20 @@ module ApiTester
|
|
11
11
|
def connection
|
12
12
|
@conn ||= Faraday.new(:url => @endpoint) do |faraday|
|
13
13
|
faraday.request :url_encoded
|
14
|
+
faraday.response :logger if ApiTester.configuration.options[:verbose]
|
14
15
|
faraday.adapter Faraday.default_adapter
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
req.headers['Content-Type'] = headers
|
28
|
-
req.body = body
|
19
|
+
[:post, :get, :put, :delete].each do |method|
|
20
|
+
define_method "#{method}" do |api, body, params = nil|
|
21
|
+
connection.send("#{method}") do |req|
|
22
|
+
req.url api, params
|
23
|
+
req.options.timeout = 3600
|
24
|
+
req.options.open_timeout = 3600
|
25
|
+
req.body = body.to_json if body
|
26
|
+
req.headers = headers
|
27
|
+
end
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
@@ -36,5 +35,18 @@ module ApiTester
|
|
36
35
|
puts resp.body
|
37
36
|
end
|
38
37
|
end
|
38
|
+
|
39
|
+
def headers
|
40
|
+
header_json
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def header_json
|
46
|
+
{
|
47
|
+
'User-Agent' => 'Api Tester',
|
48
|
+
'Content-Type' => 'application/json'
|
49
|
+
}
|
50
|
+
end
|
39
51
|
end
|
40
52
|
end
|
data/lib/api_tester/version.rb
CHANGED
data/lib/api_tester.rb
CHANGED
@@ -19,9 +19,9 @@ module ApiTester
|
|
19
19
|
yield(configuration) if block_given?
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.post(api, body)
|
22
|
+
def self.post(api, body, params = [])
|
23
23
|
puts api
|
24
|
-
resp = connection.post(api, body)
|
24
|
+
resp = connection.post(api, body, params)
|
25
25
|
connection.pretty_print(resp)
|
26
26
|
end
|
27
27
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ApiTester::Connection do
|
4
|
+
|
5
|
+
let(:url) { "http://fai.example.com" }
|
6
|
+
let(:connection) { described_class.new(url) }
|
7
|
+
let(:faraday) { Faraday.new(url: url) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(connection).to receive(:connection).and_return(faraday)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#post" do
|
14
|
+
it { expect{ connection.post("/api", { 'a' => 'b' }.to_json) }.to raise_error(Faraday::ConnectionFailed) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#get" do
|
18
|
+
it { expect{ connection.get("/api", { 'a' => 'b' }.to_json) }.to raise_error(Faraday::ConnectionFailed) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#put" do
|
22
|
+
it { expect{ connection.put("/api", { 'a' => 'b' }.to_json) }.to raise_error(Faraday::ConnectionFailed) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#delete" do
|
26
|
+
it { expect{ connection.delete("/api", { 'a' => 'b' }.to_json) }.to raise_error(Faraday::ConnectionFailed) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ApiTester do
|
4
|
+
|
5
|
+
before do
|
6
|
+
described_class.configure { |config| config.endpoint = "http://fai.example.com" }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#self.post" do
|
10
|
+
before { allow_any_instance_of(ApiTester::Connection).to receive(:post) }
|
11
|
+
before { allow_any_instance_of(ApiTester::Connection).to receive(:pretty_print) }
|
12
|
+
it { expect{ described_class.post("/api", { 'a' => 'b' }.to_json) }.to_not raise_exception }
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faizal Zakaria
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Helper for testing API
|
70
84
|
email:
|
71
85
|
- phaibusiness@gmail.com
|
@@ -74,6 +88,7 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
91
|
+
- ".rspec"
|
77
92
|
- Gemfile
|
78
93
|
- LICENSE.txt
|
79
94
|
- README.md
|
@@ -82,6 +97,9 @@ files:
|
|
82
97
|
- lib/api_tester.rb
|
83
98
|
- lib/api_tester/connection.rb
|
84
99
|
- lib/api_tester/version.rb
|
100
|
+
- spec/api_tester/connection_spec.rb
|
101
|
+
- spec/api_tester_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
85
103
|
homepage: ''
|
86
104
|
licenses:
|
87
105
|
- MIT
|
@@ -102,8 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
120
|
version: '0'
|
103
121
|
requirements: []
|
104
122
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.4.
|
123
|
+
rubygems_version: 2.4.5.1
|
106
124
|
signing_key:
|
107
125
|
specification_version: 4
|
108
126
|
summary: Helper for testing API
|
109
|
-
test_files:
|
127
|
+
test_files:
|
128
|
+
- spec/api_tester/connection_spec.rb
|
129
|
+
- spec/api_tester_spec.rb
|
130
|
+
- spec/spec_helper.rb
|