marty 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74092a6c860ba6143a686a653e304abd173f7b1e
4
- data.tar.gz: 7e18178b04dacec033571c2566c653043d27116a
3
+ metadata.gz: cb347975c0c4442e6466f8cbcbd72d431c85f45f
4
+ data.tar.gz: 4c7de97777049441bbf43ea5d324ed1a4c858315
5
5
  SHA512:
6
- metadata.gz: c9666aa7555d70c078cb27745206af4ae51dfa6728d21f0cb637d1736cb106b19228c6056c51d16a3a923f1630ee732a93768ca252d7fde6ecc7229a1f091586
7
- data.tar.gz: 675388c07330499a07f89705c7887eadaf0da17cef12c65c0ae914ca55d3c59062e08676c6af36aff1b6891827b94348849ccb3770fe6cbc66577b70c5775bc9
6
+ metadata.gz: dc0b688584580e74b519a04559d0c3dd6bcbc0d3fc2e00949403a32c54ef25f78380573238f8d80d048ce434d3c936a6c455db94c1a2945065ea4c39525b277d
7
+ data.tar.gz: 7318c212db79212f25ad3fcfc3f27d28e666f1948d333b93f7ab5d5689e5eb4f16f54873a02d016eff9678bd607a7edce244d3234b94e2229c05b7313149197b
@@ -1,24 +1,40 @@
1
1
  class Marty::RpcCall
2
- def self.marty_post(host, port, path, script, node, attrs, params)
2
+ # POST to a remote marty
3
+ def self.marty_post(host, port, path, script, node, attrs, params, options={})
3
4
  http = Net::HTTP.new(host, port)
4
5
  request = Net::HTTP::Post.new(path)
5
6
  request.add_field('Content-Type', 'application/json')
6
- request.body = {
7
- "script" => script,
8
- "node" => node,
9
- "attrs" => attrs.to_json,
10
- "params" => params.to_json,
11
- }.to_json
7
+ request.body = (options + {
8
+ "script" => script,
9
+ "node" => node,
10
+ "attrs" => attrs.to_json,
11
+ "params" => params.to_json,
12
+ }).to_json
12
13
  begin
13
- resraw = http.request(request)
14
+ response = http.request(request)
14
15
  rescue => e
15
16
  raise "#{e.message} during RPC call to #{host}:#{port}"
16
17
  end
17
- res = JSON.parse(resraw.body)
18
+
19
+ res = JSON.parse(response.body)
18
20
  raise res["error"] if res.is_a?(Hash) && !res["error"].blank?
19
21
  res
20
22
  end
21
23
 
24
+ def self.marty_download(host, port, path, job_id)
25
+ params = {job_id: job_id}
26
+ url = path + '?' + URI.encode(URI.encode_www_form(params))
27
+
28
+ http = Net::HTTP.new(host, port)
29
+ request = Net::HTTP::Get.new(url)
30
+
31
+ begin
32
+ http.request(request)
33
+ rescue => e
34
+ raise "#{e.message} during download call to #{host}:#{port}"
35
+ end
36
+ end
37
+
22
38
  def self.xml_call(host, port, path, body, use_ssl)
23
39
  http = Net::HTTP.new(host, port)
24
40
  request = Net::HTTP::Post.new(path)
@@ -26,14 +42,14 @@ class Marty::RpcCall
26
42
  request.add_field('Content-Type', 'xml')
27
43
  request.add_field('Accept', 'xml')
28
44
  request.body = body
45
+
29
46
  begin
30
- resraw = http.request(request)
31
- if resraw.class != Net::HTTPOK
32
- raise "got #{resraw} during XML call"
33
- end
47
+ response = http.request(request)
48
+ raise "got #{response} during XML call" if response.class != Net::HTTPOK
34
49
  rescue => e
35
50
  raise "#{e.message} during RPC call to #{host}:#{port}#{path}"
36
51
  end
37
- resraw.body
52
+
53
+ response.body
38
54
  end
39
55
  end
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "1.0.11"
2
+ VERSION = "1.0.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani