mortar-api-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
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
+ describe Mortar::API do
21
+
22
+ before(:each) do
23
+ @api = Mortar::API.new
24
+ end
25
+
26
+ after(:each) do
27
+ Excon.stubs.clear
28
+ end
29
+
30
+ context "user" do
31
+ it "gets logged in user" do
32
+ user_id = "b480950f1fbf4d8a96235038d6badb7d"
33
+ email = "fake@nowhere.com"
34
+ Excon.stub({:method => :get, :path => "/v2/user"}) do |params|
35
+ {:body => Mortar::API::OkJson.encode({"user_id" => user_id, "user_email" => email}), :status => 200}
36
+ end
37
+ response = @api.get_user()
38
+ response.body["user_id"].should == user_id
39
+ response.body["user_email"].should == email
40
+ end
41
+
42
+ it "errors when no user is logged in" do
43
+ Excon.stub({:method => :get, :path => "/v2/user"}) do |params|
44
+ {:status => 401}
45
+ end
46
+ expect {@api.get_user()}.to raise_error(Mortar::API::Errors::Unauthorized)
47
+ end
48
+
49
+ it "updates user successfully" do
50
+ user_id = "somebiglongid"
51
+ github_username = "some_github_name"
52
+ task_id = "some1task2id"
53
+
54
+ body = Mortar::API::OkJson.encode({"github_username" => github_username})
55
+ Excon.stub({:method => :put, :path => "/v2/user/#{user_id}", :body => body}) do |params|
56
+ {:body => Mortar::API::OkJson.encode({"task_id" => task_id}), :status => 200}
57
+ end
58
+
59
+ response = @api.update_user(user_id, {"github_username" => github_username})
60
+ response.body['task_id'].should == task_id
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,60 @@
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 "base64"
18
+ require "spec_helper"
19
+ require "mortar/api"
20
+
21
+
22
+ describe Mortar::API do
23
+
24
+ before(:each) do
25
+ @api = Mortar::API.new
26
+ end
27
+
28
+ after(:each) do
29
+ Excon.stubs.clear
30
+ end
31
+
32
+ context "validate" do
33
+ it "posts a validate" do
34
+ validate_id = "7b93e4d3ab034188a0c2be418d3d24ed"
35
+ project_name = "my_project"
36
+ pigscript_name = "my_pigscript"
37
+ git_ref = "e20395b8b06fbf52e86665b0660209673f311d1a"
38
+ parameters = {"key" => "value"}
39
+ body = Mortar::API::OkJson.encode({"project_name" => project_name,
40
+ "pigscript_name" => pigscript_name,
41
+ "git_ref" => git_ref,
42
+ "parameters" => parameters})
43
+ Excon.stub({:method => :post, :path => "/v2/validates", :body => body}) do |params|
44
+ {:body => Mortar::API::OkJson.encode({'validate_id' => validate_id}), :status => 200}
45
+ end
46
+ response = @api.post_validate(project_name, pigscript_name, git_ref, :parameters => parameters)
47
+ response.body['validate_id'].should == validate_id
48
+ end
49
+
50
+ it "gets a validate" do
51
+ validate_id = "7b93e4d3ab034188a0c2be418d3d24ed"
52
+ Excon.stub({:method => :get, :path => "/v2/validates/7b93e4d3ab034188a0c2be418d3d24ed"}) do |params|
53
+ {:body => Mortar::API::OkJson.encode({'validate_id' => validate_id, 'status' => Mortar::API::Validate::STATUS_PROGRESS}), :status => 200}
54
+ end
55
+ response = @api.get_validate(validate_id)
56
+ response.body['validate_id'].should == validate_id
57
+ response.body['status'].should == Mortar::API::Validate::STATUS_PROGRESS
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,44 @@
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 "base64"
18
+ require "spec_helper"
19
+ require "mortar/api"
20
+
21
+
22
+ describe Mortar::API do
23
+
24
+ include Mortar::API::BasicAuth
25
+
26
+ context "base methods" do
27
+ it "creates versioned API paths" do
28
+ api = Mortar::API.new
29
+ api.versioned_path("/illustrate/123").should == "/v2/illustrate/123"
30
+ api.versioned_path("illustrate/123").should == "/v2/illustrate/123"
31
+ end
32
+ end
33
+
34
+ context "api initialization" do
35
+ it "handles token auth properly" do
36
+ email = "nobody@nowhere.com"
37
+ api_key = "6db6Wm9ZUeCl0NVNdkhptksCh0T9i6bv1dYZXaKz"
38
+ api = Mortar::API.new(:user => email, :api_key => api_key)
39
+ authorization = api.connection.connection[:headers]['Authorization']
40
+ authorization.nil?.should be_false
41
+ authorization.should == basic_auth_authorization_header(email, api_key)
42
+ end
43
+ end
44
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
@@ -0,0 +1,29 @@
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 "rubygems"
18
+ require "excon"
19
+ Excon.defaults[:mock] = true
20
+
21
+ require "rspec"
22
+ require "rr"
23
+
24
+ RSpec.configure do |config|
25
+ config.mock_with :rr
26
+ config.color_enabled = true
27
+ config.order = 'rand'
28
+ config.after { RR.reset }
29
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mortar-api-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Mortar Data
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: excon
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 43
29
+ segments:
30
+ - 0
31
+ - 15
32
+ - 4
33
+ version: 0.15.4
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: gem-release
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rr
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: Client for Mortar API.
93
+ email: support@mortardata.com
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files: []
99
+
100
+ files:
101
+ - .gitignore
102
+ - .rvmrc
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE
106
+ - NOTICE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/mortar-api-ruby.rb
110
+ - lib/mortar/api.rb
111
+ - lib/mortar/api/basicauth.rb
112
+ - lib/mortar/api/clusters.rb
113
+ - lib/mortar/api/describe.rb
114
+ - lib/mortar/api/errors.rb
115
+ - lib/mortar/api/illustrate.rb
116
+ - lib/mortar/api/jobs.rb
117
+ - lib/mortar/api/login.rb
118
+ - lib/mortar/api/projects.rb
119
+ - lib/mortar/api/tasks.rb
120
+ - lib/mortar/api/user.rb
121
+ - lib/mortar/api/validate.rb
122
+ - lib/mortar/api/vendor/okjson.rb
123
+ - lib/mortar/api/version.rb
124
+ - mortar-api-ruby.gemspec
125
+ - spec/mortar/api/basicauth_spec.rb
126
+ - spec/mortar/api/clusters_spec.rb
127
+ - spec/mortar/api/describe_spec.rb
128
+ - spec/mortar/api/illustrate_spec.rb
129
+ - spec/mortar/api/jobs_spec.rb
130
+ - spec/mortar/api/login_spec.rb
131
+ - spec/mortar/api/projects_spec.rb
132
+ - spec/mortar/api/tasks_spec.rb
133
+ - spec/mortar/api/user_spec.rb
134
+ - spec/mortar/api/validate_spec.rb
135
+ - spec/mortar/api_spec.rb
136
+ - spec/spec.opts
137
+ - spec/spec_helper.rb
138
+ homepage: http://mortardata.com/
139
+ licenses: []
140
+
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 57
152
+ segments:
153
+ - 1
154
+ - 8
155
+ - 7
156
+ version: 1.8.7
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ requirements: []
167
+
168
+ rubyforge_project:
169
+ rubygems_version: 1.8.24
170
+ signing_key:
171
+ specification_version: 3
172
+ summary: Client for Mortar API
173
+ test_files:
174
+ - spec/mortar/api/basicauth_spec.rb
175
+ - spec/mortar/api/clusters_spec.rb
176
+ - spec/mortar/api/describe_spec.rb
177
+ - spec/mortar/api/illustrate_spec.rb
178
+ - spec/mortar/api/jobs_spec.rb
179
+ - spec/mortar/api/login_spec.rb
180
+ - spec/mortar/api/projects_spec.rb
181
+ - spec/mortar/api/tasks_spec.rb
182
+ - spec/mortar/api/user_spec.rb
183
+ - spec/mortar/api/validate_spec.rb
184
+ - spec/mortar/api_spec.rb
185
+ - spec/spec.opts
186
+ - spec/spec_helper.rb