webtester 0.1.8 → 0.1.9

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/json_object.rb +43 -3
  3. data/lib/request.rb +7 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d35049f469df39296436703b57f6c4d8878cce6
4
- data.tar.gz: aed420a2d891b4d6d24a6abd9c0ff095a6f820f7
3
+ metadata.gz: 8f737a2baae46e8ac06b238584ec1033d9dc2ee3
4
+ data.tar.gz: 1c7f75d845e25bf29ea28e00b73abfec5db0bda7
5
5
  SHA512:
6
- metadata.gz: 5f6bce1498f0d96af8fa0406d3cb5d65da38606a78f1c59647fbe77aadb93b65ea70a1cc376d2c2ddbd72e75cbc4320d102c4354c003b0e6374e4dc173fced10
7
- data.tar.gz: ba4aea03283c4017c4473078fa018addfee0ffc883f4afbfa30816df10cac786761d8e9af695eb8881a4dd82b3a2c6856337642ede57b46781882afd767530b9
6
+ metadata.gz: 68d15cc13de617bd363ac8e072ae993df4960c8e22171c68fec689cbcb8b7825181853d609bccaf7e8335c1111ff20f4c5eff69439bc7ef727aa59629db664a0
7
+ data.tar.gz: 312080b5d22c7240bd690479d44af8540ff8c823699eab6d3b0f13152ef67bce0dcfa07dd9f9e29ab95a0dff5e65dbb904ac93a9e5d2975078bf2dce4bf2f095
data/lib/json_object.rb CHANGED
@@ -24,13 +24,53 @@ module WT
24
24
  self.method("#{name}=").call(args[0])
25
25
  end
26
26
 
27
+ def post(url)
28
+ http_request("POST", url, self.to_s)
29
+ end
30
+
31
+ def put(url)
32
+ http_request("PUT", url, self.to_s)
33
+ end
34
+
35
+ def delete(url)
36
+ http_request("DELETE", url, nil)
37
+ end
38
+
39
+ def http_request(type, url, data)
40
+ args = []
41
+ url_parts = url.split("/")
42
+ mounted_url = url
43
+
44
+ url_parts.each do |part|
45
+ p = part.to_s
46
+
47
+ if p[0] == ':'
48
+ p[":"] = ''
49
+
50
+ begin
51
+ mounted_url[":#{p}"] = self.method(p).call.to_s
52
+ rescue NameError
53
+ mounted_url["/:#{p}"] = ''
54
+ end
55
+ end
56
+ end
57
+
58
+ request = WT::Request.new(type, mounted_url, data)
59
+ request.headers['User-Agent'] = 'Ruby; WebTester API'
60
+ request.headers['Content-Type'] = 'application/json; charset=utf-8'
61
+
62
+ return request
63
+ end
64
+
65
+
27
66
  def to_s
28
67
  result = ""
29
68
 
30
- if @__items__ and @__items__.length > 0 # Object is an Array
69
+ if @__items__ and @__items__.length > 0 # object is an Array
31
70
  result = "["
32
71
  @__items__.each do |item|
33
- result += "#{item.to_s},"
72
+ result += "," unless result[-1] == '['
73
+ result += "#{item.to_s}"
34
74
  end
35
75
  result += "]"
36
76
  else # Object is a HASH
@@ -47,11 +87,11 @@ module WT
47
87
  v_value.is_a?(FalseClass) or
48
88
  v_value.is_a?(Float))
49
89
 
90
+ result += "," unless result[-1] == '{'
50
91
  result += "\"#{v_name}\":"
51
92
  result += "\"" unless non_quoted_condition
52
93
  result += v_value.to_s
53
94
  result += "\"" unless non_quoted_condition
54
- result += ","
55
95
  end
56
96
  end
57
97
  result += "}"
data/lib/request.rb CHANGED
@@ -121,7 +121,13 @@ module WT
121
121
  end
122
122
 
123
123
  def to_s
124
- "#{self.request_type} #{self.request_url} HTTP/1.1"
124
+ s = "#{self.request_type} #{self.request_url} HTTP/1.1\r\n"
125
+ self.headers.each do |k,v|
126
+ s += "#{k}: #{v}\r\n"
127
+ end
128
+ s += "\r\n"
129
+ s += self.request_data if self.request_data
130
+ s
125
131
  end
126
132
  end
127
133
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webtester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego F. Nascimento
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A simple API to create HTTP Request tests. "
14
14
  email: diego.fnascimento@gmail.com