matterhorn_whymper 0.0.2 → 0.0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzFjMzFkMjcxNDYyMTZlZjM1NjVkMTBmMTUzNmJmNTI1N2ZiN2I1NA==
4
+ MzEwYzM5Nzg5YmFkZmU2MjNlZDZhMzQ5NDg3ZTRlNjc1MWU3YzdhZQ==
5
5
  data.tar.gz: !binary |-
6
- MmFkNTAxNDM0M2ZiM2FlMzViNTczYjYzNjcxYzI4YTNjNDNjMjhkYQ==
6
+ ZDNhNmEyZTE5YWYzYTY0ZGQwOGNhNDY2YzMyYjEzNzc1NmFlYTU0ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTc5ZGRlNGNkNGZlY2NhZGI4ZDY5YTgyNWFiMzUwYWQ2NmRmNzg4ZjA5ZTM0
10
- MmU3MjY3YjNhYzI5ZjFmYWQ2NDIwOGE1ZjExNzY0NmI0ZmNkNGI0NTNkZWQz
11
- NzVmZjQ3Njg4MGFhOThhNDQwMTc0NzI0NWQ1NWNhNzM4NWJjNTM=
9
+ NjUyZjBkMTI1MzI2YjI0YjBmOGE0Mjc3NjZmMDFjN2EzNzQxMGMwNWI2NGJj
10
+ MzJkYjkyZTBmMzY1NDliNjY0YWFiMmU0YTBjZWNhYzc5ZmM2ZTBlN2I4OWUy
11
+ MjMyOTk5YzZkODdjYmRjZGUxMjNhMDM5NTczN2JkOWE4MzhjNTM=
12
12
  data.tar.gz: !binary |-
13
- NDEzZjUwZDMwZjhmZWY3NWI3YjQxODk4ZWViNzEyMDJkNjY4M2EyNmVkMzNi
14
- YmYwMjVmMjVmNTY2ZGNlZTNhNzkzOWI3ZDM1YWZmNTE3YjQ5NWYzN2U0ODJk
15
- ZmFjY2FhMDRhYjE3M2FmNTEwNDI0NTA5NmZmZGJmYmMzNjUxYTM=
13
+ YWU5ZTIzMGJlY2NjZDU0ODEyNTc3MWExMzlkYTg4YTNiZjA2NWE5NGRhNWU4
14
+ Y2E5MzRlZWVjMDQxZTM0M2UyYmQ2OTIwZmRjOGUyMDY3NWI3OTM2NzBiOTRm
15
+ YTYyZmZjYWE5ZTI2ZmRiYTBjNjlhYWU5YzQ1MjczNzFhY2ZmNzI=
@@ -1,99 +1,155 @@
1
- class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
1
+ # ================================================================= Matterhorn::Endpoint::Ingest ===
2
2
 
3
- # --- attributes -------------------------------------------------------------
3
+ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
4
4
 
5
5
 
6
- # --- end point methodes -----------------------------------------------------
6
+ # -------------------------------------------------------------------------- endpoint methodes ---
7
7
 
8
8
  def addAttachment(file, flavor)
9
- if @media_pkg_remote.nil?
10
- raise(Matterhorn::Error, "No media package is available!")
9
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
10
+ @media_pkg_local.add_attachment(file, flavor) if @media_pkg_local
11
+ begin
12
+ @media_pkg_remote = http_client.post(
13
+ "ingest/addAttachment",
14
+ { 'flavor' => flavor,
15
+ 'mediaPackage' => @media_pkg_remote,
16
+ 'BODY' => file
17
+ }
18
+ ).body
19
+ rescue Matterhorn::HttpClientError => ex
20
+ MatterhornWhymper.logger.error { "#{self.class.name}::addAttachment | " +
21
+ "Media package not valid! / media package:\n#{@media_pkg_remote}" }
22
+ raise ex
23
+ rescue Matterhorn::HttpServerError => ex
24
+ MatterhornWhymper.logger.error { "#{self.class.name}::addAttachment | " +
25
+ "Internal server error on Matterhorn!" }
26
+ raise ex
11
27
  end
12
- @media_pkg_local.add_attachment(file, flavor)
13
- @media_pkg_remote = http_client.post(
14
- "ingest/addAttachment",
15
- { 'flavor' => flavor,
16
- 'mediaPackage' => @media_pkg_remote,
17
- 'BODY' => file
18
- }
19
- ).body
28
+ @media_pkg_remote
20
29
  end
21
30
 
22
31
 
23
32
  def addCatalog(file, flavor)
24
- if @media_pkg_remote.nil?
25
- raise(Matterhorn::Error, "No media package is available!")
33
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
34
+ @media_pkg_local.add_catalog(file, flavor) if @media_pkg_local
35
+ begin
36
+ @media_pkg_remote = http_client.post(
37
+ "ingest/addCatalog",
38
+ { 'flavor' => flavor,
39
+ 'mediaPackage' => @media_pkg_remote,
40
+ 'BODY' => file
41
+ }
42
+ ).body
43
+ rescue Matterhorn::HttpClientError => ex
44
+ MatterhornWhymper.logger.error { "#{self.class.name}::addCatalog | " +
45
+ "Media package not valid! / media package:\n#{@media_pkg_remote}" }
46
+ raise ex
47
+ rescue Matterhorn::HttpServerError => ex
48
+ MatterhornWhymper.logger.error { "#{self.class.name}::addCatalog | " +
49
+ "Internal server error on Matterhorn!" }
50
+ raise ex
26
51
  end
27
- @media_pkg_local.add_catalog(file, flavor)
28
- @media_pkg_remote = http_client.post(
29
- "ingest/addCatalog",
30
- { 'flavor' => flavor,
31
- 'mediaPackage' => @media_pkg_remote,
32
- 'BODY' => file
33
- }
34
- ).body
52
+ @media_pkg_remote
35
53
  end
36
54
 
37
55
 
38
56
  def addDCCatalog(dublin_core)
39
- if @media_pkg_remote.nil?
40
- raise(Matterhorn::Error, "No media package is available!")
57
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
58
+ @media_pkg_local.add_dc_catalog(dublin_core) if @media_pkg_local
59
+ begin
60
+ @media_pkg_remote = http_client.post(
61
+ "ingest/addDCCatalog",
62
+ { 'flavor' => 'dublincore/episode',
63
+ 'mediaPackage' => @media_pkg_remote,
64
+ 'dublinCore' => dublin_core
65
+ }
66
+ ).body
67
+ rescue Matterhorn::HttpClientError => ex
68
+ MatterhornWhymper.logger.error { "#{self.class.name}::addDCCatalog | " +
69
+ "Media package not valid! / media package:\n#{@media_pkg_remote}" }
70
+ raise ex
71
+ rescue Matterhorn::HttpServerError => ex
72
+ MatterhornWhymper.logger.error { "#{self.class.name}::addDCCatalog | " +
73
+ "Internal server error on Matterhorn!" }
74
+ raise ex
41
75
  end
42
- @media_pkg_local.add_dc_catalog(dublin_core)
43
- @media_pkg_remote = http_client.post(
44
- "ingest/addDCCatalog",
45
- { 'flavor' => 'dublincore/episode',
46
- 'mediaPackage' => @media_pkg_remote,
47
- 'dublinCore' => dublin_core
48
- }
49
- ).body
76
+ @media_pkg_remote
50
77
  end
51
78
 
52
79
 
53
80
  def addTrack(file, flavor)
54
- if @media_pkg_remote.nil?
55
- raise(Matterhorn::Error, "No media package is available!")
81
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
82
+ @media_pkg_local.add_track(file, flavor) if @media_pkg_local
83
+ begin
84
+ @media_pkg_remote = http_client.post(
85
+ "ingest/addTrack",
86
+ { 'flavor' => flavor,
87
+ 'mediaPackage' => @media_pkg_remote,
88
+ 'BODY' => file
89
+ }
90
+ ).body
91
+ rescue Matterhorn::HttpClientError => ex
92
+ MatterhornWhymper.logger.error { "#{self.class.name}::addTrack | " +
93
+ "Media package not valid! / media package:\n#{@media_pkg_remote}" }
94
+ raise ex
95
+ rescue Matterhorn::HttpServerError => ex
96
+ MatterhornWhymper.logger.error { "#{self.class.name}::addTrack | " +
97
+ "Internal server error on Matterhorn!" }
98
+ raise ex
56
99
  end
57
- @media_pkg_local.add_track(file, flavor)
58
- @media_pkg_remote = http_client.post(
59
- "ingest/addTrack",
60
- { 'flavor' => flavor,
61
- 'mediaPackage' => @media_pkg_remote,
62
- 'BODY' => file
63
- }
64
- ).body
100
+ @media_pkg_remote
65
101
  end
66
102
 
67
103
 
68
- def createMediaPackage(path = '')
69
- if !@media_pkg_remote.nil?
70
- raise(Matterhorn::Error, "A media package is allready created!")
104
+ # Create a media package on the matterhorn server.
105
+ # If the source_path to the source folder of uploaded items for that media package is given,
106
+ # then a local media description file 'manifest.xml' will be automaticaly saved in that folder.
107
+ #
108
+ def createMediaPackage(source_path = nil)
109
+ if @media_pkg_remote then raise(Matterhorn::Error, "A media package is allready created!"); end
110
+ @media_pkg_local = source_path ? Matterhorn::MediaPackage.new(source_path) : nil
111
+ begin
112
+ @media_pkg_remote = http_client.get(
113
+ "ingest/createMediaPackage"
114
+ ).body
115
+ rescue Matterhorn::HttpServerError => ex
116
+ MatterhornWhymper.logger.error { "#{self.class.name}::createMediaPackage | " +
117
+ "Internal server error on Matterhorn!" }
118
+ raise ex
71
119
  end
72
- @media_pkg_local = Matterhorn::MediaPackage.new(path)
73
- @media_pkg_remote = http_client.get(
74
- "ingest/createMediaPackage"
75
- ).body
120
+ @media_pkg_remote
76
121
  end
77
122
 
78
123
 
79
124
  def ingest(wdID = 'full', options = {})
80
- if @media_pkg_remote.nil?
81
- raise(Matterhorn::Error, "No media package is available!")
82
- end
83
- @media_pkg_local.save if !@media_pkg_local.nil?
125
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
126
+ @media_pkg_local.save if @media_pkg_local
84
127
  options['mediaPackage'] = @media_pkg_remote
85
- @workflow_inst = http_client.post(
86
- "ingest/ingest/#{wdID}",
87
- options
88
- ).body
128
+ begin
129
+ @workflow_inst = http_client.post(
130
+ "ingest/ingest/#{wdID}",
131
+ options
132
+ ).body
133
+ rescue Matterhorn::HttpClientError => ex
134
+ MatterhornWhymper.logger.error { "#{self.class.name}::ingest | " +
135
+ "Media package not valid! / media package:\n#{@media_pkg_remote}" }
136
+ raise ex
137
+ rescue Matterhorn::HttpServerError => ex
138
+ MatterhornWhymper.logger.error { "#{self.class.name}::ingest | " +
139
+ "Internal server error on Matterhorn!" }
140
+ raise ex
141
+ end
89
142
  workflow_instance
90
143
  end
91
144
 
92
145
 
146
+ # ---------------------------------------------------------------------------- helper methodes ---
147
+
93
148
  def media_package(kind = 'local')
94
- if kind == 'local' && !@media_pkg_local.nil?
149
+ unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
150
+ if kind == 'local' && @media_pkg_local
95
151
  return @media_pkg_local
96
- elsif !@media_pkg_remote.nil?
152
+ elsif @media_pkg_remote
97
153
  Matterhorn::MediaPackage.new(@media_pkg_remote)
98
154
  else
99
155
  nil
@@ -113,12 +169,8 @@ DUBLIN_CORE
113
169
 
114
170
 
115
171
  def workflow_instance
116
- if !@workflow_inst.nil?
117
- Matterhorn::WorkflowInstance.new(@workflow_inst)
118
- else
119
- nil
120
- end
172
+ @workflow_inst ? Matterhorn::WorkflowInstance.new(@workflow_inst) : nil
121
173
  end
122
174
 
123
175
 
124
- end
176
+ end # --------------------------------------------------------- end Matterhorn::Endpoint::Ingest ---
@@ -1,67 +1,95 @@
1
- class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
1
+ # =============================================================== Matterhorn::Endpoint::Workflow ===
2
2
 
3
- # --- attributes -------------------------------------------------------------
3
+ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
4
4
 
5
5
 
6
- # --- end point methodes -----------------------------------------------------
6
+ # -------------------------------------------------------------------------- endpoint methodes ---
7
7
 
8
8
  def instance(wi_id)
9
- @workflow_inst = http_client.get(
10
- "workflow/instance/#{wi_id}.xml"
11
- ).body
12
- workflow_instance
9
+ begin
10
+ wi = http_client.get(
11
+ "workflow/instance/#{wi_id}.xml"
12
+ ).body
13
+ rescue Matterhorn::HttpClientError, Matterhorn::HttpServerError => ex
14
+ if ex.code == 404
15
+ wi = nil
16
+ MatterhornWhymper.logger.warn { "#{self.class.name}::instance | " +
17
+ "WorkflowInstance[#{wi_id}]: No workflow instance with that identifier exists." }
18
+ else
19
+ MatterhornWhymper.logger.error { "#{self.class.name}::instance | " +
20
+ "WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
21
+
22
+ raise ex
23
+ end
24
+ end
25
+ wi ? Matterhorn::WorkflowInstance.new(wi) : nil
13
26
  end
14
27
 
15
28
 
16
- def remove(wi_id, options = {})
29
+ def remove(wi_id)
17
30
  begin
18
- @workflow_inst = http_client.delete(
31
+ http_client.delete(
19
32
  "workflow/remove/#{wi_id}"
20
- ).body
21
- rescue Matterhorn::HttpClientError => ex
22
- Rails.logger.warn { "Matterhorn::Workflow::remove | WorkflowInstance[wi_id] could not be stopped!\n" +
23
- "#{ex.class.name}: #{ex.to_s} / backtrace:\n#{ex.backtrace.join("\n")}" }
24
- return nil
25
- rescue => ex
26
- raise ex
33
+ )
34
+ wi_removed = true
35
+ rescue Matterhorn::HttpClientError, Matterhorn::HttpServerError => ex
36
+ if ex.code == 404
37
+ wi_removed = false
38
+ MatterhornWhymper.logger.warn { "#{self.class.name}::remove | " +
39
+ "WorkflowInstance[#{wi_id}]: No workflow instance with that identifier exists." }
40
+ else
41
+ MatterhornWhymper.logger.error { "#{self.class.name}::remove | " +
42
+ "WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
43
+
44
+ raise ex
45
+ end
27
46
  end
47
+ wi_removed
28
48
  end
29
49
 
30
50
 
31
- def resume(wi_id, options = {})
32
- options['id'] = wi_id
33
- @workflow_inst = http_client.post(
34
- "workflow/resume",
35
- options
36
- ).body
37
- workflow_instance
51
+ def resume(wi_id)
52
+ begin
53
+ wi = http_client.post(
54
+ "workflow/resume",
55
+ { 'id' => wi_id }
56
+ ).body
57
+ rescue Matterhorn::HttpClientError, Matterhorn::HttpServerError => ex
58
+ if ex.code == 404
59
+ wi = nil
60
+ MatterhornWhymper.logger.warn { "#{self.class.name}::resume | " +
61
+ "WorkflowInstance[#{wi_id}]: No suspended workflow instance with that identifier exists." }
62
+ else
63
+ MatterhornWhymper.logger.error { "#{self.class.name}::resume | " +
64
+ "WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
65
+
66
+ raise ex
67
+ end
68
+ end
69
+ wi ? Matterhorn::WorkflowInstance.new(wi) : nil
38
70
  end
39
71
 
40
72
 
41
- def stop(wi_id, options = {})
73
+ def stop(wi_id)
42
74
  begin
43
- options['id'] = wi_id
44
- @workflow_inst = http_client.post(
75
+ wi = http_client.post(
45
76
  "workflow/stop",
46
- options
77
+ { 'id' => wi_id }
47
78
  ).body
48
- workflow_instance
49
- rescue Matterhorn::HttpClientError => ex
50
- Rails.logger.warn { "Matterhorn::Workflow::stop | WorkflowInstance[wi_id] could not be stopped!\n" +
51
- "#{ex.class.name}: #{ex.to_s} / backtrace:\n#{ex.backtrace.join("\n")}" }
52
- return nil
53
- rescue => ex
54
- raise ex
55
- end
56
- end
79
+ rescue Matterhorn::HttpClientError, Matterhorn::HttpServerError => ex
80
+ if ex.code == 404
81
+ wi = nil
82
+ MatterhornWhymper.logger.warn { "#{self.class.name}::stop | " +
83
+ "WorkflowInstance[#{wi_id}]: No running workflow instance with that identifier exists." }
84
+ else
85
+ MatterhornWhymper.logger.error { "#{self.class.name}::stop | " +
86
+ "WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
57
87
 
58
-
59
- def workflow_instance
60
- if !@workflow_inst.nil?
61
- Matterhorn::WorkflowInstance.new(@workflow_inst)
62
- else
63
- nil
88
+ raise ex
89
+ end
64
90
  end
91
+ wi ? Matterhorn::WorkflowInstance.new(wi) : nil
65
92
  end
93
+
66
94
 
67
- end
95
+ end # ------------------------------------------------------- end Matterhorn::Endpoint::Workflow ---
@@ -1,25 +1,37 @@
1
+ # =================================================================================== Matterhorn ===
2
+
1
3
  module Matterhorn
2
4
 
5
+
6
+ # ======================================================================= Matterhorn::Endpoint ===
7
+
3
8
  class Endpoint
4
9
 
5
- # --- attributes -------------------------------------------------------------
10
+ # ------------------------------------------------------------------------------- attributes ---
6
11
 
7
12
  attr_reader :http_client
8
13
 
9
14
 
10
- # --- initialization ---------------------------------------------------------
15
+ # --------------------------------------------------------------------------- initialization ---
11
16
 
12
17
  def self.open(endpoint)
13
18
  if endpoint.respond_to? 'to_s'
14
19
  endpoint = endpoint.to_s.capitalize
15
20
  else
16
- #TODO: error handling
21
+ raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
22
+ "#{endpoint.inspect} does not respond to 'to_s'")
17
23
  end
18
24
  endpoint = Object.const_get('Matterhorn').const_get('Endpoint').const_get(endpoint).new
19
-
20
- yield endpoint
21
-
22
- endpoint.close
25
+ if endpoint.nil? || !endpoint.kind_of?(Matterhorn::Endpoint)
26
+ raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
27
+ "#{endpoint ? endpoint.class.name : 'nil'} is not a sub class " +
28
+ "of 'Matterhorn::Endpoint'!")
29
+ end
30
+ begin
31
+ yield endpoint
32
+ ensure
33
+ endpoint.close
34
+ end
23
35
  end
24
36
 
25
37
 
@@ -30,11 +42,14 @@ module Matterhorn
30
42
  end
31
43
 
32
44
 
45
+ # --------------------------------------------------------------------------------- methodes ---
46
+
33
47
  def close
34
48
  http_client.close
35
49
  end
36
50
 
37
51
 
38
- end
52
+ end # --------------------------------------------------------------- end Matterhorn::Endpoint ---
53
+
39
54
 
40
- end
55
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,15 +1,34 @@
1
+ # =================================================================================== Matterhorn ===
2
+
1
3
  module Matterhorn
2
4
 
3
- # --- Matterhorn Exceptions ------------------------------------------------------------------------
4
5
 
5
- class Matterhorn::Error < StandardError
6
+ # ====================================================================== several error classes ===
7
+
8
+ class Error < StandardError
6
9
  end
7
10
 
8
- class Matterhorn::HttpClientError < Matterhorn::Error
11
+
12
+ class HttpGeneralError < Matterhorn::Error
13
+
14
+ attr_reader :code, :request, :response
15
+
16
+ def initialize(message, request, response)
17
+ @request = request
18
+ @response = response
19
+ @code = response.code.to_i
20
+ super(message)
21
+ end
22
+
9
23
  end
24
+
25
+
26
+ class HttpClientError < Matterhorn::HttpGeneralError
27
+ end
28
+
10
29
 
11
- class Matterhorn::HttpServerError < Matterhorn::Error
30
+ class HttpServerError < Matterhorn::HttpGeneralError
12
31
  end
13
32
 
14
33
 
15
- end
34
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,15 +1,22 @@
1
1
  require 'net/http/post/multipart'
2
2
  require 'net/http/digest_auth'
3
3
 
4
+
5
+ # =================================================================================== Matterhorn ===
6
+
4
7
  module Matterhorn
5
8
 
9
+
10
+ # ===================================================================== Matterhorn::HttpClient ===
11
+
6
12
  class HttpClient
7
13
 
8
- # --- attributes -------------------------------------------------------------
14
+ # ------------------------------------------------------------------------------- attributes ---
9
15
 
10
16
  attr_reader :base_uri, :host, :port, :ssl
11
17
 
12
- # --- initialization ---------------------------------------------------------
18
+
19
+ # --------------------------------------------------------------------------- initialization ---
13
20
 
14
21
  def initialize(base_uri)
15
22
  @base_uri = URI.parse(base_uri)
@@ -18,11 +25,14 @@ module Matterhorn
18
25
  @ssl = @port == 443 ? true : false
19
26
  end
20
27
 
21
- def close
22
- @http_socket.finish if !@http_socket.nil? && @http_socket.started?
28
+
29
+ # ---------------------------------------------------------------------------- http methodes ---
30
+
31
+ def get(url)
32
+ request = Net::HTTP::Get.new(base_uri.request_uri + url)
33
+ execute_request(request)
23
34
  end
24
35
 
25
- # --- http methodes ----------------------------------------------------------
26
36
 
27
37
  def post(url, params = {}, file = nil, filename = nil, mime_type = nil)
28
38
  if params.has_key?('BODY') || !file.nil?
@@ -34,21 +44,18 @@ module Matterhorn
34
44
  end
35
45
 
36
46
 
37
- def get(url)
38
- request = Net::HTTP::Get.new(base_uri.request_uri + url)
39
- execute_request(request)
40
- end
41
-
42
-
43
47
  def delete(url)
44
48
  request = Net::HTTP::Delete.new(base_uri.request_uri + url)
45
49
  execute_request(request)
46
50
  end
47
51
 
48
52
 
49
- # ========================================================================== #
50
- # === private section === #
51
- # ========================================================================== #
53
+ def close
54
+ @http_socket.finish if !@http_socket.nil? && @http_socket.started?
55
+ end
56
+
57
+
58
+ # -------------------------------------------------------------------------- private section ---
52
59
  private
53
60
 
54
61
  def http_socket
@@ -62,7 +69,6 @@ module Matterhorn
62
69
  def singlepart_post(url, params)
63
70
  request = Net::HTTP::Post.new(base_uri.request_uri + url)
64
71
  request.set_form_data(params)
65
- MatterhornWhymper.logger.debug { "Matterhorn::Client::singlepart_post: request = #{request.to_yaml}"}
66
72
  request
67
73
  end
68
74
 
@@ -79,9 +85,9 @@ module Matterhorn
79
85
  file = params['BODY']
80
86
  params['BODY'] = nil
81
87
  else
82
- raise(Matterhorn::Error, "Matterhorn::Client::multipart_post: Neither BODY nor file exists!")
88
+ raise(Matterhorn::Error, "Matterhorn::HttpClient::multipart_post | " +
89
+ "Neither a BODY nor a file is present!")
83
90
  end
84
- MatterhornWhymper.logger.debug { "Matterhorn::Client::multipart_post: file = #{file.inspect}"}
85
91
  if filename.nil?
86
92
  filename = File.basename(file.path)
87
93
  end
@@ -89,7 +95,6 @@ module Matterhorn
89
95
  mime_type = MIME::Types.type_for(File.basename(file.path)).first
90
96
  end
91
97
  params['BODY'] = UploadIO.new(file, mime_type, filename)
92
- MatterhornWhymper.logger.debug { "Matterhorn::Client::multipart_post: params = #{params.to_yaml}"}
93
98
  Net::HTTP::Post::Multipart.new(base_uri.request_uri + url, params)
94
99
  end
95
100
 
@@ -111,46 +116,44 @@ module Matterhorn
111
116
  when 500..599
112
117
  handle_5xx_error(request, response)
113
118
  else
114
- handle_unknown_error(request, response)
119
+ handle_general_error(request, response)
115
120
  end
116
121
  response
117
122
  end
118
123
 
119
124
 
120
125
  def handle_2xx_ok(request, response)
121
- MatterhornWhymper.logger.info { "Matterhorn::Client::execute_request:\n" + log_message(request, response) }
126
+ msg = log_message('handle_2xx_ok', request, response)
127
+ MatterhornWhymper.logger.debug { msg }
122
128
  end
123
129
 
124
130
  def handle_4xx_error(request, response)
125
- MatterhornWhymper.logger.error { "Matterhorn::Client::execute_request: Client Error:\n" + log_message(request, response) }
126
- raise(Matterhorn::HttpClientError, log_message(request, response))
131
+ msg = log_message('handle_4xx_error', request, response)
132
+ MatterhornWhymper.logger.debug { msg }
133
+ raise(Matterhorn::HttpClientError, msg, request, response)
127
134
  end
128
135
 
129
136
  def handle_5xx_error(request, response)
130
- MatterhornWhymper.logger.error { "Matterhorn::Client::execute_request: Server Error:\n" + log_message(request, response) }
131
- raise(Matterhorn::HttpServerError, log_message(request, response))
137
+ msg = log_message('handle_5xx_error', request, response)
138
+ MatterhornWhymper.logger.debug { msg }
139
+ raise(Matterhorn::HttpServerError, msg, request, response)
132
140
  end
133
141
 
134
- def handle_unknown_error(request, response)
135
- MatterhornWhymper.logger.error { "Matterhorn::Client::execute_request: Server Error:\n" + log_message(request, response) }
136
- raise(Matterhorn::Error, log_message(request, response))
142
+ def handle_general_error(request, response)
143
+ msg = log_message('handle_general_error', request, response)
144
+ MatterhornWhymper.logger.debug { msg }
145
+ raise(Matterhorn::HttpGeneralError, msg, request, response)
137
146
  end
138
147
 
139
148
 
140
- def log_message(request, response)
141
- " request = #{log_request(request)}\n" +
142
- " response = #{log_response(response)}"
149
+ def log_message(method, request, response)
150
+ "#{self.class.name}::#{method} | code = #{response.code}\n" +
151
+ " request = #{request.method} #{request.path}\n" +
152
+ " response = #{response.code} #{response.msg}, body:\n#{response.body}\n"
143
153
  end
144
154
 
145
- def log_request(request)
146
- "#{request.method} #{request.path}"
147
- end
148
-
149
- def log_response(response)
150
- "#{response.code} #{response.msg}, body:\n#{response.body}\n"
151
- end
152
155
 
156
+ end # ------------------------------------------------------------- end Matterhorn::HttpClient ---
153
157
 
154
- end
155
158
 
156
- end
159
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,34 +1,40 @@
1
1
  require 'nokogiri'
2
2
 
3
+
4
+ # =================================================================================== Matterhorn ===
5
+
3
6
  module Matterhorn
4
7
 
8
+
9
+ # =================================================================== Matterhorn::MediaPackage ===
10
+
5
11
  class MediaPackage
6
12
 
7
- # --- const definitions ------------------------------------------------------
13
+ # ------------------------------------------------------------------------ const definitions ---
14
+
8
15
  XML_NS_MEDIAPACKAGE = "http://mediapackage.opencastproject.org"
9
16
 
10
17
 
11
- # --- initialization ---------------------------------------------------------
18
+ # --------------------------------------------------------------------------- initialization ---
12
19
 
13
20
  def initialize(path, xml = nil)
14
- @path = path + (path[-1] == '/' ? '' : '/') # guarantee that path ends with a slash
21
+ @path = path + (path[-1] == '/' ? '' : '/') # guarantee that path ends with a slash
15
22
  if !xml.nil?
16
23
  @document = Nokogiri::XML(xml)
17
24
  else
18
25
  @document = Nokogiri::XML::Builder.new do |xml|
19
- xml.mediapackage('xmlns' => XML_NS_MEDIAPACKAGE) {
26
+ xml.mediapackage('xmlns' => XML_NS_MEDIAPACKAGE) do
20
27
  xml.media
21
28
  xml.metadata
22
29
  xml.attachments
23
- }
30
+ end
24
31
  end
25
32
  .doc
26
33
  end
27
- MatterhornWhymper.logger.debug { "Matterhorn::MediaPackage::initialize | doc = #{to_xml}" }
28
34
  end
29
35
 
30
36
 
31
- # --- methodes ---------------------------------------------------------------
37
+ # --------------------------------------------------------------------------------- methodes ---
32
38
 
33
39
  # <attachments>
34
40
  # <attachment type="switchcastrecorder/metadata">
@@ -36,6 +42,7 @@ module Matterhorn
36
42
  # <url>metadata.plist</url>
37
43
  # </attachment>
38
44
  # </attachments>
45
+ #
39
46
  def add_attachment(file, flavor)
40
47
  Nokogiri::XML::Builder.with(@document.at('attachments')) do |xml|
41
48
  xml.attachment(:type => flavor) {
@@ -53,6 +60,7 @@ module Matterhorn
53
60
  # <url>dublincore.xml</url>
54
61
  # </catalog>
55
62
  # </metadata>
63
+ #
56
64
  def add_catalog(file, flavor, mimetype = 'text/xml')
57
65
  Nokogiri::XML::Builder.with(@document.at('metadata')) do |xml|
58
66
  xml.catalog(:type => flavor) {
@@ -82,6 +90,7 @@ module Matterhorn
82
90
  # <url>source1/mux_2013_12-17T14_51_29_738.mov</url>
83
91
  # </track>
84
92
  # </media>
93
+ #
85
94
  def add_track(file, flavor)
86
95
  Nokogiri::XML::Builder.with(@document.at('media')) do |xml|
87
96
  xml.track(:type => flavor) {
@@ -105,6 +114,7 @@ module Matterhorn
105
114
  end
106
115
 
107
116
 
108
- end
117
+ end # ----------------------------------------------------------- end Matterhorn::MediaPackage ---
118
+
109
119
 
110
- end
120
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,29 +1,30 @@
1
+ require 'nokogiri'
2
+
3
+
4
+ # =================================================================================== Matterhorn ===
5
+
1
6
  module Matterhorn
2
7
 
3
- class Smil
4
-
5
- # --- const definitions ------------------------------------------------------
6
8
 
7
- # --- attributes -------------------------------------------------------------
9
+ # =========================================================================== Matterhorn::Smil ===
10
+
11
+ class Smil
12
+
13
+
14
+ # ------------------------------------------------------------------------------- attributes ---
15
+
8
16
  attr_reader :head, :body
9
17
 
10
- # --- validations ------------------------------------------------------------
11
-
12
-
13
- # --- callback declarations --------------------------------------------------
14
-
15
-
16
- # --- relations --------------------------------------------------------------
17
18
 
18
-
19
- # --- initialization ---------------------------------------------------------
19
+ # --------------------------------------------------------------------------- initialization ---
20
20
 
21
21
  def initialize()
22
22
  @head = Smil::Head.new
23
23
  @body = Smil::Body.new
24
24
  end
25
25
 
26
- # --- methodes ---------------------------------------------------------------
26
+
27
+ # --------------------------------------------------------------------------------- methodes ---
27
28
 
28
29
  def save(smil_file)
29
30
  File.open(smil_file, 'w') do |file|
@@ -35,52 +36,52 @@ module Matterhorn
35
36
 
36
37
 
37
38
  def to_xml
38
- StringIO.open('', 'w') do |strio|
39
- bx = Builder::XmlMarkup.new(:target=>strio, :indent=>2)
40
- bx.instruct! :xml, :version=>'1.1', :encoding => 'UTF-8'
41
- bx.smil(:xmlns => "http://www.w3.org/ns/SMIL") do
42
- head.to_xml(bx)
43
- body.to_xml(bx)
44
- end
45
- strio.string
39
+ doc = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |bx|
40
+ bx.smil('xmlns' => "http://www.w3.org/ns/SMIL") do
41
+ head.to_xml(bx)
42
+ body.to_xml(bx)
46
43
  end
44
+ doc.to_xml
47
45
  end
48
46
 
49
-
50
- # ========================================================================== #
51
- # === protected section === #
52
- # ========================================================================== #
53
- protected
54
-
55
-
56
- # ========================================================================== #
57
- # === private section === #
58
- # ========================================================================== #
59
- private
60
-
61
- end
47
+
48
+ end # ------------------------------------------------------------------- end Matterhorn::Smil ---
62
49
 
63
50
 
64
51
 
52
+ # ===================================================================== Matterhorn::Smil::Head ===
53
+
65
54
  class Smil::Head
66
55
 
67
- def to_xml(builder)
68
- builder.head do
56
+ def to_xml(bx)
57
+ bx.head do
69
58
  end
70
59
  end
71
60
 
72
- end
61
+
62
+ end # ------------------------------------------------------------- end Matterhorn::Smil::Head ---
63
+
73
64
 
74
65
 
66
+ # ===================================================================== Matterhorn::Smil::Body ===
75
67
 
76
68
  class Smil::Body
77
69
 
70
+
71
+ # ------------------------------------------------------------------------------- attributes ---
72
+
78
73
  attr_reader :par_list
79
74
 
75
+
76
+ # --------------------------------------------------------------------------- initialization ---
77
+
80
78
  def initialize()
81
79
  @par_list = Array.new
82
80
  end
83
81
 
82
+
83
+ # --------------------------------------------------------------------------------- methodes ---
84
+
84
85
  def add_par()
85
86
  par = Smil::Par.new
86
87
  @par_list << par
@@ -96,16 +97,23 @@ module Matterhorn
96
97
  end
97
98
  end
98
99
 
99
- end
100
+
101
+ end # ------------------------------------------------------------- end Matterhorn::Smil::Body ---
100
102
 
101
103
 
102
104
 
105
+ # ================================================================== Matterhorn::Smil::Element ===
106
+
103
107
  class Smil::Element
104
108
 
105
- # --- attributes -------------------------------------------------------------
109
+
110
+ # ------------------------------------------------------------------------------- attributes ---
111
+
106
112
  attr_reader :start_point, :end_point, :rel_begin, :duration, :parent
107
113
 
108
- # --- initialization ---------------------------------------------------------
114
+
115
+ # --------------------------------------------------------------------------- initialization ---
116
+
109
117
  def initialize(parent = nil)
110
118
  @start_point = nil
111
119
  @end_point = nil
@@ -114,7 +122,8 @@ module Matterhorn
114
122
  @parent = parent
115
123
  end
116
124
 
117
- # --- methodes ---------------------------------------------------------------
125
+
126
+ # --------------------------------------------------------------------------------- methodes ---
118
127
 
119
128
  def attr_list
120
129
  attr_list = Hash.new
@@ -127,10 +136,8 @@ module Matterhorn
127
136
  attr_list
128
137
  end
129
138
 
130
-
131
- # ========================================================================== #
132
- # === protected section === #
133
- # ========================================================================== #
139
+
140
+ # ------------------------------------------------------------------------ protected section ---
134
141
  protected
135
142
 
136
143
  def start_point=(new_start_point)
@@ -145,6 +152,7 @@ module Matterhorn
145
152
  @start_point = new_start_point
146
153
  end
147
154
 
155
+
148
156
  def end_point=(new_end_point)
149
157
  if new_end_point.kind_of? String
150
158
  # end_point is an absolut time position and must be in the format 2013-12-02T14:12:42.364
@@ -157,6 +165,7 @@ module Matterhorn
157
165
  @end_point = new_end_point
158
166
  end
159
167
 
168
+
160
169
  def rel_begin=(new_rel_begin)
161
170
  if new_rel_begin.kind_of? Fixnum
162
171
  new_rel_begin = new_rel_begin / 1000.0
@@ -168,6 +177,7 @@ module Matterhorn
168
177
  @rel_begin = new_rel_begin
169
178
  end
170
179
 
180
+
171
181
  def duration=(new_duration)
172
182
  if new_duration.kind_of? Fixnum
173
183
  # duration is in ms
@@ -182,6 +192,7 @@ module Matterhorn
182
192
  @duration = new_duration
183
193
  end
184
194
 
195
+
185
196
  def update(sub_elem)
186
197
  if !sub_elem.start_point.nil? && (start_point.nil? || start_point > sub_elem.start_point)
187
198
  @start_point = sub_elem.start_point
@@ -203,21 +214,30 @@ module Matterhorn
203
214
  propagate(self) if parent.nil?
204
215
  end
205
216
 
217
+
206
218
  def propagate(parent_elem)
207
219
  end
208
220
 
209
- end
221
+
222
+ end # ---------------------------------------------------------- end Matterhorn::Smil::Element ---
210
223
 
211
224
 
212
225
 
226
+ # ====================================================================== Matterhorn::Smil::Par ===
227
+
213
228
  class Smil::Par < Smil::Element
214
229
 
230
+
231
+ # --------------------------------------------------------------------------- initialization ---
232
+
215
233
  def initialize()
216
234
  super
217
235
  @seq_list = Array.new
218
236
  end
219
237
 
220
238
 
239
+ # --------------------------------------------------------------------------------- methodes ---
240
+
221
241
  def add_seq
222
242
  seq = Smil::Seq.new(self)
223
243
  @seq_list << seq
@@ -240,23 +260,33 @@ module Matterhorn
240
260
  end
241
261
  end
242
262
 
243
- end
263
+
264
+ end # -------------------------------------------------------------- end Matterhorn::Smil::Par ---
265
+
244
266
 
245
267
 
268
+ # ====================================================================== Matterhorn::Smil::Seq ===
246
269
 
247
270
  class Smil::Seq < Smil::Element
248
271
 
272
+
273
+ # --------------------------------------------------------------------------- initialization ---
274
+
249
275
  def initialize(parent)
250
276
  super(parent)
251
277
  @track_list = Array.new
252
278
  end
253
279
 
280
+
281
+ # --------------------------------------------------------------------------------- methodes ---
282
+
254
283
  def attr_list
255
284
  attrib_list = super
256
285
  attrib_list.delete(:begin)
257
286
  attrib_list
258
287
  end
259
288
 
289
+
260
290
  def add_track(kind, file, start_point, duration)
261
291
  track = Smil::Track.new(self, kind, file, start_point, duration)
262
292
  @track_list << track
@@ -264,6 +294,7 @@ module Matterhorn
264
294
  track
265
295
  end
266
296
 
297
+
267
298
  def propagate(parent_elem)
268
299
  @rel_begin = start_point - parent_elem.start_point
269
300
  @track_list.each do |track|
@@ -272,6 +303,7 @@ module Matterhorn
272
303
  end
273
304
  end
274
305
 
306
+
275
307
  def to_xml(bx)
276
308
  bx.seq(attr_list) do
277
309
  @track_list.each do |track|
@@ -280,11 +312,18 @@ module Matterhorn
280
312
  end
281
313
  end
282
314
 
283
- end
315
+
316
+ end # -------------------------------------------------------------- end Matterhorn::Smil::Seq ---
284
317
 
285
318
 
319
+
320
+ # ====================================================================================== Track ===
321
+
286
322
  class Smil::Track < Smil::Element
287
323
 
324
+
325
+ # --------------------------------------------------------------------------- initialization ---
326
+
288
327
  def initialize(parent, kind, file, start_point, duration)
289
328
  super(parent)
290
329
  @kind = kind
@@ -293,18 +332,24 @@ module Matterhorn
293
332
  self.duration = duration
294
333
  end
295
334
 
335
+
336
+ # --------------------------------------------------------------------------------- methodes ---
337
+
296
338
  def propagate(parent_elem)
297
339
  @rel_begin = start_point - parent_elem.start_point
298
340
  end
299
341
 
342
+
300
343
  def to_xml(bx)
301
344
  attributes = attr_list
302
345
  if !@src.nil?
303
346
  attributes[:src] = @src.to_s
304
347
  end
305
- bx.tag!(@kind, attributes)
348
+ bx.tag_(@kind, attributes)
306
349
  end
307
350
 
308
- end
309
351
 
310
- end
352
+ end # ------------------------------------------------------------ end Matterhorn::Smil::Track ---
353
+
354
+
355
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,59 +1,51 @@
1
1
  require 'nokogiri'
2
2
 
3
+
4
+ # =================================================================================== Matterhorn ===
5
+
3
6
  module Matterhorn
4
7
 
8
+
9
+ # =============================================================== Matterhorn::WorkflowInstance ===
10
+
5
11
  class WorkflowInstance
6
12
 
13
+
14
+ # ------------------------------------------------------------------------ const definitions ---
15
+
7
16
  XML_NS_WORKFLOW = "http://workflow.opencastproject.org"
17
+
8
18
 
9
- # --- const definitions ------------------------------------------------------
10
-
11
- # --- attributes -------------------------------------------------------------
12
-
13
- # --- validations ------------------------------------------------------------
14
-
15
- # --- callback declarations --------------------------------------------------
16
-
17
-
18
- # --- relations --------------------------------------------------------------
19
-
20
-
21
- # --- initialization ---------------------------------------------------------
19
+ # --------------------------------------------------------------------------- initialization ---
22
20
 
23
21
  def initialize(xml)
24
22
  @document = Nokogiri::XML(xml)
25
23
  end
24
+
26
25
 
27
- # --- methodes ---------------------------------------------------------------
26
+ # --------------------------------------------------------------------------------- methodes ---
28
27
 
29
28
  def id
30
29
  @document.xpath('/nsw:workflow/@id', {"nsw" => XML_NS_WORKFLOW}).first.value
31
30
  end
32
31
 
32
+
33
33
  def state
34
34
  @document.xpath('/nsw:workflow/@state', {"nsw" => XML_NS_WORKFLOW}).first.value
35
35
  end
36
36
 
37
+
37
38
  def template
38
39
  @document.xpath('/nsw:workflow/nsw:template', {"nsw" => XML_NS_WORKFLOW}).first.content
39
40
  end
40
41
 
42
+
41
43
  def to_xml
42
44
  @document.to_xml
43
45
  end
44
46
 
45
47
 
46
- # ========================================================================== #
47
- # === protected section === #
48
- # ========================================================================== #
49
- protected
50
-
51
-
52
- # ========================================================================== #
53
- # === private section === #
54
- # ========================================================================== #
55
- private
56
-
57
- end
48
+ end # ------------------------------------------------------- end Matterhorn::WorkflowInstance ---
49
+
58
50
 
59
- end
51
+ end # --------------------------------------------------------------------------- end Matterhorn ---
@@ -1,3 +1,11 @@
1
+ # ============================================================================ MatterhornWhymper ===
2
+
1
3
  module MatterhornWhymper
2
- VERSION = "0.0.2"
3
- end
4
+
5
+
6
+ # -------------------------------------------------------------------------- const definitions ---
7
+
8
+ VERSION = "0.0.3"
9
+
10
+
11
+ end # -------------------------------------------------------------------- end MatterhornWhymper ---
@@ -7,17 +7,24 @@ require 'matterhorn/media_package'
7
7
  require 'matterhorn/error'
8
8
 
9
9
 
10
+ # ============================================================================ MatterhornWhymper ===
11
+
10
12
  module MatterhornWhymper
11
13
 
12
- def self.info
13
- "Ruby wrapper against the Matterhorn Endpoint API. Version #{MatterhornWhymper::VERSION}"
14
- end
15
-
16
-
14
+
15
+ # --------------------------------------------------------------------------------- attributes ---
16
+
17
17
  class << self
18
18
  attr_accessor :configuration, :logger
19
19
  end
20
20
 
21
+
22
+ # ----------------------------------------------------------------------------------- methodes ---
23
+
24
+ def self.info
25
+ "Ruby wrapper against the Matterhorn Endpoint API. Version #{MatterhornWhymper::VERSION}"
26
+ end
27
+
21
28
 
22
29
  def self.configure
23
30
  self.configuration ||= Configuration.new
@@ -32,16 +39,23 @@ module MatterhornWhymper
32
39
 
33
40
 
34
41
 
42
+ # =========================================================== MatterhornWhymper::Configuration ===
43
+
35
44
  class Configuration
36
45
 
46
+ # ------------------------------------------------------------------------------- attributes ---
47
+
37
48
  attr_accessor :system_account_user, :system_account_password, :system_domain, :system_protocol
38
49
 
50
+
51
+ # --------------------------------------------------------------------------------- methodes ---
52
+
39
53
  def uri
40
54
  "#{system_protocol}://#{system_account_user}:#{system_account_password}@#{system_domain}"
41
55
  end
42
56
 
43
57
 
44
- end
58
+ end # --------------------------------------------------- end MatterhornWhymper::Configuration ---
45
59
 
46
60
 
47
- end
61
+ end # -------------------------------------------------------------------- end MatterhornWhymper ---
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matterhorn_whymper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Fritschi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post