algorithmia 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af5707cad45492ed4759ffcac8b783a607103ebd
4
- data.tar.gz: 924fdf137930e6918776422a83375e3230ba8a2b
3
+ metadata.gz: 221b1eceac956d96b62ff29d39f7d3f922f17607
4
+ data.tar.gz: 9a95bdc4128ca4bfbbc72e2be46e6279cb807eed
5
5
  SHA512:
6
- metadata.gz: ea5c9f40c37f248eafcbac914c3798826d5f3ad2950021be5bfccfe993a23504eded7d79a2675de9bad0e8e468d2fdaaff6f7287a76231a239066f5474f157da
7
- data.tar.gz: 2384aa57d51524efbe30da2dbe1b16c678701e5e402deeed10f4aa4716357462536b262ebb1d1594b41457f57b27bc3d1d9b435a05fbb7f4f44211f9fad6c2ee
6
+ metadata.gz: 7ce500a43c125a943e498913dba6a5f99d2652c73d7a7db8f198759cf380475db0afd590f3a05b37369dd3f858c6df68e77e498bd51989c4a8e14e0830bdcea4
7
+ data.tar.gz: 2dc4531f7708d00e13806eb6102b91e81eff0404eace4e42824e0ae91ed877ad7d8669a4fb335be563eb8095ed651d4e611824ef40605929bc8da65b156852c9
@@ -12,15 +12,15 @@ module Algorithmia
12
12
  end
13
13
 
14
14
  def set_options(options_hash)
15
- @query_options.update(options_hash)
15
+ @query.update(options_hash)
16
16
  end
17
17
 
18
18
  def set_timeout(timeout)
19
- @query_options[:timeout] = timeout.to_i
19
+ @query[:timeout] = timeout.to_i
20
20
  end
21
21
 
22
22
  def enable_stdout
23
- @query_options[:stdout] = true
23
+ @query[:stdout] = true
24
24
  end
25
25
 
26
26
  def pipe(input)
@@ -38,7 +38,7 @@ module Algorithmia
38
38
  }
39
39
 
40
40
  response = Algorithmia::Requester.new(@client).post(@endpoint, input, query: @query, headers: headers)
41
- Algorithmia::Response.new(response.parsed_response)
41
+ Algorithmia::Response.new(response.parsed_response, @query[:output])
42
42
  end
43
43
 
44
44
  def pipe_json(input)
@@ -66,22 +66,39 @@ module Algorithmia
66
66
 
67
67
  def check_for_errors(response)
68
68
  if response.code >= 200 && response.code < 300
69
- parse_error_message(response) if response['error']
69
+ if response.is_a?(Hash) and response['error']
70
+ parse_error_message(response) if response['error']
71
+ end
70
72
  return
71
73
  end
72
74
 
73
75
 
74
76
  case response.code
75
77
  when 401
76
- raise Errors::UnauthorizedError.new("The request you are making requires authorization. Please check that you have permissions & that you've set your API key.", response)
78
+ if response.nil?
79
+ raise Errors::UnauthorizedError.new("The request you are making requires authorization. Please check that you have permissions & that you've set your API key.", nil)
80
+ end
81
+ raise Errors::UnauthorizedError.new(response["error"]["message"], response)
77
82
  when 400
83
+ if response.nil?
84
+ raise Errors::NotFoundError.new("The request was invalid", nil)
85
+ end
78
86
  parse_error_message(response)
79
87
  when 404
80
- raise Errors::NotFoundError.new("The URI requested is invalid or the resource requested does not exist.", response)
88
+ if response.nil?
89
+ raise Errors::NotFoundError.new("The URI requested is invalid or the resource requested does not exist.", nil)
90
+ end
91
+ raise Errors::NotFoundError.new(response["error"]["message"], response)
81
92
  when 500
82
- raise Errors::InternalServerError.new("Whoops! Something is broken.", response)
93
+ if response.nil?
94
+ raise Errors::InternalServerError.new("Whoops! Something is broken.", nil)
95
+ end
96
+ raise Errors::InternalServerError.new(response["error"]["message"], response)
83
97
  else
84
- raise Errors::UnknownError.new("The error you encountered returned the message: #{response["error"]["message"]} with stacktrace: #{error["stacktrace"]}", response)
98
+ if response.nil?
99
+ raise Errors::UnknownError.new("An unknown error occurred", nil)
100
+ end
101
+ raise Errors::UnknownError.new("message: #{response["error"]["message"]} stacktrace: #{error["stacktrace"]}", response)
85
102
  end
86
103
  end
87
104
 
@@ -95,9 +112,9 @@ module Algorithmia
95
112
  raise Errors::JsonParseError.new("Unable to parse the input. Please make sure it matches the expected input of the algorithm and can be parsed into JSON.", response)
96
113
  else
97
114
  if error["stacktrace"].nil?
98
- raise Errors::UnknownError.new("The error you encountered returned the message: #{error["message"]}", response)
115
+ raise Errors::UnknownError.new(error["message"], response)
99
116
  else
100
- raise Errors::UnknownError.new("The error you encountered returned the message: #{error["message"]} with stacktrace: #{error["stacktrace"]}", response)
117
+ raise Errors::UnknownError.new("message: #{error["message"]} stacktrace: #{error["stacktrace"]}", response)
101
118
  end
102
119
  end
103
120
  end
@@ -2,38 +2,61 @@ require "base64"
2
2
 
3
3
  module Algorithmia
4
4
  class Response
5
- attr_reader :json
5
+ attr_reader :response
6
6
 
7
- def initialize(result)
8
- @json = result
7
+ def initialize(response, output_type)
8
+ @response = response
9
+ @output_type = output_type
9
10
  end
10
11
 
11
12
  def result
12
- if content_type == 'binary'
13
- Base64.decode64(@json["result"])
13
+ if @output_type == 'raw'
14
+ @response
15
+ elsif content_type == 'binary'
16
+ Base64.decode64(@response["result"])
14
17
  else
15
- @json["result"]
18
+ @response["result"]
16
19
  end
17
20
  end
18
21
 
19
22
  def metadata
20
- @json["metadata"]
23
+ if @output_type == 'raw'
24
+ nil
25
+ else
26
+ @response["metadata"]
27
+ end
21
28
  end
22
29
 
23
30
  def duration
24
- metadata["duration"]
31
+ if @output_type == 'raw'
32
+ nil
33
+ else
34
+ metadata["duration"]
35
+ end
25
36
  end
26
37
 
27
38
  def content_type
28
- metadata["content_type"]
39
+ if @output_type == 'raw'
40
+ nil
41
+ else
42
+ metadata["content_type"]
43
+ end
29
44
  end
30
45
 
31
46
  def stdout
32
- metadata["stdout"]
47
+ if @output_type == 'raw'
48
+ nil
49
+ else
50
+ metadata["stdout"]
51
+ end
33
52
  end
34
53
 
35
54
  def alerts
36
- metadata["alerts"]
55
+ if @output_type == 'raw'
56
+ nil
57
+ else
58
+ metadata["alerts"]
59
+ end
37
60
  end
38
61
  end
39
62
  end
@@ -1,3 +1,3 @@
1
1
  module Algorithmia
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algorithmia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algorithmia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler