ragoon 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23616cbfc914424fbaae35704b3e75882cbf07c6
4
- data.tar.gz: 78a00db94a1831c7b0d74eda848e422b09dcd9cc
3
+ metadata.gz: 6d599f1d03691cb88ef6728c4cecdbf69d1762ef
4
+ data.tar.gz: 18f8ce5b9989c066663da7f0079db320510b499a
5
5
  SHA512:
6
- metadata.gz: 9729d0754e37771f8fc7e9de50d7f7234c3aed0bf567a1c6372a0d921ba4d00045c59b7fdd3312c74f16e805595490808154d8241206863853d83ccbb0431adf
7
- data.tar.gz: 208f461513e1024985d2bf0041a96555c7da2eb074c1622ed6e3dad5340981640ca83c74848d5b062a6492895d1460f2cfeafc8a8bf42d7e6dee4fb9e6da6d92
6
+ metadata.gz: '009eefbef6e6e0175c27233b6ff1fa167806601f7fc1ead1f17cb3556759ddb5fba0977f71ae3eb1ed2a80db810b6e8a16cef3a84395dbefe24292735644a89c'
7
+ data.tar.gz: d5e4ad9a3f7f5bfd8f9c478f8a40207d4ce8c9bedf49d57dc07634bf11ef74e828d61d47d1bbbbd6da8d7f7d0275aa763f4fc236b1ea4436749f347931a8e978
data/.gitignore CHANGED
@@ -8,7 +8,6 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /vendor/bundle/
11
- /.secret_options
11
+ /.secret_options*
12
12
  /build/
13
13
  /release/
14
-
@@ -4,6 +4,7 @@ require 'time'
4
4
 
5
5
  require 'ragoon/version'
6
6
  require 'ragoon/xml'
7
+ require 'ragoon/error'
7
8
  require 'ragoon/client'
8
9
  require 'ragoon/services'
9
10
  require 'ragoon/services/schedule'
@@ -15,10 +16,11 @@ module Ragoon
15
16
 
16
17
  def self.default_options
17
18
  {
18
- endpoint: ENV['GAROON_ENDPOINT'] || secret_options[:garoon_endpoint] || raise_option_error('endpoint'),
19
- username: ENV['GAROON_USERNAME'] || secret_options[:garoon_username] || raise_option_error('username'),
20
- password: ENV['GAROON_PASSWORD'] || secret_options[:garoon_password] || raise_option_error('password'),
21
- version: ENV['GAROON_VERSION'] || secret_options[:garoon_version] || 4
19
+ endpoint: ENV['GAROON_ENDPOINT'] || raise_option_error('endpoint'),
20
+ username: ENV['GAROON_USERNAME'] || raise_option_error('username'),
21
+ password: ENV['GAROON_PASSWORD'] || raise_option_error('password'),
22
+ version: ENV['GAROON_VERSION'] || 4,
23
+ retry: ENV['GAROON_RETRY'] || 10,
22
24
  }
23
25
  end
24
26
 
@@ -30,8 +32,11 @@ module Ragoon
30
32
 
31
33
  def self.secret_options
32
34
  if @@secret_options.empty?
33
- raise '`./.secret_options` is required.' unless File.exists?('./.secret_options')
34
- @@secret_options = eval(File.read('./.secret_options'))
35
+ if File.exist?('./.secret_options')
36
+ @@secret_options = eval(File.read('./.secret_options'))
37
+ else
38
+ @@secret_options = default_options
39
+ end
35
40
  end
36
41
  @@secret_options
37
42
  end
@@ -7,9 +7,20 @@ class Ragoon::Client
7
7
  end
8
8
 
9
9
  def request(action_name, body_node)
10
- @action_name = action_name
11
- @body_node = body_node
12
- @response = RestClient.post(endpoint, Ragoon::XML.render(action_name, body_node, @options))
10
+ retry_count = @options[:retry].to_i
11
+
12
+ retry_count.times do
13
+ begin
14
+ request_once(action_name, body_node)
15
+ return
16
+ rescue Ragoon::Error => e
17
+ unless e.message.include?('指定された画面はアクセスできません。')
18
+ raise e
19
+ end
20
+ sleep(0.5)
21
+ end
22
+ end
23
+ raise Ragoon::Error.new("試行回数が#{retry_count}回を超えたので終了しました。")
13
24
  end
14
25
 
15
26
  def result_set
@@ -19,4 +30,22 @@ class Ragoon::Client
19
30
  def reset
20
31
  @result_set = nil
21
32
  end
33
+
34
+ private
35
+
36
+ def request_once(action_name, body_node)
37
+ reset
38
+ @action_name = action_name
39
+ @body_node = body_node
40
+ @response = RestClient.post(endpoint, Ragoon::XML.render(action_name, body_node, @options))
41
+ ensure
42
+ raise_error unless result_set.xpath('//soap:Fault').empty?
43
+ end
44
+
45
+ def raise_error
46
+ raise Ragoon::Error.new(
47
+ result_set.xpath('//soap:Reason').text.strip,
48
+ result_set.xpath('//soap:Detail/*').map { |c| [c.name, c.text.strip] }.to_h
49
+ )
50
+ end
22
51
  end
@@ -0,0 +1,24 @@
1
+ class Ragoon::Error < StandardError
2
+ def initialize(message = nil, details = {})
3
+ super(message)
4
+ @details = details
5
+ end
6
+
7
+ attr_reader :details
8
+
9
+ def code
10
+ @details['code']
11
+ end
12
+
13
+ def diagnosis
14
+ @details['diagnosis']
15
+ end
16
+
17
+ def cause
18
+ @details['cause']
19
+ end
20
+
21
+ def counter_measure
22
+ @details['counter_measure']
23
+ end
24
+ end
@@ -7,7 +7,7 @@ class Ragoon::Services
7
7
 
8
8
  attr_reader :client, :action_type
9
9
 
10
- def initialize(options = Ragoon.default_options)
10
+ def initialize(options = Ragoon.secret_options)
11
11
  @options = options
12
12
  @action_type = self.class.name.split('::').pop.downcase.to_sym
13
13
  @client = Ragoon::Client.new(self.endpoint, options)
@@ -1,3 +1,3 @@
1
1
  module Ragoon
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIOYA, Hiromu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -112,6 +112,7 @@ files:
112
112
  - bin/setup
113
113
  - lib/ragoon.rb
114
114
  - lib/ragoon/client.rb
115
+ - lib/ragoon/error.rb
115
116
  - lib/ragoon/services.rb
116
117
  - lib/ragoon/services/notification.rb
117
118
  - lib/ragoon/services/schedule.rb
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubyforge_project:
142
- rubygems_version: 2.6.8
143
+ rubygems_version: 2.6.13
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: Ragoon is a simple Garoon 3 API client.