ragoon 0.5.2 → 0.6.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: 2ef078868badd41e0917f2acdcf12767f0ac11a4
4
- data.tar.gz: b08e7c4cac479050116f7148918e6d6f770ddff0
3
+ metadata.gz: fe814ed32bc7d13e09e6722ab67449e44461523a
4
+ data.tar.gz: eb5eb942bcc1ea59f4fb3791f9275b53dec50631
5
5
  SHA512:
6
- metadata.gz: 091de10493e4dd054876f012d811f0d1b03f6539a8d3c0489df736ed6e7064383b979853863ae73dd6d15a3b96f5d8ed725fcce2d89b6d58d81c7c377f7397a0
7
- data.tar.gz: d4c59ba3506d32c3d133d178aae91c95b87a8089d189ee8fcd4b6dcbb07d5e3ba3c539f5e4a5e4a14e40ba7f4a3602a378151985f096f53101555229b61fd7cb
6
+ metadata.gz: 725ee5d5a650f1ad84e7ee8472d6c007b0dbf42cea726d6bc4d79e8a849124f6bc78af048fe774ec7cb9e891d5486a0282299523b8d040e03086322cc1cb834e
7
+ data.tar.gz: 80d73ab6973c26567fb4549d022fa8fc0d2ee20ec5666a9271fb9edd5f99e501cd05df661a0a90864931ffebffab2257446b5f4c5ddc6da1200d034f4e57fbe6
data/README.md CHANGED
@@ -75,6 +75,95 @@ notifications = service.retreive
75
75
  ]
76
76
  ```
77
77
 
78
+ ### Workflow
79
+
80
+ ```
81
+ service = Ragoon::Services::Workflow.new
82
+ service.workflow_get_requests(
83
+ request_form_id: 41,
84
+ filter: 'All',
85
+ start_request_date: Time.new(2011, 6, 19, 13, 30),
86
+ end_request_date: Time.new(2014, 12, 1, 19, 50),
87
+ start_approval_date: Time.new(2011, 6, 1, 19, 40),
88
+ end_approval_date: Time.new(2014, 12, 31, 9, 45),
89
+ applicant: 14,
90
+ last_approval: 6,
91
+ start_to_get_information_from: 2,
92
+ maximum_request_amount_to_get: 10
93
+ )
94
+
95
+ => [
96
+ {:id=>"33",
97
+ :number=>"33",
98
+ :priority=>"0",
99
+ :subject=>"12月7日休日出勤",
100
+ :status=>"承認",
101
+ :applicant=>"14",
102
+ :last_approver=>"6",
103
+ :request_date=>2014-12-01 19:40:26 +0900}
104
+ ]
105
+
106
+ service.workflow_get_requests_by_id([33])
107
+
108
+ => [
109
+ {:id=>"33",
110
+ :number=>"33",
111
+ :name=>"休日出勤申請(12月7日休日出勤)",
112
+ :processing_step=>"97",
113
+ :status=>"承認",
114
+ :urgent=>"false",
115
+ :version=>"1417430538",
116
+ :date=>2014-12-01 19:40:26 +0900,
117
+ :status_type=>"approved",
118
+ :applicant=>{:id=>"14", :name=>"松田 環奈"},
119
+ :items=>
120
+ [{:name=>"社員番号", :value=>"3110342"}],
121
+ :steps=>
122
+ [{:id=>"97",
123
+ :name=>"経理担当者",
124
+ :type=>"回覧",
125
+ :is_approval_step=>"0",
126
+ :processors=>
127
+ [{:id=>"13", :name=>"加藤 美咲", :comment=>nil}]}]}
128
+ ]
129
+
130
+ service.workflow_get_sent_application_versions([
131
+ {id: 23, version: 1306486544},
132
+ {id: 20, version: 1306486544},
133
+ {id: 22, version: 1306486533},
134
+ ],
135
+ start_date: Time.new(2011, 5, 25, 18, 50),
136
+ end_date: Time.new(2011, 6, 26, 18, 0)
137
+ )
138
+
139
+ => [
140
+ {:id=>"22", :version=>"1306486534", :operation=>"modify"},
141
+ {:id=>"23", :version=>"0", :operation=>"remove"},
142
+ {:id=>"21", :version=>"1415185979", :operation=>"add"}
143
+ ]
144
+
145
+ service.workflow_get_sent_applications_by_id([21])
146
+
147
+ => [{:id=>"21",
148
+ :number=>"21",
149
+ :name=>"休日出勤申請(休日出勤申請)",
150
+ :processing_step=>"65",
151
+ :status=>"承認",
152
+ :urgent=>"false",
153
+ :version=>"1415185979",
154
+ :date=>2011-05-27 16:10:41 +0900,
155
+ :status_type=>"approved",
156
+ :applicant=>{:id=>"6", :name=>"佐藤 昇"},
157
+ :items=>
158
+ [{:name=>"社員番号", :value=>"3110334"}],
159
+ :steps=>
160
+ [{:id=>"63",
161
+ :name=>"部長",
162
+ :type=>"承認(全員)",
163
+ :is_approval_step=>"1",
164
+ :processors=>[{:id=>"6", :name=>"佐藤 昇", :comment=>nil}]}]}]
165
+ ```
166
+
78
167
  ## License
79
168
 
80
169
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -4,6 +4,7 @@ require 'ragoon/client'
4
4
  require 'ragoon/services'
5
5
  require 'ragoon/services/schedule'
6
6
  require 'ragoon/services/notification'
7
+ require 'ragoon/services/workflow'
7
8
 
8
9
  require 'nokogiri'
9
10
  require 'rest-client'
@@ -11,16 +12,12 @@ require 'rest-client'
11
12
  module Ragoon
12
13
  @@secret_options = {}
13
14
 
14
- def self.garoon_endpoint
15
- ENV['GAROON_ENDPOINT'] || secret_options[:garoon_endpoint] || raise_option_error('endpoint')
16
- end
17
-
18
- def self.garoon_username
19
- ENV['GAROON_USERNAME'] || secret_options[:garoon_username] || raise_option_error('username')
20
- end
21
-
22
- def self.garoon_password
23
- ENV['GAROON_PASSWORD'] || secret_options[:garoon_password] || raise_option_error('password')
15
+ def self.default_options
16
+ {
17
+ endpoint: ENV['GAROON_ENDPOINT'] || secret_options[:garoon_endpoint] || raise_option_error('endpoint'),
18
+ username: ENV['GAROON_USERNAME'] || secret_options[:garoon_username] || raise_option_error('username'),
19
+ password: ENV['GAROON_PASSWORD'] || secret_options[:garoon_password] || raise_option_error('password')
20
+ }
24
21
  end
25
22
 
26
23
  def self.raise_option_error(type)
@@ -1,14 +1,15 @@
1
1
  class Ragoon::Client
2
2
  attr_reader :endpoint, :response
3
3
 
4
- def initialize(endpoint)
4
+ def initialize(endpoint, options)
5
5
  @endpoint = endpoint
6
+ @options = options
6
7
  end
7
8
 
8
9
  def request(action_name, body_node)
9
10
  @action_name = action_name
10
11
  @body_node = body_node
11
- @response = RestClient.post(endpoint, Ragoon::XML.render(action_name, body_node))
12
+ @response = RestClient.post(endpoint, Ragoon::XML.render(action_name, body_node, @options))
12
13
  end
13
14
 
14
15
  def result_set
@@ -2,18 +2,19 @@ class Ragoon::Services
2
2
  SERVICE_LOCATIONS = {
3
3
  schedule: '/cbpapi/schedule/api?',
4
4
  notification: '/cbpapi/notification/api?',
5
+ workflow: '/cbpapi/workflow/api?',
5
6
  }.freeze
6
7
 
7
8
  attr_reader :client, :action_type
8
9
 
9
- def initialize
10
+ def initialize(options = Ragoon.default_options)
11
+ @options = options
10
12
  @action_type = self.class.name.split('::').pop.downcase.to_sym
11
- @client = Ragoon::Client.new(self.endpoint)
13
+ @client = Ragoon::Client.new(self.endpoint, options)
12
14
  end
13
15
 
14
16
  def endpoint
15
- endpoint = URI(Ragoon.garoon_endpoint)
16
- "#{endpoint.scheme}://#{endpoint.host}#{endpoint.path}#{SERVICE_LOCATIONS[action_type]}"
17
+ "#{base_endpoint}#{SERVICE_LOCATIONS[action_type]}"
17
18
  end
18
19
 
19
20
  def self.start_and_end(date = Date.today)
@@ -22,4 +23,12 @@ class Ragoon::Services
22
23
  end: ((date + 1).to_time - 1).utc,
23
24
  }
24
25
  end
26
+
27
+ private
28
+
29
+ def base_endpoint
30
+ endpoint = URI(@options[:endpoint])
31
+ "#{endpoint.scheme}://#{endpoint.host}#{endpoint.path}"
32
+ end
33
+
25
34
  end
@@ -106,7 +106,7 @@ class Ragoon::Services::Schedule < Ragoon::Services
106
106
  end
107
107
 
108
108
  def event_url(id)
109
- "#{Ragoon::garoon_endpoint.gsub(/\?.*\Z/, '')}/schedule/view?event=#{id}"
109
+ "#{base_endpoint}/schedule/view?event=#{id}"
110
110
  end
111
111
 
112
112
  def facility_names(event)
@@ -0,0 +1,220 @@
1
+ #
2
+ # Workflow API Service
3
+ # https://cybozudev.zendesk.com/hc/ja/articles/202270284
4
+ #
5
+ class Ragoon::Services::Workflow < Ragoon::Services
6
+
7
+ #
8
+ # for admin only
9
+ #
10
+
11
+ def workflow_get_requests(request_form_id:, **options)
12
+ action_name = 'WorkflowGetRequests'
13
+
14
+ options[:request_form_id] = request_form_id
15
+ [ :start_request_date, :end_request_date,
16
+ :start_approval_date, :end_approval_date ].each do |key|
17
+ options[key] = to_datetime(options[key]) if options.has_key?(key)
18
+ end
19
+
20
+ body_node = Ragoon::XML.create_node(action_name)
21
+ parameter_node = Ragoon::XML.create_node('parameters')
22
+ body_node.add_child(parameter_node)
23
+
24
+ manage_parameter_node = Ragoon::XML.create_node(
25
+ 'manage_request_parmeter', options)
26
+ parameter_node.add_child(manage_parameter_node)
27
+
28
+ client.request(action_name, body_node)
29
+
30
+ client.result_set.xpath('//manage_item_detail').map do |item|
31
+ {
32
+ id: item[:pid],
33
+ number: item[:number],
34
+ priority: item[:priority],
35
+ subject: item[:subject],
36
+ status: item[:status],
37
+ applicant: item[:applicant], # user_id
38
+ last_approver: item[:last_approver],
39
+ request_date: parse_time(item[:request_date]),
40
+ }
41
+ end
42
+ ensure
43
+ client.reset
44
+ end
45
+
46
+ def workflow_get_requests_by_id(ids)
47
+ action_name = 'WorkflowGetRequestById'
48
+
49
+ body_node = Ragoon::XML.create_node(action_name)
50
+ parameter_node = Ragoon::XML.create_node('parameters')
51
+ body_node.add_child(parameter_node)
52
+
53
+ ids.each do |id|
54
+ request_id_node = Ragoon::XML.create_node('request_id')
55
+ request_id_node.content = id
56
+ parameter_node.add_child(request_id_node)
57
+ end
58
+
59
+ client.request(action_name, body_node)
60
+
61
+ client.result_set.xpath('//application').map do |app|
62
+ parse_application(app)
63
+ end
64
+ ensure
65
+ client.reset
66
+ end
67
+
68
+ #
69
+ # unprocessed
70
+ #
71
+
72
+ def workflow_get_unprocessed_application_versions(id_versions = [])
73
+ get_application_versions(
74
+ 'WorkflowGetUnprocessedApplicationVersions',
75
+ nil, nil,
76
+ id_versions
77
+ )
78
+ end
79
+
80
+ def workflow_get_unprocessed_applications_by_id(ids)
81
+ get_applications_by_id('WorkflowGetUnprocessedApplicationsById', ids)
82
+ end
83
+
84
+ #
85
+ # sent
86
+ #
87
+
88
+ def workflow_get_sent_application_versions(id_versions = [], start_date:, end_date: nil)
89
+ get_application_versions(
90
+ 'WorkflowGetSentApplicationVersions',
91
+ start_date, end_date,
92
+ id_versions
93
+ )
94
+ end
95
+
96
+ def workflow_get_sent_applications_by_id(ids)
97
+ get_applications_by_id('WorkflowGetSentApplicationsById', ids)
98
+ end
99
+
100
+ #
101
+ # recieved
102
+ #
103
+
104
+ def workflow_get_received_application_versions(id_versions = [], start_date:, end_date: nil)
105
+ get_application_versions(
106
+ 'WorkflowGetReceivedApplicationVersions',
107
+ start_date, end_date,
108
+ id_versions
109
+ )
110
+ end
111
+
112
+ def workflow_get_received_applications_by_id(ids)
113
+ get_applications_by_id('WorkflowGetReceivedApplicationsById', ids)
114
+ end
115
+
116
+ private
117
+
118
+ def get_application_versions(action_name, start_date, end_date, id_versions)
119
+ body_node = Ragoon::XML.create_node(action_name)
120
+
121
+ attributes = {}
122
+ attributes['start'] = to_datetime(start_date) unless start_date.nil?
123
+ attributes['end'] = to_datetime(end_date) unless end_date.nil?
124
+ parameter_node = Ragoon::XML.create_node('parameters', attributes)
125
+ body_node.add_child(parameter_node)
126
+
127
+ id_versions.each do |item|
128
+ parameter_node << Ragoon::XML.create_node(
129
+ 'application_item',
130
+ id: item[:id], version: item[:version]
131
+ )
132
+ end
133
+
134
+ client.request(action_name, body_node)
135
+
136
+ client.result_set.xpath('//application_item').map do |item|
137
+ {
138
+ id: item['id'],
139
+ version: item['version'],
140
+ operation: item['operation']
141
+ }
142
+ end
143
+ ensure
144
+ client.reset
145
+ end
146
+
147
+ def get_applications_by_id(action_name, ids)
148
+ body_node = Ragoon::XML.create_node(action_name)
149
+
150
+ parameter_node = Ragoon::XML.create_node('parameters')
151
+ body_node.add_child(parameter_node)
152
+
153
+ ids.each do |id|
154
+ id_node = Ragoon::XML.create_node('application_id')
155
+ id_node.content = id
156
+ parameter_node.add_child(id_node)
157
+ end
158
+
159
+ client.request(action_name, body_node)
160
+
161
+ client.result_set.xpath('//application').map do |app|
162
+ parse_application(app)
163
+ end
164
+ ensure
165
+ client.reset
166
+ end
167
+
168
+ def parse_application(app)
169
+ {
170
+ id: app['id'],
171
+ number: app['number'],
172
+ name: app['name'],
173
+ processing_step: app['processing_step'],
174
+ status: app['status'],
175
+ urgent: app['urgent'],
176
+ version: app['version'],
177
+ date: parse_time(app['date']),
178
+ status_type: app['status_type'],
179
+
180
+ applicant: app.xpath('wf:applicant', wf: 'http://schemas.cybozu.co.jp/workflow/2008').map {|applicant|
181
+ {
182
+ id: applicant['id'],
183
+ name: applicant['name']
184
+ }
185
+ }.first,
186
+
187
+ items: app.xpath('wf:items/wf:item', wf: 'http://schemas.cybozu.co.jp/workflow/2008').map {|item|
188
+ {
189
+ name: item['name'],
190
+ value: item['value']
191
+ }
192
+ },
193
+
194
+ steps: app.xpath('wf:steps/wf:step', wf: 'http://schemas.cybozu.co.jp/workflow/2008').map {|step|
195
+ {
196
+ id: step['id'],
197
+ name: step['name'],
198
+ type: step['type'],
199
+ is_approval_step: step['is_approval_step'],
200
+ processors: step.xpath('wf:processor', wf: 'http://schemas.cybozu.co.jp/workflow/2008').map {|pro|
201
+ {
202
+ id: pro['id'],
203
+ name: pro['processor_name'],
204
+ comment: pro['comment']
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ end
211
+
212
+ def parse_time(time)
213
+ Time.parse(time).localtime
214
+ end
215
+
216
+ def to_datetime(str)
217
+ str.utc.strftime('%FT%TZ')
218
+ end
219
+
220
+ end
@@ -1,3 +1,3 @@
1
1
  module Ragoon
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -2,8 +2,8 @@ module Ragoon::XML
2
2
  ACTION_PLACEHOLDER = '<!-- REQUEST_ACTION -->'.freeze
3
3
  BODY_PLACEHOLDER = '<!-- REQUEST_BODY -->'.freeze
4
4
 
5
- def self.render(action_name, body_node)
6
- template.dup.
5
+ def self.render(action_name, body_node, options)
6
+ template(options).dup.
7
7
  gsub!(ACTION_PLACEHOLDER, action_name).
8
8
  gsub!(BODY_PLACEHOLDER, body_node.to_xml)
9
9
  end
@@ -16,7 +16,7 @@ module Ragoon::XML
16
16
  node
17
17
  end
18
18
 
19
- def self.template
19
+ def self.template(options)
20
20
  <<"XML"
21
21
  <?xml version="1.0" encoding="UTF-8"?>
22
22
  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
@@ -33,8 +33,8 @@ module Ragoon::XML
33
33
  SOAP-ENV:mustUnderstand="1"
34
34
  xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext">
35
35
  <UsernameToken wsu:Id="id">
36
- <Username>#{Ragoon.garoon_username}</Username>
37
- <Password>#{Ragoon.garoon_password}</Password>
36
+ <Username>#{options[:username]}</Username>
37
+ <Password>#{options[:password]}</Password>
38
38
  </UsernameToken>
39
39
  </Security>
40
40
  <Timestamp SOAP-ENV:mustUnderstand="1" Id="id"
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: 0.5.2
4
+ version: 0.6.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: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -115,6 +115,7 @@ files:
115
115
  - lib/ragoon/services.rb
116
116
  - lib/ragoon/services/notification.rb
117
117
  - lib/ragoon/services/schedule.rb
118
+ - lib/ragoon/services/workflow.rb
118
119
  - lib/ragoon/version.rb
119
120
  - lib/ragoon/xml.rb
120
121
  - ragoon.gemspec