sidemash-sdk 0.1.0 → 0.1.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +58 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +203 -0
  8. data/README.md +43 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/sidemash-sdk +3 -0
  13. data/lib/sidemash/sdk/auth.rb +75 -0
  14. data/lib/sidemash/sdk/client.rb +36 -0
  15. data/lib/sidemash/sdk/create_stream_square_form.rb +114 -0
  16. data/lib/sidemash/sdk/domain.rb +24 -0
  17. data/lib/sidemash/sdk/hook.rb +71 -0
  18. data/lib/sidemash/sdk/hook_http_call.rb +75 -0
  19. data/lib/sidemash/sdk/hook_ws_call.rb +75 -0
  20. data/lib/sidemash/sdk/hook_zoom.rb +41 -0
  21. data/lib/sidemash/sdk/http.rb +112 -0
  22. data/lib/sidemash/sdk/http_call_error.rb +13 -0
  23. data/lib/sidemash/sdk/http_method.rb +119 -0
  24. data/lib/sidemash/sdk/http_request.rb +32 -0
  25. data/lib/sidemash/sdk/instance_status.rb +175 -0
  26. data/lib/sidemash/sdk/list_form.rb +95 -0
  27. data/lib/sidemash/sdk/pagination.rb +116 -0
  28. data/lib/sidemash/sdk/play.rb +68 -0
  29. data/lib/sidemash/sdk/publish.rb +68 -0
  30. data/lib/sidemash/sdk/publish_rtmp.rb +82 -0
  31. data/lib/sidemash/sdk/rest_collection.rb +65 -0
  32. data/lib/sidemash/sdk/secure_and_non_secure.rb +82 -0
  33. data/lib/sidemash/sdk/stream_meta_data.rb +68 -0
  34. data/lib/sidemash/sdk/stream_square.rb +148 -0
  35. data/lib/sidemash/sdk/stream_square_rest_collection.rb +82 -0
  36. data/lib/sidemash/sdk/stream_square_service.rb +56 -0
  37. data/lib/sidemash/sdk/stream_square_size.rb +119 -0
  38. data/lib/sidemash/sdk/timestamp.rb +68 -0
  39. data/lib/sidemash/sdk/update_stream_square_form.rb +100 -0
  40. data/lib/sidemash/sdk/user_desc.rb +68 -0
  41. data/lib/sidemash/sdk/utc_date_time.rb +75 -0
  42. data/lib/sidemash/sdk/version.rb +5 -0
  43. data/lib/sidemash/sdk.rb +39 -0
  44. data/sidemash-sdk.gemspec +31 -0
  45. metadata +48 -4
@@ -0,0 +1,24 @@
1
+ module Sidemash::Sdk
2
+ class Domain
3
+
4
+ attr_reader :_type
5
+ attr_reader :id
6
+ attr_reader :url
7
+ attr_reader :created_time
8
+ attr_reader :foreign_data
9
+ attr_reader :description
10
+ attr_reader :name
11
+ attr_reader :status
12
+
13
+ def initialize(obj)
14
+ @_type = obj['_type']
15
+ @id = obj['id']
16
+ @url = obj['url']
17
+ @created_time = obj['createdTime']
18
+ @foreign_data = obj['foreignData']
19
+ @description = obj['description']
20
+ @name = obj['name']
21
+ @status = obj['status']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ =begin
2
+ Copyright © 2020 Sidemash Cloud Services
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing,
11
+ software distributed under the License is distributed on an
12
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13
+ either express or implied. See the License for the specific
14
+ language governing permissions and limitations under the License.
15
+ =end
16
+
17
+
18
+
19
+
20
+ module Sidemash::Sdk
21
+ class Hook
22
+ def http_call?
23
+ @_type == HttpCall._type
24
+ end
25
+
26
+ def ws_call?
27
+ @_type == WsCall._type
28
+ end
29
+
30
+ def not_http_call?
31
+ @_type != HttpCall._type
32
+ end
33
+
34
+ def not_ws_call?
35
+ @_type != WsCall._type
36
+ end
37
+
38
+ def self.from_json(js)
39
+ h = JSON.parse(js)
40
+ Hook.from_hash(h)
41
+ end
42
+
43
+ def to_remote
44
+ raise NotImplementedError, 'The implementation lies in the children classes HttpCall, WsCall'
45
+ end
46
+
47
+ def to_hash
48
+ raise NotImplementedError, 'The implementation lies in the children classes HttpCall, WsCall'
49
+ end
50
+
51
+ def self.from_remote(h)
52
+ case h['_type']
53
+ when HookHttpCall._type then HookHttpCall.from_remote(h)
54
+ when HookWsCall._type then HookWsCall.from_remote(h)
55
+ else raise(ArgumentError, "Invalid hash submitted for creating 'Hook'" + " Unexpected '_type' = " + ty)
56
+ end
57
+ end
58
+
59
+ def self.from_hash(h)
60
+ case h['_type']
61
+ when HookHttpCall._type then HookHttpCall.from_hash(h)
62
+ when HookWsCall._type then HookWsCall.from_hash(h)
63
+ else raise(ArgumentError, "Invalid hash submitted for creating 'Hook'" + " Unexpected '_type' = " + ty)
64
+ end
65
+ end
66
+
67
+ def to_json(*a)
68
+ to_hash.to_json(*a)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,75 @@
1
+ =begin
2
+ Copyright © 2020 Sidemash Cloud Services
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing,
11
+ software distributed under the License is distributed on an
12
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13
+ either express or implied. See the License for the specific
14
+ language governing permissions and limitations under the License.
15
+ =end
16
+
17
+
18
+
19
+
20
+ module Sidemash::Sdk
21
+ class HookHttpCall < Hook
22
+ attr_reader :method
23
+ attr_reader :url
24
+
25
+ def initialize(method, url)
26
+ @_type = 'Hook.HttpCall'
27
+ @method = method
28
+ @url = url
29
+ end
30
+
31
+ def self._type
32
+ 'Hook.HttpCall'
33
+ end
34
+
35
+ def self.from_json(js)
36
+ h = JSON.parse(js)
37
+ HookHttpCall.from_hash(h)
38
+ end
39
+
40
+ def to_remote
41
+ result = {}
42
+ result[:_type] = @_type
43
+ result[:method] = @method.to_s
44
+ result[:url] = @url
45
+ result
46
+ end
47
+
48
+ def to_hash
49
+ result = {}
50
+ result[:_type] = @_type
51
+ result[:method] = @method.to_s
52
+ result[:url] = @url
53
+ result
54
+ end
55
+
56
+ def self.from_remote(h)
57
+ HookHttpCall.new(HttpMethod.from_s(h['method']),
58
+ h['url'])
59
+ end
60
+
61
+ def self.from_hash(h)
62
+ HookHttpCall.new(HttpMethod.from_s(h['method']),
63
+ h['url'])
64
+ end
65
+
66
+ def to_json(*a)
67
+ to_hash.to_json(*a)
68
+ end
69
+
70
+ def to_s
71
+ ('HookHttpCall(method=' + @method.to_s +
72
+ ', url=' + @url + ')')
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ =begin
2
+ Copyright © 2020 Sidemash Cloud Services
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing,
11
+ software distributed under the License is distributed on an
12
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13
+ either express or implied. See the License for the specific
14
+ language governing permissions and limitations under the License.
15
+ =end
16
+
17
+
18
+
19
+
20
+ module Sidemash::Sdk
21
+ class HookWsCall < Hook
22
+ attr_reader :method
23
+ attr_reader :url
24
+
25
+ def initialize(method, url)
26
+ @_type = 'Hook.WsCall'
27
+ @method = method
28
+ @url = url
29
+ end
30
+
31
+ def self._type
32
+ 'Hook.WsCall'
33
+ end
34
+
35
+ def self.from_json(js)
36
+ h = JSON.parse(js)
37
+ HookWsCall.from_hash(h)
38
+ end
39
+
40
+ def to_remote
41
+ result = {}
42
+ result[:_type] = @_type
43
+ result[:method] = @method.to_s
44
+ result[:url] = @url
45
+ result
46
+ end
47
+
48
+ def to_hash
49
+ result = {}
50
+ result[:_type] = @_type
51
+ result[:method] = @method.to_s
52
+ result[:url] = @url
53
+ result
54
+ end
55
+
56
+ def self.from_remote(h)
57
+ HookWsCall.new(HttpMethod.from_s(h['method']),
58
+ h['url'])
59
+ end
60
+
61
+ def self.from_hash(h)
62
+ HookWsCall.new(HttpMethod.from_s(h['method']),
63
+ h['url'])
64
+ end
65
+
66
+ def to_json(*a)
67
+ to_hash.to_json(*a)
68
+ end
69
+
70
+ def to_s
71
+ ('HookWsCall(method=' + @method.to_s +
72
+ ', url=' + @url + ')')
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,41 @@
1
+
2
+
3
+ module Sidemash::Sdk
4
+ class HookZoom < Hook
5
+ def initialize()
6
+ end
7
+
8
+ def self._type
9
+ 'Hook.Zoom'
10
+ end
11
+
12
+ def self.from_json(js)
13
+ h = JSON.parse(js)
14
+ HookZoom.from_hash(h)
15
+ end
16
+
17
+ def to_remote
18
+ result[:_type] = @_type
19
+ end
20
+
21
+ def to_hash
22
+ result[:_type] = @_type
23
+ end
24
+
25
+ def self.from_remote(h)
26
+ HookZoom.new()
27
+ end
28
+
29
+ def self.from_hash(h)
30
+ HookZoom.new()
31
+ end
32
+
33
+ def to_json(*a)
34
+ to_hash.to_json(*a)
35
+ end
36
+
37
+ def to_s
38
+ 'HookZoom'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,112 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'httparty'
4
+
5
+ module Sidemash::SDK
6
+ class Http
7
+
8
+ def self.post(path:, body:, query_string:, headers:, auth:)
9
+ Http._call(path, 'POST', body, auth, query_string, headers)
10
+ end
11
+
12
+ def self.list(path:, query_string:, headers:, auth:)
13
+ Http._call(path, 'GET', nil, auth, query_string, headers)
14
+ end
15
+
16
+ def self.get(path:, query_string:, headers:, auth:)
17
+ Http._call(path, 'GET', nil, auth, query_string, headers)
18
+ end
19
+
20
+ def self.put(path: , body:, query_string:, headers:, auth:)
21
+ Http._call(path, 'PUT', body, auth, query_string, headers)
22
+ end
23
+
24
+ def self.patch(path:, body:, query_string:, headers:, auth:)
25
+ Http._call(path, 'PATCH', body, auth, query_string, headers)
26
+ end
27
+
28
+ def self.delete(path:, body:, query_string:, headers:, auth:)
29
+ Http._call(path, 'DELETE', body, auth, query_string, headers)
30
+ end
31
+
32
+
33
+ private_class_method
34
+ def self.version
35
+ "V1.0"
36
+ end
37
+
38
+ private_class_method
39
+ def self._host
40
+ 'http://dev-api.sidemash.io'
41
+ end
42
+
43
+ private_class_method
44
+ def self._sign(message, private_key)
45
+ signature = OpenSSL::HMAC.digest('sha512', private_key, message)
46
+ Base64.strict_encode64(signature)
47
+ end
48
+
49
+ private_class_method
50
+ def self._sha256(message)
51
+ hash = OpenSSL::Digest.digest('sha256', message)
52
+ Base64.strict_encode64(hash)
53
+ end
54
+
55
+ private_class_method
56
+ def self._compute_signed_headers(body, headers, auth)
57
+ signed_headers =
58
+ {'Accept' => 'application/json', 'User-Agent' => 'Sdk Ruby v1.0', 'Authorization': 'Bearer ' + auth.token},
59
+ merge(headers).
60
+ merge(body.nil? ? {} : {'Content-Type' => 'application/json'})
61
+ signed_headers
62
+ end
63
+
64
+ private_class_method
65
+ def self._make_request(method, url, body, headers)
66
+ response = nil
67
+ case method
68
+ when 'POST'
69
+ response = HTTParty.post(url, body: body, headers: headers)
70
+ when 'GET'
71
+ response = HTTParty.get(url, body: body, headers: headers)
72
+ when 'PATCH'
73
+ response = HTTParty.patch(url, body: body, headers: headers)
74
+ when 'PUT'
75
+ response = HTTParty.put(url, body: body, headers: headers)
76
+ when 'DELETE'
77
+ response = HTTParty.delete(url, headers: headers)
78
+ else
79
+ raise 'Unsupported HTTP Method: ' + method
80
+ end
81
+ return response
82
+ end
83
+
84
+
85
+ private_class_method
86
+ def self._call(path, method, body, auth, query_string, headers)
87
+ body_str = body.nil? ? nil : body.to_json
88
+ url = Http._host + path + query_string
89
+ signed_headers = Http._compute_signed_headers(body, headers.nil? ? {} : headers, auth)
90
+ sdm_request = Sidemash::Sdk::HttpRequest.new(signed_headers,
91
+ method,
92
+ path,
93
+ query_string,
94
+ body_str.nil? ? nil : Http._sha256(body_str))
95
+ h = signed_headers
96
+ h['X-Sdm-SignedHeaders'] = signed_headers.keys.select { |key| key }.join(', ')
97
+ h['X-Sdm-Nonce'] = sdm_request.nonce.to_s
98
+ h['X-Sdm-Signature'] = 'SHA512 ' + Http._sign(sdm_request.to_message, auth.private_key)
99
+ response = Http._make_request(method, url, body_str, h)
100
+ if response.code == 204
101
+ nil
102
+ else
103
+ response_json = JSON.parse(response.body)
104
+ if response.code < 300
105
+ response_json
106
+ else
107
+ raise Sidemash::Sdk::HttpCallError.new(response.code, response_json)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module Sidemash::Sdk
3
+ class HttpCallError < StandardError
4
+ attr_reader :status_code
5
+ attr_reader :body
6
+
7
+ def initialize(status_code, body)
8
+ super(JSON.pretty_generate(body))
9
+ @status_code = status_code
10
+ @body = body
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,119 @@
1
+ =begin
2
+ Copyright © 2020 Sidemash Cloud Services
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing,
11
+ software distributed under the License is distributed on an
12
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13
+ either express or implied. See the License for the specific
14
+ language governing permissions and limitations under the License.
15
+ =end
16
+
17
+
18
+
19
+
20
+ module Sidemash::Sdk
21
+ class HttpMethod
22
+ attr_reader :value
23
+
24
+ def initialize(value)
25
+ @value = value
26
+ end
27
+
28
+ def self.get
29
+ HttpMethod.new('GET')
30
+ end
31
+
32
+ def self.post
33
+ HttpMethod.new('POST')
34
+ end
35
+
36
+ def self.put
37
+ HttpMethod.new('PUT')
38
+ end
39
+
40
+ def self.delete
41
+ HttpMethod.new('DELETE')
42
+ end
43
+
44
+ def self.patch
45
+ HttpMethod.new('PATCH')
46
+ end
47
+
48
+ def self.all_possibles_values
49
+ Set['GET',
50
+ 'POST',
51
+ 'PUT',
52
+ 'DELETE',
53
+ 'PATCH']
54
+ end
55
+
56
+ def self.from_s(value)
57
+ case value
58
+ when 'GET' then HttpMethod.get
59
+ when 'POST' then HttpMethod.post
60
+ when 'PUT' then HttpMethod.put
61
+ when 'DELETE' then HttpMethod.delete
62
+ when 'PATCH' then HttpMethod.patch
63
+ else nil
64
+ end
65
+ end
66
+
67
+ def self.valid?(value)
68
+ HttpMethod.all_possibles_values.include? value
69
+ end
70
+
71
+ def not_get?
72
+ @value != 'GET'
73
+ end
74
+
75
+ def not_post?
76
+ @value != 'POST'
77
+ end
78
+
79
+ def not_put?
80
+ @value != 'PUT'
81
+ end
82
+
83
+ def not_delete?
84
+ @value != 'DELETE'
85
+ end
86
+
87
+ def not_patch?
88
+ @value != 'PATCH'
89
+ end
90
+
91
+ def get?
92
+ @value == 'GET'
93
+ end
94
+
95
+ def post?
96
+ @value == 'POST'
97
+ end
98
+
99
+ def put?
100
+ @value == 'PUT'
101
+ end
102
+
103
+ def delete?
104
+ @value == 'DELETE'
105
+ end
106
+
107
+ def patch?
108
+ @value == 'PATCH'
109
+ end
110
+
111
+ def to_json(*a)
112
+ @value
113
+ end
114
+
115
+ def to_s
116
+ @value
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,32 @@
1
+
2
+ module Sidemash::Sdk
3
+ class HttpRequest
4
+ attr_reader :nonce
5
+ attr_reader :signed_headers
6
+ attr_reader :method
7
+ attr_reader :path
8
+ attr_reader :query_string
9
+ attr_reader :body_hash
10
+
11
+ def initialize(signed_headers, method, path, query_string, body_hash)
12
+ now = Time.now
13
+ @nonce = now.to_i + now.usec / 1000
14
+ @signed_headers = signed_headers
15
+ @method = method
16
+ @path = path
17
+ @query_string = query_string
18
+ @body_hash = body_hash
19
+ end
20
+
21
+ def to_message
22
+ result = ''
23
+ result += @nonce.to_s
24
+ result += @signed_headers.map { |header_name, header_value| header_name + ':' + header_value }.join('')
25
+ result += @method
26
+ result += @path
27
+ result += !@query_string.nil? ? @query_string : ''
28
+ result += !@body_hash.nil? ? @body_hash : ''
29
+ result
30
+ end
31
+ end
32
+ end