matterhorn_whymper 0.6.1 → 1.0.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 +8 -8
- data/lib/matterhorn/dublin_core.rb +12 -0
- data/lib/matterhorn/endpoint/event.rb +68 -4
- data/lib/matterhorn/endpoint/ingest.rb +7 -7
- data/lib/matterhorn/endpoint/series.rb +7 -7
- data/lib/matterhorn/endpoint/workflow.rb +4 -4
- data/lib/matterhorn/endpoint.rb +40 -12
- data/lib/matterhorn/http_client.rb +49 -28
- data/lib/matterhorn/media_package.rb +22 -0
- data/lib/matterhorn_whymper/version.rb +1 -1
- data/lib/matterhorn_whymper.rb +52 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Zjk0MThiN2Q1MzMyZjExNGMzZWM1ZjIxZGI1ZDY3NTEwMGRmNTk0MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDVhNjlhNWQwYWZjMGI1MzdlZDUxYjcxMWY0ZWM3OGU1Mzg2ZDkwZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjM3ZmQ5OTEwODQ1ZDI4Yjg5NGMyYzc0NzM0ZDFlNjk0MmMwYjA3MmI1YzNk
|
10
|
+
NzM1NTIxNmU4NjU4MmY4YTBiZGVhMWRmYjdjMzM5YTMwZDI5MWFhZTk1ODMz
|
11
|
+
Y2ExNjlmNGUzODhkMzNkYTA5OTBiYWFjOTcwMDE2MTMxYzE2Yzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTcxMzY1NjcyYzMwYzAyMTU5MzRiNWYzYjE4YjZhYjJlMjI0MDgwMDM1NGU0
|
14
|
+
MjI1M2E1YmIwZDVmNjA0YmY0NGQxYjdiMTM5ZjllYWNkN2E1NDkxNTJiNTQ4
|
15
|
+
YjVjZjhhOGRlNzcyNzA4MzMxZGEzNTI3YTk5NTkxNGRkNTFkZTg=
|
@@ -72,6 +72,11 @@ class Matterhorn::DublinCore
|
|
72
72
|
end
|
73
73
|
|
74
74
|
|
75
|
+
def each_dcterms_element(&block)
|
76
|
+
each_element('dcterms', &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
75
80
|
def save(file)
|
76
81
|
File.open(file, 'w') do |file|
|
77
82
|
file.write(@document.to_xml)
|
@@ -166,6 +171,13 @@ class Matterhorn::DublinCore
|
|
166
171
|
end
|
167
172
|
elem.content
|
168
173
|
end
|
174
|
+
|
169
175
|
|
176
|
+
def each_element(ns, &block)
|
177
|
+
@document.xpath("/xmlns:dublincore/#{ns}:*").each do |elem|
|
178
|
+
yield elem.name, elem.content
|
179
|
+
end
|
180
|
+
end
|
170
181
|
|
182
|
+
|
171
183
|
end # --------------------------------------------------------------- end Matterhorn::DublinCore ---
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
# ================================================================== Matterhorn::Endpoint::Event ===
|
2
4
|
|
3
5
|
# This endpoint is not a pure wrapper of the admin endpoint.
|
@@ -15,27 +17,89 @@ class Matterhorn::Endpoint::Event < Matterhorn::Endpoint
|
|
15
17
|
# --------------------------------------------------------------------------------------- read ---
|
16
18
|
|
17
19
|
def read_media_package(media_package_id)
|
18
|
-
|
20
|
+
media_package = nil
|
19
21
|
begin
|
20
|
-
split_response
|
22
|
+
split_response http_endpoint_client.get(
|
21
23
|
"archive/archive/mediapackage/#{media_package_id}"
|
22
24
|
)
|
23
|
-
|
25
|
+
media_package = Matterhorn::MediaPackage.new(response_body)
|
24
26
|
rescue => ex
|
25
27
|
exception_handler('read_media_package', ex, {
|
26
28
|
404 => "The media package of event[#{media_package_id}] could not be found."
|
27
29
|
}
|
28
30
|
)
|
29
31
|
end
|
30
|
-
|
32
|
+
media_package
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def read_dublin_core(media_package_id)
|
37
|
+
dublin_core = nil
|
38
|
+
begin
|
39
|
+
mp = read_media_package(media_package_id)
|
40
|
+
if !mp.nil?
|
41
|
+
dc_uri = URI.parse(mp.dc_catalog_url)
|
42
|
+
split_response http_endpoint_client.get(dc_uri.request_uri)
|
43
|
+
dublin_core = Matterhorn::DublinCore.new(response_body)
|
44
|
+
end
|
45
|
+
rescue => ex
|
46
|
+
exception_handler('read_dublin_core', ex, {
|
47
|
+
404 => "The media package of event[#{media_package_id}] could not be found."
|
48
|
+
}
|
49
|
+
)
|
50
|
+
end
|
51
|
+
dublin_core
|
31
52
|
end
|
32
53
|
|
33
54
|
|
34
55
|
# ------------------------------------------------------------------------------------- update ---
|
35
56
|
|
57
|
+
def changeable_element?(element_name)
|
58
|
+
['title', 'subject', 'description', 'language', 'license',
|
59
|
+
'contributer', 'source'].include?(element_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def update_dublin_core(media_package_id, dublin_core)
|
64
|
+
updated = false
|
65
|
+
begin
|
66
|
+
dc_field_arr = []
|
67
|
+
dublin_core.each_dcterms_element do |name, content|
|
68
|
+
if changeable_element?(name) && !content.blank?
|
69
|
+
dc_field_arr << {
|
70
|
+
'id' => name,
|
71
|
+
'value' => content
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
split_response http_api_client.put(
|
76
|
+
"api/events/#{media_package_id}/metadata?type=dublincore/episode",
|
77
|
+
{ 'metadata' => dc_field_arr.to_json }
|
78
|
+
)
|
79
|
+
updated = true
|
80
|
+
rescue => ex
|
81
|
+
exception_handler('update_dublin_core', ex, {
|
82
|
+
400 => "The request is invaldi or inconsistent.",
|
83
|
+
404 => "The media package of event[#{media_package_id}] could not be found."
|
84
|
+
}
|
85
|
+
)
|
86
|
+
end
|
87
|
+
updated
|
88
|
+
end
|
89
|
+
|
36
90
|
|
37
91
|
# ------------------------------------------------------------------------------------- delete ---
|
38
92
|
|
93
|
+
def delete(media_package_id)
|
94
|
+
begin
|
95
|
+
split_response http_endpoint_client.delete(
|
96
|
+
"archive/delete/#{media_package_id}"
|
97
|
+
)
|
98
|
+
rescue => ex
|
99
|
+
exception_handler('delete', ex, {})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
39
103
|
|
40
104
|
# ---------------------------------------------------------------------------- private section ---
|
41
105
|
private
|
@@ -9,7 +9,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
9
9
|
unless @media_pkg_xml_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
10
10
|
@media_pkg_local.add_attachment(file, flavor) if @media_pkg_local
|
11
11
|
begin
|
12
|
-
spit_response
|
12
|
+
spit_response http_endpoint_client.post(
|
13
13
|
"ingest/addAttachment",
|
14
14
|
{ 'flavor' => flavor,
|
15
15
|
'mediaPackage' => @media_pkg_xml_remote,
|
@@ -32,7 +32,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
32
32
|
unless @media_pkg_xml_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
33
33
|
@media_pkg_local.add_catalog(file, flavor) if @media_pkg_local
|
34
34
|
begin
|
35
|
-
split_response
|
35
|
+
split_response http_endpoint_client.post(
|
36
36
|
"ingest/addCatalog",
|
37
37
|
{ 'flavor' => flavor,
|
38
38
|
'mediaPackage' => @media_pkg_xml_remote,
|
@@ -55,7 +55,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
55
55
|
unless @media_pkg_xml_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
56
56
|
@media_pkg_local.add_dc_catalog(dublin_core) if @media_pkg_local
|
57
57
|
begin
|
58
|
-
split_response
|
58
|
+
split_response http_endpoint_client.post(
|
59
59
|
"ingest/addDCCatalog",
|
60
60
|
{ 'flavor' => 'dublincore/episode',
|
61
61
|
'mediaPackage' => @media_pkg_xml_remote,
|
@@ -80,7 +80,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
80
80
|
@media_pkg_local.add_track(file_or_url, flavor) if @media_pkg_local
|
81
81
|
begin
|
82
82
|
if HTTP_PROTOCOL_RE =~ file_or_url
|
83
|
-
split_response
|
83
|
+
split_response http_endpoint_client.post(
|
84
84
|
"ingest/addTrack",
|
85
85
|
{ 'flavor' => flavor,
|
86
86
|
'mediaPackage' => @media_pkg_xml_remote,
|
@@ -88,7 +88,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
88
88
|
}
|
89
89
|
)
|
90
90
|
else
|
91
|
-
split_response
|
91
|
+
split_response http_endpoint_client.post(
|
92
92
|
"ingest/addTrack",
|
93
93
|
{ 'flavor' => flavor,
|
94
94
|
'mediaPackage' => @media_pkg_xml_remote,
|
@@ -120,7 +120,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
120
120
|
nil
|
121
121
|
end
|
122
122
|
begin
|
123
|
-
split_response
|
123
|
+
split_response http_endpoint_client.get(
|
124
124
|
"ingest/createMediaPackage"
|
125
125
|
)
|
126
126
|
@media_pkg_xml_remote = response_body
|
@@ -137,7 +137,7 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
137
137
|
@media_pkg_local.save if @media_pkg_local
|
138
138
|
options['mediaPackage'] = @media_pkg_xml_remote
|
139
139
|
begin
|
140
|
-
split_response
|
140
|
+
split_response http_endpoint_client.post(
|
141
141
|
"ingest/ingest/#{wdID}",
|
142
142
|
options
|
143
143
|
)
|
@@ -17,7 +17,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
17
17
|
def create(dublin_core, acl = nil)
|
18
18
|
dc = nil
|
19
19
|
begin
|
20
|
-
split_response
|
20
|
+
split_response http_endpoint_client.post(
|
21
21
|
"series",
|
22
22
|
{ 'series' => dublin_core.to_xml, 'acl' => acl ? acl.to_xml : '' }
|
23
23
|
)
|
@@ -39,7 +39,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
39
39
|
def read(series_id)
|
40
40
|
dc_model = nil
|
41
41
|
begin
|
42
|
-
split_response
|
42
|
+
split_response http_endpoint_client.get(
|
43
43
|
"series/#{series_id}.xml"
|
44
44
|
)
|
45
45
|
dc_model = Matterhorn::DublinCore.new(response_body)
|
@@ -59,7 +59,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
59
59
|
def read_acl(series_id)
|
60
60
|
acl_model = nil
|
61
61
|
begin
|
62
|
-
split_response
|
62
|
+
split_response http_endpoint_client.get(
|
63
63
|
"series/#{series_id}/acl.xml"
|
64
64
|
)
|
65
65
|
acl_model = Matterhorn::Acl.new(response_body)
|
@@ -76,7 +76,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
76
76
|
def find(options)
|
77
77
|
dc_models = []
|
78
78
|
begin
|
79
|
-
split_response
|
79
|
+
split_response http_endpoint_client.get(
|
80
80
|
"series/series.xml#{build_query_str(options)}"
|
81
81
|
)
|
82
82
|
Nokogiri::XML(response_body).
|
@@ -97,7 +97,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
97
97
|
def count
|
98
98
|
count = 0
|
99
99
|
begin
|
100
|
-
split_response
|
100
|
+
split_response http_endpoint_client.get(
|
101
101
|
"series/count"
|
102
102
|
)
|
103
103
|
count = response_body.to_i
|
@@ -132,7 +132,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
132
132
|
def update_acl(series_id, acl)
|
133
133
|
acl_updated = false
|
134
134
|
begin
|
135
|
-
split_response
|
135
|
+
split_response http_endpoint_client.post(
|
136
136
|
"series/#{series_id}/accesscontrol", { 'acl' => acl.to_xml }
|
137
137
|
)
|
138
138
|
acl_updated = true
|
@@ -154,7 +154,7 @@ class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
|
154
154
|
def delete(series_id)
|
155
155
|
deleted = false
|
156
156
|
begin
|
157
|
-
split_response
|
157
|
+
split_response http_endpoint_client.delete(
|
158
158
|
"series/#{series_id}"
|
159
159
|
)
|
160
160
|
deleted = true
|
@@ -8,7 +8,7 @@ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
|
|
8
8
|
def instance(wi_id)
|
9
9
|
wi = nil
|
10
10
|
begin
|
11
|
-
split_response
|
11
|
+
split_response http_endpoint_client.get(
|
12
12
|
"workflow/instance/#{wi_id}.xml"
|
13
13
|
)
|
14
14
|
wi = response_body
|
@@ -25,7 +25,7 @@ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
|
|
25
25
|
def remove(wi_id)
|
26
26
|
wi_removed = false
|
27
27
|
begin
|
28
|
-
split_response
|
28
|
+
split_response http_endpoint_client.delete(
|
29
29
|
"workflow/remove/#{wi_id}"
|
30
30
|
)
|
31
31
|
wi_removed = true
|
@@ -42,7 +42,7 @@ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
|
|
42
42
|
def resume(wi_id)
|
43
43
|
wi = nil
|
44
44
|
begin
|
45
|
-
split_response
|
45
|
+
split_response http_endpoint_client.post(
|
46
46
|
"workflow/resume",
|
47
47
|
{ 'id' => wi_id }
|
48
48
|
)
|
@@ -61,7 +61,7 @@ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
|
|
61
61
|
def stop(wi_id)
|
62
62
|
wi = nil
|
63
63
|
begin
|
64
|
-
split_response
|
64
|
+
split_response http_endpoint_client.post(
|
65
65
|
"workflow/stop",
|
66
66
|
{ 'id' => wi_id }
|
67
67
|
)
|
data/lib/matterhorn/endpoint.rb
CHANGED
@@ -9,14 +9,15 @@ class Matterhorn::Endpoint
|
|
9
9
|
|
10
10
|
# ----------------------------------------------------------------------------- initialization ---
|
11
11
|
|
12
|
-
def self.create(endpoint)
|
12
|
+
def self.create(endpoint, org_domain = '', mh_instance = :default)
|
13
13
|
if endpoint.respond_to? 'to_s'
|
14
14
|
endpoint = endpoint.to_s.capitalize
|
15
15
|
else
|
16
16
|
raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
|
17
17
|
"#{endpoint.inspect} does not respond to 'to_s'")
|
18
18
|
end
|
19
|
-
endpoint = Object.const_get('Matterhorn').const_get('Endpoint').
|
19
|
+
endpoint = Object.const_get('Matterhorn').const_get('Endpoint').
|
20
|
+
const_get(endpoint).new(org_domain, mh_instance)
|
20
21
|
if endpoint.nil? || !endpoint.kind_of?(Matterhorn::Endpoint)
|
21
22
|
raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
|
22
23
|
"#{endpoint ? endpoint.class.name : 'nil'} is not a sub class " +
|
@@ -26,8 +27,8 @@ class Matterhorn::Endpoint
|
|
26
27
|
end
|
27
28
|
|
28
29
|
|
29
|
-
def self.open(endpoint)
|
30
|
-
endpoint = create(endpoint)
|
30
|
+
def self.open(endpoint, org_domain = '', mh_instance = :default)
|
31
|
+
endpoint = create(endpoint, mh_instance)
|
31
32
|
begin
|
32
33
|
yield endpoint
|
33
34
|
ensure
|
@@ -36,12 +37,33 @@ class Matterhorn::Endpoint
|
|
36
37
|
end
|
37
38
|
|
38
39
|
|
39
|
-
def initialize
|
40
|
-
@
|
41
|
-
MatterhornWhymper.configuration.
|
42
|
-
MatterhornWhymper.configuration.
|
43
|
-
|
40
|
+
def initialize(org_domain = '', mh_instance = :default)
|
41
|
+
@http_endpoint_client = Matterhorn::HttpClient.new(
|
42
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:protocol],
|
43
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:domain],
|
44
|
+
org_domain,
|
45
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:user],
|
46
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:password],
|
47
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:auth_mode],
|
48
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:http_timeout],
|
49
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:ssl_dont_verify_cert],
|
50
|
+
MatterhornWhymper.configuration.endpoint(mh_instance)[:multi_tenand]
|
44
51
|
)
|
52
|
+
@http_api_client = if !MatterhornWhymper.configuration.api(mh_instance).nil?
|
53
|
+
Matterhorn::HttpClient.new(
|
54
|
+
MatterhornWhymper.configuration.api(mh_instance)[:protocol],
|
55
|
+
MatterhornWhymper.configuration.api(mh_instance)[:domain],
|
56
|
+
org_domain,
|
57
|
+
MatterhornWhymper.configuration.api(mh_instance)[:user],
|
58
|
+
MatterhornWhymper.configuration.api(mh_instance)[:password],
|
59
|
+
MatterhornWhymper.configuration.api(mh_instance)[:auth_mode],
|
60
|
+
MatterhornWhymper.configuration.api(mh_instance)[:http_timeout],
|
61
|
+
MatterhornWhymper.configuration.api(mh_instance)[:ssl_dont_verify_cert],
|
62
|
+
MatterhornWhymper.configuration.api(mh_instance)[:multi_tenand]
|
63
|
+
)
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
45
67
|
@response_code = 200
|
46
68
|
@response_body = nil
|
47
69
|
@error_msg = ''
|
@@ -66,15 +88,21 @@ class Matterhorn::Endpoint
|
|
66
88
|
|
67
89
|
|
68
90
|
def close
|
69
|
-
|
91
|
+
http_endpoint_client.close
|
92
|
+
http_api_client.close
|
70
93
|
end
|
71
94
|
|
72
95
|
|
73
96
|
# ---------------------------------------------------------------------- *** protected section ***
|
74
97
|
protected
|
75
98
|
|
76
|
-
def
|
77
|
-
@
|
99
|
+
def http_endpoint_client
|
100
|
+
@http_endpoint_client
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def http_api_client
|
105
|
+
@http_api_client
|
78
106
|
end
|
79
107
|
|
80
108
|
|
@@ -2,6 +2,7 @@ require 'net/http/post/multipart'
|
|
2
2
|
require 'net/http/digest_auth'
|
3
3
|
require 'mime/types'
|
4
4
|
|
5
|
+
|
5
6
|
# =================================================================================== Matterhorn ===
|
6
7
|
|
7
8
|
module Matterhorn
|
@@ -11,27 +12,26 @@ module Matterhorn
|
|
11
12
|
|
12
13
|
class HttpClient
|
13
14
|
|
14
|
-
# ------------------------------------------------------------------------------- attributes ---
|
15
|
-
|
16
|
-
attr_reader :base_uri, :host, :port, :ssl, :ssl_dont_verify_cert, :timeout
|
17
|
-
|
18
|
-
|
19
15
|
# --------------------------------------------------------------------------- initialization ---
|
20
16
|
|
21
|
-
def initialize(
|
22
|
-
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
17
|
+
def initialize(protocol, domain, org_domain, user, password, auth_mode,
|
18
|
+
http_timeout = nil, ssl_dont_verify_cert = false, multi_tenand = true)
|
19
|
+
@sub_domain = org_domain.split('.').first
|
20
|
+
@uri = URI.parse("#{protocol}://#{domain}")
|
21
|
+
@uri.user = user
|
22
|
+
@uri.password = password
|
23
|
+
@auth_mode = auth_mode
|
24
|
+
@ssl = @uri.port == 443 ? true : false
|
25
|
+
@timeout = http_timeout
|
27
26
|
@ssl_dont_verify_cert = ssl_dont_verify_cert
|
27
|
+
@multi_tenand = multi_tenand
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
31
|
# ---------------------------------------------------------------------------- http methodes ---
|
32
32
|
|
33
33
|
def get(url)
|
34
|
-
request = Net::HTTP::Get.new(
|
34
|
+
request = Net::HTTP::Get.new(assemble_url(url))
|
35
35
|
execute_request(request)
|
36
36
|
end
|
37
37
|
|
@@ -45,9 +45,16 @@ module Matterhorn
|
|
45
45
|
execute_request(request)
|
46
46
|
end
|
47
47
|
|
48
|
+
|
49
|
+
def put(url, params = {})
|
50
|
+
request = Net::HTTP::Put.new(assemble_url(url))
|
51
|
+
request.set_form_data(params)
|
52
|
+
execute_request(request)
|
53
|
+
end
|
48
54
|
|
55
|
+
|
49
56
|
def delete(url)
|
50
|
-
request = Net::HTTP::Delete.new(
|
57
|
+
request = Net::HTTP::Delete.new(assemble_url(url))
|
51
58
|
execute_request(request)
|
52
59
|
end
|
53
60
|
|
@@ -62,19 +69,28 @@ module Matterhorn
|
|
62
69
|
|
63
70
|
def http_socket
|
64
71
|
return @http_socket if !@http_socket.nil? && @http_socket.started?
|
65
|
-
@http_socket = Net::HTTP.new(host, port)
|
66
|
-
@http_socket.use_ssl = ssl
|
67
|
-
@http_socket.verify_mode = OpenSSL::SSL::VERIFY_NONE if ssl && ssl_dont_verify_cert
|
68
|
-
if
|
69
|
-
@http_socket.open_timeout = timeout
|
70
|
-
@http_socket.read_timeout = timeout
|
72
|
+
@http_socket = Net::HTTP.new(@uri.host, @uri.port)
|
73
|
+
@http_socket.use_ssl = @ssl
|
74
|
+
@http_socket.verify_mode = OpenSSL::SSL::VERIFY_NONE if @ssl && @ssl_dont_verify_cert
|
75
|
+
if !@timeout.nil?
|
76
|
+
@http_socket.open_timeout = @timeout
|
77
|
+
@http_socket.read_timeout = @timeout
|
71
78
|
end
|
72
79
|
@http_socket.start
|
73
80
|
end
|
74
81
|
|
82
|
+
|
83
|
+
def assemble_url(url)
|
84
|
+
if @multi_tenand && !@sub_domain.blank?
|
85
|
+
@uri.request_uri + "#{@sub_domain}/" + url
|
86
|
+
else
|
87
|
+
@uri.request_uri + url
|
88
|
+
end
|
89
|
+
end
|
75
90
|
|
91
|
+
|
76
92
|
def singlepart_post(url, params)
|
77
|
-
request = Net::HTTP::Post.new(
|
93
|
+
request = Net::HTTP::Post.new(assemble_url(url))
|
78
94
|
request.set_form_data(params)
|
79
95
|
request
|
80
96
|
end
|
@@ -102,18 +118,23 @@ module Matterhorn
|
|
102
118
|
mime_type = MIME::Types.type_for(File.basename(file.path)).first
|
103
119
|
end
|
104
120
|
params['BODY'] = UploadIO.new(file, mime_type, filename)
|
105
|
-
Net::HTTP::Post::Multipart.new(
|
121
|
+
Net::HTTP::Post::Multipart.new(assemble_url(url), params)
|
106
122
|
end
|
107
123
|
|
108
124
|
|
109
125
|
def execute_request(request)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
126
|
+
case @auth_mode
|
127
|
+
when 'basic'
|
128
|
+
request.basic_auth(@uri.user, @uri.password)
|
129
|
+
when 'digest'
|
130
|
+
head = Net::HTTP::Head.new(@uri.request_uri + request.path)
|
131
|
+
head['X-REQUESTED-AUTH'] = 'Digest'
|
132
|
+
head['X-Opencast-Matterhorn-Authorization'] = 'true'
|
133
|
+
digest_result = http_socket.request(head)
|
134
|
+
digest_auth = Net::HTTP::DigestAuth.new
|
135
|
+
auth = digest_auth.auth_header(@uri, digest_result['www-authenticate'], request.method)
|
136
|
+
request.add_field('Authorization', auth)
|
137
|
+
end
|
117
138
|
response = http_socket.request(request)
|
118
139
|
case response.code.to_i
|
119
140
|
when 200..299
|
@@ -98,6 +98,17 @@ class Matterhorn::MediaPackage
|
|
98
98
|
end
|
99
99
|
|
100
100
|
|
101
|
+
def dc_catalog_url
|
102
|
+
url_elem = @document.at_xpath('//xmlns:catalog[@type="dublincore/episode"]/xmlns:url',
|
103
|
+
{'xmlns' => XML_NS_MEDIAPACKAGE})
|
104
|
+
if url_elem
|
105
|
+
url_elem.content
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
101
112
|
# <media>
|
102
113
|
# <track type="presenter/source+partial">
|
103
114
|
# <tags/>
|
@@ -115,6 +126,17 @@ class Matterhorn::MediaPackage
|
|
115
126
|
end
|
116
127
|
|
117
128
|
|
129
|
+
def track_url(flavor)
|
130
|
+
url_elem = @document.at_xpath("//xmlns:track[contains(@type, \"#{flavor}\")]/xmlns:url",
|
131
|
+
{'xmlns' => Matterhorn::MediaPackage::XML_NS_MEDIAPACKAGE})
|
132
|
+
if url_elem
|
133
|
+
url_elem.content
|
134
|
+
else
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
118
140
|
# Returns the id attribute of mediapackage element.
|
119
141
|
# <mediapackage xmlns="http://mediapackage.opencastproject.org" id="1" duration="2704016" start="2014-04-23T12:35:00Z">
|
120
142
|
#
|
@@ -5,7 +5,7 @@ module MatterhornWhymper
|
|
5
5
|
|
6
6
|
# -------------------------------------------------------------------------- const definitions ---
|
7
7
|
|
8
|
-
VERSION = "0.
|
8
|
+
VERSION = "1.0.0"
|
9
9
|
|
10
10
|
|
11
11
|
end # -------------------------------------------------------------------- end MatterhornWhymper ---
|
data/lib/matterhorn_whymper.rb
CHANGED
@@ -46,7 +46,6 @@ module MatterhornWhymper
|
|
46
46
|
require 'logger'
|
47
47
|
self.logger = Logger.new(STDOUT)
|
48
48
|
end
|
49
|
-
self.configuration.http_timeout = nil
|
50
49
|
yield(configuration) if block_given?
|
51
50
|
end
|
52
51
|
|
@@ -56,16 +55,62 @@ module MatterhornWhymper
|
|
56
55
|
|
57
56
|
class Configuration
|
58
57
|
|
59
|
-
#
|
58
|
+
# --------------------------------------------------------------------------------- methodes ---
|
60
59
|
|
61
|
-
|
62
|
-
|
60
|
+
def initialize
|
61
|
+
@mhw_config = {}
|
62
|
+
end
|
63
63
|
|
64
|
+
def add_matterhorn_instance(name = 'default')
|
65
|
+
@mhw_config[name.to_sym] = {}
|
66
|
+
end
|
64
67
|
|
65
|
-
|
68
|
+
def add_endpoint(options, mh_i = 'default')
|
69
|
+
@mhw_config[mh_i.to_sym][:endpoint] = validate_options(options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_api(options, mh_i = 'default')
|
73
|
+
@mhw_config[mh_i.to_sym][:api] = validate_options(options)
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_default_matterhorn_instance(mh_i)
|
77
|
+
unless @mhw_config[mh_i.to_sym].nil?
|
78
|
+
@mhw_config[:default] = @mhw_config[mh_i.to_sym]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def endpoint(mh_i = :default)
|
84
|
+
@mhw_config[mh_i][:endpoint]
|
85
|
+
end
|
86
|
+
|
87
|
+
def api(mh_i = :default)
|
88
|
+
@mhw_config[mh_i][:api]
|
89
|
+
end
|
66
90
|
|
67
|
-
|
68
|
-
|
91
|
+
|
92
|
+
# -------------------------------------------------------------------------- private section ---
|
93
|
+
private
|
94
|
+
|
95
|
+
def validate_options(opt)
|
96
|
+
valid_keys = [:protocol, :domain, :user, :password, :auth_mode,
|
97
|
+
:http_timeout, :ssl_dont_verify_cert, :multi_tenand]
|
98
|
+
options = {
|
99
|
+
:protocol => 'http',
|
100
|
+
:domain => 'example.org',
|
101
|
+
:user => 'admin',
|
102
|
+
:password => '',
|
103
|
+
:auth_mode => 'basic',
|
104
|
+
:http_timeout => nil,
|
105
|
+
:ssl_dont_verify_cert => false,
|
106
|
+
:multi_tenand => true
|
107
|
+
}
|
108
|
+
opt.each do |key, value|
|
109
|
+
if valid_keys.include? key.to_sym
|
110
|
+
options[key.to_sym] = value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
options
|
69
114
|
end
|
70
115
|
|
71
116
|
|
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Fritschi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|