brandmaker 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 +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +1 -0
- data/brandmaker.gemspec +27 -0
- data/lib/brandmaker.rb +17 -0
- data/lib/brandmaker/configuration.rb +46 -0
- data/lib/brandmaker/custom_structure.rb +54 -0
- data/lib/brandmaker/external_media_variable.rb +37 -0
- data/lib/brandmaker/grid_variable.rb +55 -0
- data/lib/brandmaker/job.rb +57 -0
- data/lib/brandmaker/job_config.rb +18 -0
- data/lib/brandmaker/media_variable.rb +7 -0
- data/lib/brandmaker/variable.rb +37 -0
- data/lib/brandmaker/variable_collection.rb +26 -0
- data/lib/brandmaker/variable_config.rb +39 -0
- data/lib/brandmaker/variable_purpose.rb +7 -0
- data/lib/brandmaker/version.rb +3 -0
- data/spec/brandmaker/configuration_spec.rb +47 -0
- data/spec/brandmaker/custom_structure_spec.rb +73 -0
- data/spec/brandmaker/external_media_variable_spec.rb +72 -0
- data/spec/brandmaker/grid_variable_spec.rb +153 -0
- data/spec/brandmaker/job_spec.rb +89 -0
- data/spec/brandmaker/seed_data.rb +206 -0
- data/spec/brandmaker/variable_collection_spec.rb +56 -0
- data/spec/brandmaker/variable_spec.rb +64 -0
- data/spec/spec_helper.rb +18 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 465a9280f15999620616b433538f1160675be864
|
4
|
+
data.tar.gz: ac65d3c9d3eecec276af7c1e12306b7e07bb922f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a7607738ef57fbb3bf703eb026a1fc670f7b5e9e8904b224da915a61396a9704c51d4bd2f311d40d92812a384f801e6595694f52027d1f5cf2bf3f2054f4b26
|
7
|
+
data.tar.gz: 88868a715738c2399386f86dbe14c5c72cf26004807d67bcbad060014718748900c4042cc756d346e985309b35d4b877c1fc4ec5875ebc6d96df60dd0ff224ac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 2013-05-06 - v0.1.0
|
4
|
+
|
5
|
+
* Additional `fileType` in ExternalMediaVariable
|
6
|
+
* Disable Savon stdout logging
|
7
|
+
* Support comma separated values (last element is picked)
|
8
|
+
|
9
|
+
## 2013-04-08 - v0.0.1
|
10
|
+
|
11
|
+
* Extract common BrandMaker code
|
12
|
+
* Update and fix specs
|
13
|
+
* Remove Rails code
|
14
|
+
* Make configuration Rails independent
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sebastian de Castelberg
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Brandmaker
|
2
|
+
|
3
|
+
BrandMaker Client written in ruby. Implements Access to the
|
4
|
+
following BrandMaker APIs:
|
5
|
+
|
6
|
+
* JobManager (DSE)
|
7
|
+
|
8
|
+
Access to the Media Pool API is planned.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'brandmaker',
|
15
|
+
:git => "git@github.com:screenconcept/brandmaker.git",
|
16
|
+
:tag => 'v0.x.y'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Configuration
|
25
|
+
|
26
|
+
Enter the BrandMaker SOAP API information in a new initializer file
|
27
|
+
|
28
|
+
# file: config/initializers/brandmaker.rb
|
29
|
+
Brandmaker.configure do |conf|
|
30
|
+
conf.user = 'username'
|
31
|
+
conf.password = 'password'
|
32
|
+
conf.dse_service = 'https://<url>/webservices/dse/?wsdl'
|
33
|
+
conf.media_pool_service = 'https://<url>/webservices/MediaPool/?wsdl'
|
34
|
+
|
35
|
+
config = Brandmaker::JobConfig.new('job_type_technical_name').tap do |c|
|
36
|
+
c.add_variables(
|
37
|
+
{ :name => :JobName, :label => 'Job name' },
|
38
|
+
# ...
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
conf.job_configs = {
|
43
|
+
:job_type_technical_name => job_type_technical_name
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
Make sure to add a valid JobConfiguration for the corresponding job type.
|
48
|
+
See [here](https://github.com/screenconcept/job_manager/blob/config/initializers/brandmaker.rb) for a sample initializer file.
|
49
|
+
|
50
|
+
#### Variable Configuration
|
51
|
+
|
52
|
+
Simple variable
|
53
|
+
|
54
|
+
c.add_variables 'Variable A', 'Variable B'
|
55
|
+
|
56
|
+
Custom variable
|
57
|
+
|
58
|
+
c.add_variables { :name => :JobName, :label => 'Job name' },
|
59
|
+
|
60
|
+
Available Variable configuration options
|
61
|
+
|
62
|
+
{
|
63
|
+
name: 'Variable Name',
|
64
|
+
label: 'Human readable label',
|
65
|
+
purpose: Brandmaker::VariablePurpose.EMAIL_RECIPIENT,
|
66
|
+
content_type: :media | :grid
|
67
|
+
}
|
68
|
+
|
69
|
+
### Job fetching
|
70
|
+
|
71
|
+
Fetch a specific Job calling the find method on the `Job` class
|
72
|
+
|
73
|
+
job = Job.find 1000
|
74
|
+
# Access the variables
|
75
|
+
job.variables
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/brandmaker.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'brandmaker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "brandmaker"
|
8
|
+
gem.version = Brandmaker::VERSION
|
9
|
+
gem.authors = ["Immanuel Häussermann", "Sebastian de Castelberg"]
|
10
|
+
gem.email = ["developers@screenconcept.ch"]
|
11
|
+
gem.description = %q{Allows access to BrandMaker JobManager (DSE) and MediaPool APIs}
|
12
|
+
gem.summary = %q{Ruby based BrandMaker API}
|
13
|
+
gem.homepage = "https://github.com/screenconcept/brandmaker"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'savon', '~> 1.2.0'
|
21
|
+
gem.add_dependency 'activesupport'
|
22
|
+
gem.add_dependency 'rest-client'
|
23
|
+
gem.add_dependency 'json'
|
24
|
+
|
25
|
+
gem.add_development_dependency 'rspec'
|
26
|
+
gem.add_development_dependency 'pry'
|
27
|
+
end
|
data/lib/brandmaker.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "brandmaker/version"
|
2
|
+
require "brandmaker/configuration"
|
3
|
+
require "brandmaker/job_config"
|
4
|
+
require "brandmaker/variable_purpose"
|
5
|
+
require "brandmaker/custom_structure"
|
6
|
+
require "brandmaker/grid_variable"
|
7
|
+
require "brandmaker/job"
|
8
|
+
require "brandmaker/media_variable"
|
9
|
+
require "brandmaker/external_media_variable"
|
10
|
+
require "brandmaker/variable_config"
|
11
|
+
require "brandmaker/variable"
|
12
|
+
require "brandmaker/variable_collection"
|
13
|
+
|
14
|
+
Savon.configure do |config|
|
15
|
+
config.log = false
|
16
|
+
config.log_level = :info
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Brandmaker
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
yield(configuration)
|
9
|
+
|
10
|
+
configuration.dse_client = Savon.client do |wsdl, http, wsse|
|
11
|
+
wsdl.document = configuration.dse_service
|
12
|
+
wsdl.endpoint = configuration.dse_service
|
13
|
+
http.auth.basic(configuration.user, configuration.password)
|
14
|
+
end
|
15
|
+
|
16
|
+
configuration.media_pool_client = Savon.client do |wsdl, http, wsse|
|
17
|
+
wsdl.document = configuration.media_pool_service
|
18
|
+
wsdl.endpoint = configuration.media_pool_service
|
19
|
+
http.auth.basic(configuration.user, configuration.password)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
class Configuration
|
28
|
+
attr_accessor :user
|
29
|
+
attr_accessor :password
|
30
|
+
attr_accessor :dse_service
|
31
|
+
attr_accessor :media_pool_service
|
32
|
+
attr_accessor :external_media_service
|
33
|
+
attr_accessor :external_media_service_secret
|
34
|
+
attr_accessor :job_configs
|
35
|
+
|
36
|
+
attr_accessor :dse_client
|
37
|
+
attr_accessor :media_pool_client
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@job_configs = {}
|
41
|
+
@media_pool_client = Savon.client
|
42
|
+
@dse_client = Savon.client
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'brandmaker/configuration'
|
2
|
+
|
3
|
+
require 'savon'
|
4
|
+
|
5
|
+
module Brandmaker
|
6
|
+
class CustomStructure
|
7
|
+
extend Savon::Model
|
8
|
+
|
9
|
+
actions :find_all_custom_structures
|
10
|
+
|
11
|
+
def self.client
|
12
|
+
Brandmaker.configuration.dse_client
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def find_by_technical_name technical_name
|
17
|
+
name = custom_structure_name_for_mapped_technical_name(technical_name)
|
18
|
+
unless name.nil?
|
19
|
+
all.find { |cs| cs.name == name }
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def all
|
26
|
+
find_all_custom_structures.body[:find_all_custom_structures_response][:return][:custom_structures].collect do |data|
|
27
|
+
CustomStructure.new data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def custom_structure_name_for_mapped_technical_name technical_name
|
32
|
+
{
|
33
|
+
'anbieter_hinzufgen' => 'PM_ExterneSuppliers_Druckereien'
|
34
|
+
}[technical_name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize data
|
39
|
+
@data = data
|
40
|
+
end
|
41
|
+
|
42
|
+
def name
|
43
|
+
@data[:name]
|
44
|
+
end
|
45
|
+
|
46
|
+
def label
|
47
|
+
@data[:name]
|
48
|
+
end
|
49
|
+
|
50
|
+
def objects
|
51
|
+
@data[:objects]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Brandmaker
|
5
|
+
class ExternalMediaVariable < Variable
|
6
|
+
attr_accessor :downloadUrl
|
7
|
+
attr_accessor :fileOriginalName
|
8
|
+
attr_accessor :fileType
|
9
|
+
|
10
|
+
def value
|
11
|
+
super.split(",").last rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def reload
|
15
|
+
if value.present?
|
16
|
+
res = RestClient.get(
|
17
|
+
Brandmaker.configuration.external_media_service,
|
18
|
+
{
|
19
|
+
:params => {
|
20
|
+
:mediaID => value,
|
21
|
+
:secret => Brandmaker.configuration.external_media_service_secret
|
22
|
+
}
|
23
|
+
}
|
24
|
+
)
|
25
|
+
hash = JSON.parse(res)
|
26
|
+
error = hash['ERROR'].presence
|
27
|
+
if error
|
28
|
+
raise error
|
29
|
+
end
|
30
|
+
self.fileOriginalName = hash['fileOriginalName']
|
31
|
+
self.downloadUrl = hash['downloadUrl']
|
32
|
+
self.fileType = hash['fileType']
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
require 'brandmaker/variable'
|
4
|
+
|
5
|
+
module Brandmaker
|
6
|
+
class GridVariable < Variable
|
7
|
+
def value
|
8
|
+
begin
|
9
|
+
if custom_structure.present?
|
10
|
+
values = custom_structure_values
|
11
|
+
else
|
12
|
+
values = actual_values
|
13
|
+
end
|
14
|
+
|
15
|
+
if purpose == VariablePurpose::EMAIL_RECIPIENT
|
16
|
+
values.map { |val| extract_email val }.compact
|
17
|
+
else
|
18
|
+
values
|
19
|
+
end
|
20
|
+
rescue
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def actual_values
|
26
|
+
rows.map do |row|
|
27
|
+
row.try(:[], :variable).try(:[], :value).presence
|
28
|
+
end.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def custom_structure_values
|
32
|
+
actual_values.collect do |val|
|
33
|
+
obj = custom_structure.objects.find do |object|
|
34
|
+
object[:name] == val
|
35
|
+
end
|
36
|
+
obj[:label]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def rows
|
41
|
+
values = @data[:grid][:row]
|
42
|
+
values = [values] if values.is_a? Hash
|
43
|
+
values
|
44
|
+
end
|
45
|
+
|
46
|
+
def extract_email val
|
47
|
+
val.match(/\(([^)]+)\)/).try(:[], 1)
|
48
|
+
end
|
49
|
+
|
50
|
+
def custom_structure
|
51
|
+
@custom_structure ||= Brandmaker::CustomStructure.find_by_technical_name(self.technical_name)
|
52
|
+
@custom_structure
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'brandmaker/configuration'
|
2
|
+
|
3
|
+
require 'savon'
|
4
|
+
|
5
|
+
module Brandmaker
|
6
|
+
class Job
|
7
|
+
extend Savon::Model
|
8
|
+
|
9
|
+
actions :find_by_id
|
10
|
+
|
11
|
+
def self.client
|
12
|
+
Brandmaker.configuration.dse_client
|
13
|
+
end
|
14
|
+
|
15
|
+
# ”desriptions" is a brandmaker typo in API
|
16
|
+
|
17
|
+
def self.find id
|
18
|
+
Job.new find_by_id({:id => id}).body[:find_by_id_response][:return]
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize data
|
22
|
+
@data = data
|
23
|
+
@plain_variables ||= Brandmaker::VariableCollection.new @data[:desriptions][:variable]
|
24
|
+
end
|
25
|
+
|
26
|
+
def id
|
27
|
+
@data[:desriptions][:id]
|
28
|
+
end
|
29
|
+
|
30
|
+
def technical_name
|
31
|
+
@data[:desriptions][:type_name]
|
32
|
+
end
|
33
|
+
|
34
|
+
def config
|
35
|
+
Brandmaker.configuration.job_configs[self.technical_name.to_sym] or raise "Job #{self.id} is not configured, no config for #{self.technical_name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def variables
|
39
|
+
available_variable_names = @plain_variables.map(&:technical_name)
|
40
|
+
@variables ||= Brandmaker::VariableCollection.new(
|
41
|
+
config.variables.select do |variable_config|
|
42
|
+
available_variable_names.include? variable_config.name.to_s
|
43
|
+
end.collect do |variable_config|
|
44
|
+
variable = @plain_variables.find_by_technical_name(variable_config.name.to_s)
|
45
|
+
configured_variable = variable_config.to_typed_instance(variable.data)
|
46
|
+
configured_variable.config = variable_config
|
47
|
+
configured_variable
|
48
|
+
end, false)
|
49
|
+
end
|
50
|
+
|
51
|
+
def recipients
|
52
|
+
val = variables.find_by_purpose(VariablePurpose::EMAIL_RECIPIENT).value
|
53
|
+
val = [val] unless val.is_a? Array
|
54
|
+
val
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|