watir_api 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watir_api.rb +13 -6
- data/watir_api.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd5fa8ac2cf09b66985111647ddcab4cc178fbd
|
4
|
+
data.tar.gz: 0b0245d742a805fd30c29472715035454589180e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 516e6b75070acbe7e4db73b0398e75b111ceb4f2952237688d1b72d26256d1592c90f9c8c5077b0086a173d67bc18df2e91e04f80439b5b86413ca6ce2112d6f
|
7
|
+
data.tar.gz: e783068c1804287a634dd6bfeae7f6400f4382fd41a8e5faf8ea5aca95fd53ef8a79ace7bcfcecbcdb1cc265954179f724d76f66a5a9991b66967e007d85410d
|
data/lib/watir_api.rb
CHANGED
@@ -12,7 +12,7 @@ module WatirApi
|
|
12
12
|
|
13
13
|
def show(id:, **opt)
|
14
14
|
new rest_call({method: :get,
|
15
|
-
url: "#{route}/#{id}"}.merge opt)
|
15
|
+
url: "#{route}/#{id}".chomp('/')}.merge opt)
|
16
16
|
end
|
17
17
|
|
18
18
|
def create(obj = nil)
|
@@ -24,12 +24,12 @@ module WatirApi
|
|
24
24
|
|
25
25
|
def destroy(id:, **opt)
|
26
26
|
new rest_call({method: :delete,
|
27
|
-
url: "#{route}/#{id}"}.merge opt)
|
27
|
+
url: "#{route}/#{id}".chomp('/')}.merge opt)
|
28
28
|
end
|
29
29
|
|
30
30
|
def update(id:, with:, **opt)
|
31
31
|
new rest_call({method: :put,
|
32
|
-
url: "#{route}/#{id}",
|
32
|
+
url: "#{route}/#{id}".chomp('/'),
|
33
33
|
payload: generate_payload(with)}.merge opt)
|
34
34
|
end
|
35
35
|
|
@@ -41,8 +41,8 @@ module WatirApi
|
|
41
41
|
@@base_url || ''
|
42
42
|
end
|
43
43
|
|
44
|
-
def route
|
45
|
-
"#{base_url}/#{endpoint}"
|
44
|
+
def route(opt = {})
|
45
|
+
"#{opt[:base_url] || base_url}/#{opt.delete(:endpoint) || endpoint}"
|
46
46
|
end
|
47
47
|
|
48
48
|
def endpoint
|
@@ -56,6 +56,8 @@ module WatirApi
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def rest_call(opt)
|
59
|
+
opt[:verify_ssl] = opt.delete(:ssl) if opt.key?(:ssl)
|
60
|
+
opt[:headers] = opt.delete(:headers) || headers
|
59
61
|
RestClient::Request.execute(opt) do |response, request, result|
|
60
62
|
[response, request, result]
|
61
63
|
end
|
@@ -92,7 +94,12 @@ module WatirApi
|
|
92
94
|
|
93
95
|
def convert_to_model(data)
|
94
96
|
if data.is_a? Hash
|
95
|
-
(model_object.
|
97
|
+
return if (model_object.valid_keys & data.keys).empty?
|
98
|
+
begin
|
99
|
+
model_object.convert(data)
|
100
|
+
rescue StandardError => ex
|
101
|
+
raise unless ex.message.include?('Can not convert Hash to Model')
|
102
|
+
end
|
96
103
|
elsif data.is_a? Array
|
97
104
|
data.map do |hash|
|
98
105
|
model = convert_to_model(hash)
|
data/watir_api.gemspec
CHANGED