ey_services_api 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/ey_services_api.gemspec +2 -1
- data/lib/ey_services_api.rb +2 -0
- data/lib/ey_services_api/integration.rb +57 -0
- data/lib/ey_services_api/integration/server.rb +78 -0
- data/lib/ey_services_api/version.rb +1 -1
- data/script/ci +1 -0
- metadata +23 -7
data/ey_services_api.gemspec
CHANGED
@@ -17,8 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
|
-
|
20
|
+
|
21
21
|
s.add_development_dependency 'rspec'
|
22
|
+
s.add_dependency "sinatra"
|
22
23
|
s.add_dependency 'json'
|
23
24
|
s.add_dependency 'ey_api_hmac', ">= 0.3.0"
|
24
25
|
end
|
data/lib/ey_services_api.rb
CHANGED
@@ -8,6 +8,8 @@ require "ey_services_api/service_account_creation"
|
|
8
8
|
require "ey_services_api/service_account_response"
|
9
9
|
require "ey_services_api/provisioned_service_creation"
|
10
10
|
require "ey_services_api/provisioned_service_response"
|
11
|
+
require "ey_services_api/integration"
|
12
|
+
require "ey_services_api/integration/server"
|
11
13
|
|
12
14
|
module EY
|
13
15
|
module ServicesAPI
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module EY
|
2
|
+
module ServicesAPI
|
3
|
+
class Integration
|
4
|
+
|
5
|
+
def self.register_service(registration_url, service_url)
|
6
|
+
create_service(service_registration_params(service_url), registration_url)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.server
|
10
|
+
Server
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.mapper=(mapper)
|
14
|
+
@mapper = mapper
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.mapper
|
18
|
+
@mapper
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.service_registration_params(base_url)
|
24
|
+
{
|
25
|
+
:name => fetch_from_description(:name),
|
26
|
+
:label => fetch_from_description(:label),
|
27
|
+
:service_accounts_url => "#{base_url + mapper.api_root}/service_accounts",
|
28
|
+
:home_url => fetch_from_description(:home_url),
|
29
|
+
:terms_and_conditions_url => fetch_from_description(:terms_and_conditions_url),
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.fetch_from_description(thing)
|
34
|
+
mapper.description[thing] or raise "Expected 'description' to define a #{thing} for your service"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create_service(registration_params, service_registration_url)
|
38
|
+
remote_service = connection.register_service(service_registration_url, registration_params)
|
39
|
+
mapper.save_service_url(remote_service.url)
|
40
|
+
remote_service
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.connection
|
44
|
+
unless EY::ServicesAPI.setup?
|
45
|
+
EY::ServicesAPI.setup!(mapper.api_creds)
|
46
|
+
end
|
47
|
+
EY::ServicesAPI.connection
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.test_setup(auth_id, auth_key, tresfiestas_url, tresfiestas_rackapp)
|
51
|
+
mapper.save_api_creds(auth_id, auth_key)
|
52
|
+
connection.backend = tresfiestas_rackapp
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module EY
|
4
|
+
module ServicesAPI
|
5
|
+
class Integration
|
6
|
+
class Server < Sinatra::Base
|
7
|
+
|
8
|
+
enable :raise_errors
|
9
|
+
disable :dump_errors
|
10
|
+
disable :show_exceptions
|
11
|
+
|
12
|
+
use EY::ApiHMAC::ApiAuth::LookupServer do |env, auth_id|
|
13
|
+
Integration.mapper.api_creds && (Integration.mapper.api_creds[:auth_id] == auth_id) && Integration.mapper.api_creds[:auth_key]
|
14
|
+
end
|
15
|
+
|
16
|
+
post "/service_accounts" do
|
17
|
+
request_body = request.body.read
|
18
|
+
service_account = EY::ServicesAPI::ServiceAccountCreation.from_request(request_body)
|
19
|
+
created = mapper.service_account_create(service_account)
|
20
|
+
response_params = {
|
21
|
+
:configuration_required => false,
|
22
|
+
:configuration_url => nil,
|
23
|
+
:provisioned_services_url => "#{api_base_url}/service_accounts/#{created[:id]}/provisioned_services",
|
24
|
+
:url => "#{api_base_url}/service_accounts/#{created[:id]}"
|
25
|
+
}
|
26
|
+
response = EY::ServicesAPI::ServiceAccountResponse.new(response_params)
|
27
|
+
content_type :json
|
28
|
+
headers 'Location' => response.url
|
29
|
+
response.to_hash.to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
post "/service_accounts/:service_account_id/provisioned_services" do |service_account_id|
|
33
|
+
request_body = request.body.read
|
34
|
+
provisioned_service = EY::ServicesAPI::ProvisionedServiceCreation.from_request(request_body)
|
35
|
+
created = mapper.provisioned_service_create(service_account_id, provisioned_service)
|
36
|
+
response_params = {
|
37
|
+
:configuration_required => false,
|
38
|
+
:configuration_url => "#{true_base_url}#{created[:configuration_url]}",
|
39
|
+
:vars => created[:vars],
|
40
|
+
:url => "#{api_base_url}/service_accounts/#{service_account_id}/provisioned_services/#{created[:id]}",
|
41
|
+
}
|
42
|
+
response = EY::ServicesAPI::ProvisionedServiceResponse.new(response_params)
|
43
|
+
content_type :json
|
44
|
+
headers 'Location' => response.url
|
45
|
+
response.to_hash.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
delete "/service_accounts/:service_account_id" do |service_account_id|
|
49
|
+
mapper.service_account_cancel(service_account_id)
|
50
|
+
content_type :json
|
51
|
+
{}.to_json
|
52
|
+
end
|
53
|
+
|
54
|
+
delete "/service_accounts/:service_account_id/provisioned_services/:provisioned_service_id" do |service_account_id, provisioned_service_id|
|
55
|
+
mapper.provisioned_service_cancel(service_account_id, provisioned_service_id)
|
56
|
+
content_type :json
|
57
|
+
{}.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def mapper
|
63
|
+
Integration.mapper
|
64
|
+
end
|
65
|
+
|
66
|
+
def api_base_url
|
67
|
+
true_base_url + mapper.api_root
|
68
|
+
end
|
69
|
+
|
70
|
+
def true_base_url
|
71
|
+
uri = URI.parse(request.url)
|
72
|
+
uri.to_s.gsub(uri.request_uri, '')
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/script/ci
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ey_services_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 15
|
10
|
+
version: 0.3.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jacob & Thorben & David & mkb & Josh & Others
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-08-
|
18
|
+
date: 2012-08-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
type: :development
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: sinatra
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
@@ -46,9 +46,23 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: json
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ey_api_hmac
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
66
|
none: false
|
53
67
|
requirements:
|
54
68
|
- - ">="
|
@@ -60,7 +74,7 @@ dependencies:
|
|
60
74
|
- 0
|
61
75
|
version: 0.3.0
|
62
76
|
type: :runtime
|
63
|
-
version_requirements: *
|
77
|
+
version_requirements: *id004
|
64
78
|
description: API for Partner Services (talks to services.engineyard.com)
|
65
79
|
email:
|
66
80
|
- jacob@engineyard.com
|
@@ -86,6 +100,8 @@ files:
|
|
86
100
|
- lib/ey_services_api/api_struct.rb
|
87
101
|
- lib/ey_services_api/connection.rb
|
88
102
|
- lib/ey_services_api/external_test_helper.rb
|
103
|
+
- lib/ey_services_api/integration.rb
|
104
|
+
- lib/ey_services_api/integration/server.rb
|
89
105
|
- lib/ey_services_api/invoice.rb
|
90
106
|
- lib/ey_services_api/message.rb
|
91
107
|
- lib/ey_services_api/provisioned_service_creation.rb
|