mio-config 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e89eebb32948e70e99580986e17078ed767c0175
4
- data.tar.gz: 7364a61d783d97994c2f4b7d0e2cc77dc3fa80be
3
+ metadata.gz: 9b537238571c23ae727d460f69433f156a60551d
4
+ data.tar.gz: 29ecbac1e9932354cd695d1a965516e183d3fd43
5
5
  SHA512:
6
- metadata.gz: 6f1713418b1c39742fa3318d3d2e96a0c2eeeb55a7c96a6497dbb0966ec07eeceebb7a287311ba30f6551876b4eba7f8c50f112e91678f3403a97ec2aed8eb53
7
- data.tar.gz: 6dc11edcc8664cc6b8bc492b99828032407a6b5b0f05299aedda57ce2e4a0fdad55d042b7790a2fe42294d2ac625cd69660a85c6bafb4aa240bed7881c047ae1
6
+ metadata.gz: 8afc13b5ee2df8f1ec4da287db3f2d99078858ed3251705736ee7d07b4c5cef58b36f4f5d8d9127e2d34e53edac8964792fc13d49ad63315e9b63f44dac1c65a
7
+ data.tar.gz: 0580d40dd0b841e821e2e04ab30da860d8115a0c079542dc7db542332bb8d785aca96b59595cc9a4aa78e2715530b1dda3ce31202ee9a0391a7ccaa81cf5e32b
data/lib/mio/client.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  require 'faraday'
2
2
  require 'faraday/detailed_logger'
3
- require 'ostruct'
4
- require 'net/http/persistent'
5
3
  require 'json'
6
-
7
- require 'pp'
8
-
9
4
  require 'mio/requests'
5
+ require 'net/http/persistent'
6
+ require 'nokogiri'
7
+ require 'ostruct'
8
+ require 'pp'
10
9
 
11
10
  class Mio
12
11
  class Client
@@ -20,9 +19,9 @@ class Mio
20
19
  @agent.basic_auth(username, password)
21
20
  end
22
21
 
23
- def find_all resource, opts={}
22
+ def find_all resource, opts={}, accept='application/json'
24
23
  url = path(resource)
25
- response = get url, opts
24
+ response = get url, opts, accept
26
25
 
27
26
  unless response.success?
28
27
  raise Mio::Client::LoadOfBollocks, "GET on #{url} returned #{response.status}"
@@ -70,6 +69,17 @@ class Mio
70
69
  make_object response.body
71
70
  end
72
71
 
72
+
73
+ def template resource, payload, opts={}
74
+ url = path(resource)
75
+ response = put url, payload, opts, 'text/html', 'text/html'
76
+ unless response.success?
77
+ raise Mio::Client::LoadOfBollocks, "PUT on #{url}, with #{payload.inspect} returned #{response.status}"
78
+ end
79
+
80
+ Nokogiri::HTML(response.body)
81
+ end
82
+
73
83
  def action resource, id, payload, opts={}
74
84
  url = path(resource, id, :actions)
75
85
  statuses = get url, opts
@@ -88,16 +98,16 @@ class Mio
88
98
  end
89
99
 
90
100
  private
91
- def get url, opts
92
- Mio::Requests.make_request :get, @agent, url, opts
101
+ def get url, opts, accept='application/json'
102
+ Mio::Requests.make_request :get, @agent, url, opts, accept
93
103
  end
94
104
 
95
105
  def post url, payload, opts
96
106
  Mio::Requests.make_request :post, @agent, url, opts, payload
97
107
  end
98
108
 
99
- def put url, payload, opts, content_type='application/vnd.nativ.mio.v1+json'
100
- Mio::Requests.make_request :put, @agent, url, opts, payload, content_type
109
+ def put url, payload, opts, content_type='application/vnd.nativ.mio.v1+json', accept='application/json'
110
+ Mio::Requests.make_request :put, @agent, url, opts, payload, content_type, accept
101
111
  end
102
112
 
103
113
  def make_object response
data/lib/mio/model.rb CHANGED
@@ -123,7 +123,7 @@ class Mio
123
123
  private
124
124
  def look_up
125
125
  r = self.class.resource_name
126
- all_resources = @client.find_all(r)
126
+ all_resources = @client.find_all r
127
127
  return nil if all_resources['totalCount'] == 0
128
128
 
129
129
  all_resources[r].find{|o| o['name'] == @args.name}
@@ -5,13 +5,9 @@ class Mio
5
5
 
6
6
  field :name, String, 'Name of the Email Message Action'
7
7
  field :visibility, Array, 'Ids of the accounts which may see the import action', [4]
8
- field :template, Fixnum, 'Id of email template'
8
+ field :template, String, 'Name of email template'
9
9
  field :recipientExpression, String, 'Evaluated Expression value which generates an email address', '${job.mioObject.owner.email}'
10
10
 
11
- # @TODO mio api does not currently support templates
12
- # templates CRUD needs to be automated via mio-config
13
- # templates should be looked up by name rather than by id ^^
14
-
15
11
  field :enable, Symbol, ':true or :false', :true
16
12
  field :start, Symbol, ':true or :false', :true
17
13
 
@@ -25,10 +21,20 @@ class Mio
25
21
  }
26
22
  end
27
23
 
28
- def config_hash
29
- # @TODO Get the Email Template id from the template name
24
+ def get_message_template_id mesage_template_name
25
+ r = 'messageTemplates'
26
+ message_templates = @client.find_all(r)
27
+
28
+ md = message_templates[r].find{|md| md['name'] == mesage_template_name}
29
+ if md.nil?
30
+ raise Mio::Model::NoSuchResource, 'No such message template [' + mesage_template_name + ']'
31
+ end
30
32
 
31
- { :'message-template' => { id: @args.template },
33
+ md['id']
34
+ end
35
+
36
+ def config_hash
37
+ { :'message-template' => { id: get_message_template_id(@args.template) },
32
38
  recipients: { expression: [ { value: @args.recipientExpression, isExpression: false } ] }
33
39
  }
34
40
  end
@@ -0,0 +1,40 @@
1
+ class Mio
2
+ class Model
3
+ class MessageTemplate < Model
4
+ set_resource :messageTemplates
5
+
6
+ field :name, String, 'Name of the Email Message Action'
7
+ field :visibility, Array, 'Ids of the accounts which may see the import action', [4]
8
+ field :subject, String, 'Subject of email'
9
+ field :priority, String, 'Email Priority - Highest, High, Normal, Low, Lowest', 'Normal'
10
+ field :template, String, 'Email template HTML'
11
+
12
+ field :enable, Symbol, ':true or :false', :true
13
+ field :start, Symbol, ':true or :false', :true
14
+
15
+ def create_hash
16
+ {name: @args.name,
17
+ visibilityIds: @args.visibility,
18
+ subject: @args.subject,
19
+ priority: @args.priority
20
+ }
21
+ end
22
+
23
+ def go
24
+ unless look_up
25
+ @object = create
26
+ else
27
+ @object = look_up
28
+ set_start :stop
29
+ end
30
+ template_path = "#{self.class.resource_name}/#{@object['id']}/body"
31
+
32
+ @client.template template_path, @args.template
33
+
34
+ set_enable
35
+ return @object
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -61,9 +61,9 @@ class Mio
61
61
  validation_handler = hash.fetch(:validationHandler)
62
62
  unless validation_handler.nil?
63
63
  child.validation handler: validation_handler
64
- else
65
- child.validation handler: validation_handler_by_type(type)
66
64
  end
65
+ else
66
+ child.validation handler: validation_handler_by_type(type)
67
67
  end
68
68
  if hash.key?(:formType)
69
69
  child.send("form-type", hash.fetch(:formType))
data/lib/mio/requests.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Mio
2
2
  module Requests
3
3
 
4
- def self.make_request type, agent, url, opts, body=nil, content_type='application/vnd.nativ.mio.v1+json'
4
+ def self.make_request type, agent, url, opts, body=nil, content_type='application/vnd.nativ.mio.v1+json', accept='application/json'
5
5
  if content_type.nil?
6
6
  content_type = 'application/vnd.nativ.mio.v1+json'
7
7
  end
@@ -15,6 +15,7 @@ class Mio
15
15
  end
16
16
  end
17
17
  r.headers[:content_type] = content_type
18
+ r.headers[:accept]= accept
18
19
  end
19
20
  end
20
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mio-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jspc
@@ -102,32 +102,33 @@ extensions: []
102
102
  extra_rdoc_files:
103
103
  - README.md
104
104
  files:
105
- - "./lib/mio.rb"
106
- - "./lib/mio/client.rb"
107
- - "./lib/mio/config.rb"
108
- - "./lib/mio/errors.rb"
109
- - "./lib/mio/migrations.rb"
110
- - "./lib/mio/model.rb"
111
- - "./lib/mio/model/autoload.rb"
112
- - "./lib/mio/model/email_message_action.rb"
113
- - "./lib/mio/model/groovy_script.rb"
114
- - "./lib/mio/model/groovy_script_wait.rb"
115
- - "./lib/mio/model/hotfolder.rb"
116
- - "./lib/mio/model/import_action.rb"
117
- - "./lib/mio/model/metadata_definition.rb"
118
- - "./lib/mio/model/metadatadefinition/definition.rb"
119
- - "./lib/mio/model/metadatadefinition/option.rb"
120
- - "./lib/mio/model/place_holder_group_asset_action.rb"
121
- - "./lib/mio/model/s3.rb"
122
- - "./lib/mio/model/variant.rb"
123
- - "./lib/mio/model/workflow.rb"
124
- - "./lib/mio/model/workflow/node.rb"
125
- - "./lib/mio/model/workflow/transition.rb"
126
- - "./lib/mio/requests.rb"
127
- - "./lib/mio/search.rb"
128
- - "./lib/mio/tasks.rb"
129
- - "./lib/mio/tasks/migrations.rb"
130
- - "./lib/mio/tasks/skeletons.rb"
105
+ - "./lib//mio.rb"
106
+ - "./lib//mio/client.rb"
107
+ - "./lib//mio/config.rb"
108
+ - "./lib//mio/errors.rb"
109
+ - "./lib//mio/migrations.rb"
110
+ - "./lib//mio/model.rb"
111
+ - "./lib//mio/model/autoload.rb"
112
+ - "./lib//mio/model/email_message_action.rb"
113
+ - "./lib//mio/model/groovy_script.rb"
114
+ - "./lib//mio/model/groovy_script_wait.rb"
115
+ - "./lib//mio/model/hotfolder.rb"
116
+ - "./lib//mio/model/import_action.rb"
117
+ - "./lib//mio/model/message_template.rb"
118
+ - "./lib//mio/model/metadata_definition.rb"
119
+ - "./lib//mio/model/metadatadefinition/definition.rb"
120
+ - "./lib//mio/model/metadatadefinition/option.rb"
121
+ - "./lib//mio/model/place_holder_group_asset_action.rb"
122
+ - "./lib//mio/model/s3.rb"
123
+ - "./lib//mio/model/variant.rb"
124
+ - "./lib//mio/model/workflow.rb"
125
+ - "./lib//mio/model/workflow/node.rb"
126
+ - "./lib//mio/model/workflow/transition.rb"
127
+ - "./lib//mio/requests.rb"
128
+ - "./lib//mio/search.rb"
129
+ - "./lib//mio/tasks.rb"
130
+ - "./lib//mio/tasks/migrations.rb"
131
+ - "./lib//mio/tasks/skeletons.rb"
131
132
  - README.md
132
133
  homepage: https://ft.com
133
134
  licenses: