watir_api 0.1.2 → 0.2.0
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 +27 -15
- data/watir_api.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2866494791af1c0785b52cb294240c8f0a2c16a9
|
4
|
+
data.tar.gz: 0a7dd46130691e620357d03fcd66113372ee2ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9abe2898a5c711ec90c37889123516c985e51165670040576b747983503c742f3134a12b25ce5c37b6b6508ab5a18edb0f8969a7ac49977226855e65d5b7e23d
|
7
|
+
data.tar.gz: f9a64cc277053f4c4530d978efa808bf2d22a34b15e777e9f466ea94156e909ac931edde90a2949980e070c5c0b8a7a7ae5dec79ca31c068fbba5bad397d059f
|
data/lib/watir_api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "rest-client"
|
2
2
|
require "json"
|
3
|
+
require 'active_support/inflector'
|
3
4
|
|
4
5
|
module WatirApi
|
5
6
|
class Base
|
@@ -7,30 +8,29 @@ module WatirApi
|
|
7
8
|
|
8
9
|
def index(opt = {})
|
9
10
|
new rest_call({method: :get,
|
10
|
-
|
11
|
+
url: route(opt)}.merge opt)
|
11
12
|
end
|
12
13
|
|
13
14
|
def show(id:, **opt)
|
14
15
|
new rest_call({method: :get,
|
15
|
-
|
16
|
+
url: "#{route(opt)}/#{id}".chomp('/')}.merge opt)
|
16
17
|
end
|
17
18
|
|
18
|
-
def create(obj = nil)
|
19
|
-
new rest_call(method: :post,
|
20
|
-
|
21
|
-
|
22
|
-
headers: headers)
|
19
|
+
def create(obj = nil, opt = {})
|
20
|
+
new rest_call({method: :post,
|
21
|
+
url: route(opt),
|
22
|
+
payload: generate_payload(obj)}.merge opt)
|
23
23
|
end
|
24
24
|
|
25
25
|
def destroy(id:, **opt)
|
26
26
|
new rest_call({method: :delete,
|
27
|
-
|
27
|
+
url: "#{route(opt)}/#{id}".chomp('/')}.merge opt)
|
28
28
|
end
|
29
29
|
|
30
30
|
def update(id:, with:, **opt)
|
31
31
|
new rest_call({method: :put,
|
32
|
-
|
33
|
-
|
32
|
+
url: "#{route(opt)}/#{id}".chomp('/'),
|
33
|
+
payload: generate_payload(with)}.merge opt)
|
34
34
|
end
|
35
35
|
|
36
36
|
def base_url=(base_url)
|
@@ -57,7 +57,7 @@ module WatirApi
|
|
57
57
|
|
58
58
|
def rest_call(opt)
|
59
59
|
opt[:verify_ssl] = opt.delete(:ssl) if opt.key?(:ssl)
|
60
|
-
opt[:headers]
|
60
|
+
opt[:headers] ||= headers
|
61
61
|
RestClient::Request.execute(opt) do |response, request, result|
|
62
62
|
[response, request, result]
|
63
63
|
end
|
@@ -81,15 +81,27 @@ module WatirApi
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
attr_reader :
|
84
|
+
attr_reader :response, :code, :header, :data
|
85
85
|
|
86
86
|
def initialize(args)
|
87
|
-
response,
|
87
|
+
response, _request, _result = *args
|
88
88
|
@response = response
|
89
89
|
@code = response.code
|
90
|
-
@header =
|
90
|
+
@header = response.instance_variable_get('@headers')
|
91
91
|
@data = JSON.parse(response.body, symbolize_names: true) rescue nil
|
92
|
-
|
92
|
+
|
93
|
+
set_watir_model_attr
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_watir_model_attr
|
97
|
+
return unless defined?(model_object.new)
|
98
|
+
model = convert_to_model(@data) unless @data.nil?
|
99
|
+
var = model_object.to_s[/[^:]*$/].underscore
|
100
|
+
var = var.pluralize if @data.is_a? Array
|
101
|
+
instance_variable_set "@#{var}", model
|
102
|
+
singleton_class.class_eval { attr_accessor var }
|
103
|
+
@id = @data[:id] if @data.is_a? Hash
|
104
|
+
singleton_class.class_eval { attr_accessor :id } unless @id.nil?
|
93
105
|
end
|
94
106
|
|
95
107
|
def convert_to_model(data)
|
data/watir_api.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Titus Fortner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|