mortar-api-ruby 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mortar-api-ruby (0.3.1)
4
+ mortar-api-ruby (0.3.0)
5
5
  excon (~> 0.15.4)
6
6
 
7
7
  GEM
@@ -32,6 +32,7 @@ module Mortar
32
32
  end
33
33
  end
34
34
 
35
+ class Redirect < ErrorWithResponse; end
35
36
  class BadRequest < ErrorWithResponse; end
36
37
  class Unauthorized < ErrorWithResponse; end
37
38
  class VerificationRequired < ErrorWithResponse; end
@@ -18,7 +18,7 @@ module Mortar
18
18
  class API
19
19
  # client version
20
20
  # see http://semver.org/
21
- VERSION = "0.3.1"
21
+ VERSION = "0.4.0"
22
22
 
23
23
  SERVER_API_VERSION = "2"
24
24
  end
data/lib/mortar/api.rb CHANGED
@@ -109,6 +109,12 @@ module Mortar
109
109
  end
110
110
  end
111
111
 
112
+ #Check if we got a redirect and treat it as an error.
113
+ if response.body.include? "redirect"
114
+ redirect_error = Mortar::API::Errors::Redirect.new(response.body["error"], response.body)
115
+ raise(redirect_error)
116
+ end
117
+
112
118
  # reset (non-persistent) connection
113
119
  @connection.reset
114
120
 
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright 2012 Mortar Data Inc.
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, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "spec_helper"
18
+ require "mortar/api"
19
+
20
+
21
+ describe Mortar::API do
22
+
23
+ before(:each) do
24
+ @api = Mortar::API.new
25
+ end
26
+
27
+ after(:each) do
28
+ Excon.stubs.clear
29
+ end
30
+
31
+ context "redirect" do
32
+ it "posts an illustrate and gets a redirect" do
33
+ illustrate_id = "7b93e4d3ab034188a0c2be418d3d24ed"
34
+ project_name = "my_project"
35
+ pigscript_name = "my_pigscript"
36
+ pigscript_alias = "my_alias"
37
+ skip_pruning = false
38
+ git_ref = "e20395b8b06fbf52e86665b0660209673f311d1a"
39
+ parameters = {"key" => "value"}
40
+ body = Mortar::API::OkJson.encode({"project_name" => project_name,
41
+ "pigscript_name" => pigscript_name,
42
+ "alias" => pigscript_alias,
43
+ "skip_pruning" => skip_pruning,
44
+ "git_ref" => git_ref,
45
+ "parameters" => parameters})
46
+ redirect_url = "some_redirect_url"
47
+ redirect_message = "some_redirect_message"
48
+ Excon.stub({:method => :post, :path => "/v2/illustrates", :body => body}) do |params|
49
+ {:body => Mortar::API::OkJson.encode({'redirect' => redirect_url, 'error' => redirect_message}), :status => 200}
50
+ end
51
+ expect {@api.post_illustrate(project_name, pigscript_name, pigscript_alias, skip_pruning, git_ref, :parameters => parameters)}.to raise_error(Mortar::API::Errors::Redirect)
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortar-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-25 00:00:00.000000000 Z
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -125,6 +125,7 @@ files:
125
125
  - spec/mortar/api/basicauth_spec.rb
126
126
  - spec/mortar/api/clusters_spec.rb
127
127
  - spec/mortar/api/describe_spec.rb
128
+ - spec/mortar/api/errors_spec.rb
128
129
  - spec/mortar/api/fixtures_spec.rb
129
130
  - spec/mortar/api/illustrate_spec.rb
130
131
  - spec/mortar/api/jobs_spec.rb
@@ -164,6 +165,7 @@ test_files:
164
165
  - spec/mortar/api/basicauth_spec.rb
165
166
  - spec/mortar/api/clusters_spec.rb
166
167
  - spec/mortar/api/describe_spec.rb
168
+ - spec/mortar/api/errors_spec.rb
167
169
  - spec/mortar/api/fixtures_spec.rb
168
170
  - spec/mortar/api/illustrate_spec.rb
169
171
  - spec/mortar/api/jobs_spec.rb