watir_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/lib/watir_api.rb +94 -0
- data/watir_api.gemspec +35 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00da5b6321bda48b3657842314ed6de70ff47950
|
4
|
+
data.tar.gz: b7286ae2ee5779433b2b7364cecc181053e3b14a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '08d1724faed27a8122db5bf2b1268897373fecb437480c77fb40fa3497ce8241b6c07f0c2afcdc296551bd8a94ef8911e6ca29638289213ee22e78cd7398ba05'
|
7
|
+
data.tar.gz: c4553e0c0864f6d4bf10b257df294ca6740d82f1cdd26e2d8402e66d1cc710c3c995807e5f29f1cf3c24eb17d010d6d46ff9fc6b53bd0a1b1e61405da8284e4a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Titus Fortner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# WatirApi
|
2
|
+
|
3
|
+
Send and receive data via a Web App's API, ideally using WatirModel objects. The goal is to
|
4
|
+
compare test data with what is input and displayed via UI.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'watir_api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install watir_api
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
This gem is still in beta; if you have suggestions to improve it, please write some code or
|
25
|
+
raise an issue on Github
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/titusfortner/watir_api.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/watir_api.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module WatirApi
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def index(opt = {})
|
9
|
+
new rest_call(:get, route, opt)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show(id:, **opt)
|
13
|
+
new rest_call(:get, "#{route}/#{id}", opt)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(obj = nil)
|
17
|
+
new rest_call(:post, route, generate_payload(obj), content_type: :json)
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy(id:, **opt)
|
21
|
+
new rest_call(:delete, "#{route}/#{id}", opt)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(id:, with:, **opt)
|
25
|
+
new rest_call(:put, "#{route}/#{id}", generate_payload(with), opt)
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_url=(base_url)
|
29
|
+
@@base_url = base_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
@@base_url || ''
|
34
|
+
end
|
35
|
+
|
36
|
+
def route
|
37
|
+
"#{base_url}/#{endpoint}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def endpoint
|
41
|
+
''
|
42
|
+
end
|
43
|
+
|
44
|
+
def model_object
|
45
|
+
eval "Model::#{self.to_s[/[^:]*$/]}"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def rest_call(method, *args)
|
51
|
+
RestClient.send(method, *args)
|
52
|
+
rescue => e
|
53
|
+
e.response
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_payload(obj)
|
57
|
+
case obj
|
58
|
+
when NilClass
|
59
|
+
model_object.new.to_api
|
60
|
+
when WatirModel
|
61
|
+
obj.to_api
|
62
|
+
when JSON
|
63
|
+
# noop
|
64
|
+
else
|
65
|
+
obj.to_json
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_reader :data, :code, :response
|
71
|
+
|
72
|
+
def initialize(response)
|
73
|
+
@response = response
|
74
|
+
@code = response.code
|
75
|
+
@data = JSON.parse(response.body, symbolize_names: true) rescue nil
|
76
|
+
@data = (convert_to_model(@data) || @data) unless @data.nil? || !(defined? model_object.new)
|
77
|
+
end
|
78
|
+
|
79
|
+
def convert_to_model(data)
|
80
|
+
if data.is_a? Hash
|
81
|
+
(model_object.keys & data.keys).empty? ? return : model_object.convert(data)
|
82
|
+
elsif data.is_a? Array
|
83
|
+
data.map do |hash|
|
84
|
+
model = convert_to_model(hash)
|
85
|
+
model.nil? ? return : model
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def model_object
|
91
|
+
self.class.model_object
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/watir_api.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "watir_api"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["Titus Fortner"]
|
8
|
+
spec.email = ["titusfortner@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = %q{A simple class for interacting with a Web App's API using test data}
|
11
|
+
spec.description = %q{Send and receive data via a Web App's API, ideally using WatirModel objects. The goal is to
|
12
|
+
compare test data with what is input and displayed via UI.}
|
13
|
+
spec.homepage = "https://github.com/titusfortner/watir_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.add_runtime_dependency "rest-client"
|
28
|
+
spec.add_runtime_dependency "faker"
|
29
|
+
spec.add_runtime_dependency "watir_model", "~> 0.4.6"
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "require_all"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Titus Fortner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: watir_model
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: require_all
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: |-
|
112
|
+
Send and receive data via a Web App's API, ideally using WatirModel objects. The goal is to
|
113
|
+
compare test data with what is input and displayed via UI.
|
114
|
+
email:
|
115
|
+
- titusfortner@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/watir_api.rb
|
128
|
+
- watir_api.gemspec
|
129
|
+
homepage: https://github.com/titusfortner/watir_api
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata:
|
133
|
+
allowed_push_host: https://rubygems.org
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.6.11
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: A simple class for interacting with a Web App's API using test data
|
154
|
+
test_files: []
|