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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/watir_api.rb +13 -6
  3. data/watir_api.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb25e51df99ac53a5b6b1dcc2f9be372bb96332d
4
- data.tar.gz: f61459b4cccb2601e10f0d69c58d6d6ec301f72e
3
+ metadata.gz: 0bd5fa8ac2cf09b66985111647ddcab4cc178fbd
4
+ data.tar.gz: 0b0245d742a805fd30c29472715035454589180e
5
5
  SHA512:
6
- metadata.gz: 0ede385d5cd5d0d0e903ae9395cfc82a847798f1cc14656f0bc59dac97cd3957c5a746b8d3d6249ddb8022c8337b087b24a9b530fa2dc028bdc24bb0465bcf7b
7
- data.tar.gz: c296a167491f4fa69b12bc8cd7daf2de7caa22b61b710ae3e8fddff567c926f0eacc9847f9e0e33a8235003ebb95d99ebbce90d9869cd2ea41489f214488d8c4
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.keys & data.keys).empty? ? return : model_object.convert(data)
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
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "watir_api"
6
- spec.version = "0.1.1"
6
+ spec.version = "0.1.2"
7
7
  spec.authors = ["Titus Fortner"]
8
8
  spec.email = ["titusfortner@gmail.com"]
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner