api_tester 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 095c03023153a592e189ba0189bf3fdc40523294
4
- data.tar.gz: 26c734161d007dbdeffaee619e7ea2ec18157e15
3
+ metadata.gz: 87533e89491fb00373e6444fc9c3d4a541bed0cd
4
+ data.tar.gz: 3f1fcf1fed9e4bf025bd1f4b8a089a862eae7bcf
5
5
  SHA512:
6
- metadata.gz: eb26e7c72507ac30d5a61b5581a7396382debd8f0daa21f38cf35315d30fcb1f73f40cb87779c80ae05ddcadd02609727579d48ac272117613befb9e82857fc3
7
- data.tar.gz: 8d239a3dd05b81c471d502441c2bead7482fd37ae2da4a35d5ddb4f3bf5aa99d451b67b2e911704b0862de4a33739924cd57501a933f7ac205c3031f013f7706
6
+ metadata.gz: 9e23497cbfc815b3204cc705892e522fe166d588a4441a42123e14afdca11aea761220f8789e65063f1d3e7f9893c3031cc2cb5e41d5fc0ef07d015d1ab4b027
7
+ data.tar.gz: f4c4fd0e235707f97446c77f92316615bf5529964a7db9742232155e7138f1163d163fba6684d59c2a037e5cb72e141b228738ebb5f0dd3a30a2b04609206052
data/.rspec ADDED
@@ -0,0 +1,6 @@
1
+ --color
2
+ --format progress
3
+ --backtrace
4
+ --default-path spec
5
+
6
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ApiTester
2
2
 
3
- TODO: Write a gem description
3
+ API tester library.
4
4
 
5
5
  ## Installation
6
6
 
data/api_tester.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "faraday"
24
24
  spec.add_development_dependency "json"
25
+ spec.add_development_dependency "rspec"
25
26
  end
@@ -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
- def headers
19
- 'application/json'
20
- end
21
-
22
- def post(api, body)
23
- resp = connection.post do |req|
24
- req.url api
25
- req.options.timeout = 3600
26
- req.options.open_timeout = 3600
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
@@ -1,3 +1,3 @@
1
1
  module ApiTester
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'api_tester'
3
+
4
+ RSpec.configure do |c|
5
+ end
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.3
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: 2014-11-05 00:00:00.000000000 Z
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.2
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