spore-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e1a7ba43152c6e2d5a33dbbda8f8ecac32082b6
4
+ data.tar.gz: a2174dc979121e76623c29624001ce3827fc3bc2
5
+ SHA512:
6
+ metadata.gz: 024c95944c74bc4b41aa3c4a487c3cd46049e14711aafcd759a223f434a26440483f08bdcd07b0882c2c09bbf25dceffe78376a95261156c6e7a851a323dc0bb
7
+ data.tar.gz: 9eae761ee9b301b6e4dc4de791ad83d349a029f63cd67a6ae4cf1b46c6c0f3467cacbc735f932599387f6eceff3b99fb8d051ee28f5d8475e3d4a76e660898e9
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Teleborder, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,2 @@
1
+ # spore-api-ruby
2
+ Implmentation of the Spore API in ruby
@@ -0,0 +1,4 @@
1
+ desc "Open an irb session preloaded with this library"
2
+ task :console do
3
+ sh "irb -rubygems -I lib -r spore.rb"
4
+ end
@@ -0,0 +1 @@
1
+ require 'spore/client'
@@ -0,0 +1,92 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require 'spore/version'
5
+ require 'spore/client/users'
6
+ require 'spore/client/cells'
7
+ require 'spore/client/apps'
8
+ require 'spore/client/deployments'
9
+ require 'spore/client/memberships'
10
+
11
+ module Spore
12
+
13
+ class Client
14
+ include Spore::Client::Users
15
+ include Spore::Client::Cells
16
+ include Spore::Client::Apps
17
+ include Spore::Client::Deployments
18
+ include Spore::Client::Memberships
19
+
20
+ attr_reader :email
21
+ attr_reader :name
22
+ attr_reader :key
23
+ attr_reader :current_user
24
+
25
+ attr_accessor :api_endpoint
26
+ attr_accessor :user_agent
27
+ attr_accessor :middleware
28
+
29
+ def initialize(email = nil, key = nil)
30
+ @email = email
31
+ @key = key
32
+ end
33
+
34
+ def api_endpoint
35
+ @api_endpoint ||= 'http://pod.spore.sh/'
36
+ end
37
+
38
+ def user_agent
39
+ @user_agent ||= "Spore #{Spore::Version.to_s}"
40
+ end
41
+
42
+ def middleware
43
+ @middleware ||= Faraday::RackBuilder.new do |builder|
44
+ builder.use Faraday::Request::UrlEncoded
45
+ builder.use Spore::Response::RaiseError
46
+ builder.use Spore::Response::ParseJSON
47
+ builder.adapter Faraday.default_adapter
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def get(path, params = nil)
54
+ request(:get, path, params)
55
+ end
56
+
57
+ def post(path, params, options = nil)
58
+ request(:post, path, params, options)
59
+ end
60
+
61
+ def patch(path, params, options = nil)
62
+ request(:patch, path, params, options)
63
+ end
64
+
65
+ def delete(path, params = nil)
66
+ request(:delete, path, params)
67
+ end
68
+
69
+ def request(method, path, parameters = {}, options = nil)
70
+ response = connection.send(method.to_sym, path, parameters) do |req|
71
+ req.headers["Prefer"] = 'respond-async' if options && options[:async]
72
+ end
73
+ if error = response.body["error"]
74
+ raise error["message"]
75
+ end
76
+ response
77
+ rescue Faraday::Error::ClientError
78
+ raise Spore::RequestError
79
+ end
80
+
81
+ def connection
82
+ Faraday.new(api_endpoint) do |conn|
83
+ conn.basic_auth(email, key) if signed_in?
84
+ conn.request :url_encoded
85
+ conn.response :json, :content_type => /\bjson$/
86
+ conn.adapter Faraday.default_adapter
87
+ conn.headers[:user_agent] = user_agent
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,31 @@
1
+ module Spore
2
+ class Client
3
+ module Apps
4
+ def list_apps
5
+ response = get "/apps"
6
+ response.body["apps"]
7
+ end
8
+
9
+ def get_app(app_id)
10
+ response = get "/apps/#{app_id}"
11
+ response.body["app"]
12
+ end
13
+
14
+ def create_app(app_id = nil, name)
15
+ app_id = SecureRandom.uuid if app_id.nil?
16
+ response = post "/apps", { id: app_id, name: name }, { async: true }
17
+ response.body["app"]
18
+ end
19
+
20
+ def change_app_owner(app_id, email)
21
+ response = patch "apps/#{app_id}", { email: email }, { async: true }
22
+ response.body["app"]
23
+ end
24
+
25
+ def change_app_name(app_id, name)
26
+ response = patch "apps/#{app_id}", { name: name }
27
+ response.body["app"]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module Spore
2
+ class Client
3
+ module Cells
4
+ def create_cell(app_id, environment, key, value, cell_id = nil)
5
+ cell_id = SecureRandom.uuid if cell_id.nil?
6
+ path = "/apps/#{app_id}/envs/#{environment}/cells"
7
+ response = post path, { id: cell_id, key: key, value: value }, { async: true }
8
+ response.body["cell"]
9
+ end
10
+
11
+ def get_cell(app_id, environment, cell_id)
12
+ path = "/apps/#{app_id}/envs/#{environment}/cells/#{cell_id}"
13
+ response = get path
14
+ response.body["cell"]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Spore
2
+ class Client
3
+ module Deployments
4
+ def list_deployments(app_id, env)
5
+ response = get "/apps/#{app_id}/envs/#{env}/deployments"
6
+ response.body["deployments"]
7
+ end
8
+
9
+ def create_deployment(app_id, env, name)
10
+ response = post "/apps/#{app_id}/envs/#{env}/deployments", { name: name }
11
+ response.body["deployment"]
12
+ end
13
+
14
+ def destroy_deployment(app_id, env, name)
15
+ response = delete "/apps/#{app_id}/envs/#{env}/deployments/#{name}"
16
+ response.body["deployment"]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Spore
2
+ class Client
3
+ module Memberships
4
+ def list_memberships(app_id, env)
5
+ response = get "/apps/#{app_id}/envs/#{env}/memberships"
6
+ response.body["memberships"]
7
+ end
8
+
9
+ def grant_membership(app_id, env, email)
10
+ response = post "/apps/#{app_id}/envs/#{env}/memberships", { email: email }
11
+ response.body["membership"]
12
+ end
13
+
14
+ def accept_membership(token)
15
+ response = get "/invites/#{token}"
16
+ app_id = response.body["invite"]["app"]
17
+ env = response.body["invite"]["environment"]
18
+ email = response.body["invite"]["email"]
19
+ response = patch "/apps/#{app_id}/envs/#{env}/memberships/#{email}", { token: token }
20
+ response.body["membership"]
21
+ end
22
+
23
+ def revoke_membership(app_id, env, email)
24
+ response = delete "/apps/#{app_id}/envs/#{env}/memberships/#{email}"
25
+ response.body["membership"]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Spore
2
+ class Client
3
+ module Users
4
+ def signup(email, password)
5
+ response = post "/users", { email: email, password: password }
6
+ @verified = response.body["user"]["verified"]
7
+ login(email, password)
8
+ self
9
+ end
10
+
11
+ def login(email, password)
12
+ response = post "/users/#{email}/keys", { password: password }
13
+ @email = email
14
+ @key = response.body["key"]
15
+ self
16
+ end
17
+
18
+ def verify(token)
19
+ response = patch "/users/#{@email}", { token: token }
20
+ @verified = response.body["user"]["verified"]
21
+ self
22
+ end
23
+
24
+ def signed_in?
25
+ !email.nil? && !key.nil?
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Spore
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+
7
+ class << self
8
+ def to_s
9
+ [MAJOR, MINOR, PATCH].join('.')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spore/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spore-api"
8
+ spec.version = Spore::Version
9
+ spec.authors = ["Shayan Guha"]
10
+ spec.email = ["shayan@teleborder.com"]
11
+ spec.description = "A simple Spore API library."
12
+ spec.summary = "A simple Spore API library."
13
+ spec.homepage = "http://spore.sh/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = %w(LICENSE README.md Rakefile spore-api.gemspec)
17
+ spec.files += Dir.glob("lib/**/*.rb")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'faraday', "~> 0.9"
23
+ spec.add_dependency 'faraday_middleware', "~> 0.9"
24
+ spec.add_dependency 'htmlentities', "~> 4.3"
25
+ spec.add_dependency 'multi_json', '~> 1.8'
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spore-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shayan Guha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: htmlentities
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: A simple Spore API library.
70
+ email:
71
+ - shayan@teleborder.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/spore.rb
80
+ - lib/spore/client.rb
81
+ - lib/spore/client/apps.rb
82
+ - lib/spore/client/cells.rb
83
+ - lib/spore/client/deployments.rb
84
+ - lib/spore/client/memberships.rb
85
+ - lib/spore/client/users.rb
86
+ - lib/spore/version.rb
87
+ - spore-api.gemspec
88
+ homepage: http://spore.sh/
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A simple Spore API library.
112
+ test_files: []
113
+ has_rdoc: