pact_broker 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -2
- data/Gemfile.lock +12 -21
- data/config.ru +2 -1
- data/db/migrations/05_add_order_column_to_version.rb +7 -0
- data/db/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api.rb +23 -11
- data/lib/pact_broker/api/representors.rb +4 -1
- data/lib/pact_broker/api/representors/pact_broker_urls.rb +8 -0
- data/lib/pact_broker/api/representors/pact_collection_representor.rb +34 -0
- data/lib/pact_broker/api/representors/pact_pacticipant_representor.rb +27 -0
- data/lib/pact_broker/api/representors/pact_representor.rb +27 -0
- data/lib/pact_broker/api/representors/pacticipant_collection_representor.rb +20 -0
- data/lib/pact_broker/api/representors/pacticipant_empty_collection_representor.rb +33 -0
- data/lib/pact_broker/api/representors/representable_pact.rb +19 -0
- data/lib/pact_broker/api/representors/version_representor.rb +1 -0
- data/lib/pact_broker/models/order_versions.rb +33 -0
- data/lib/pact_broker/models/pact.rb +7 -2
- data/lib/pact_broker/models/pacticipant.rb +3 -1
- data/lib/pact_broker/models/version.rb +7 -1
- data/lib/pact_broker/repositories/pact_repository.rb +26 -5
- data/lib/pact_broker/resources/json_resource.rb +37 -0
- data/lib/pact_broker/resources/latest_pact.rb +41 -0
- data/lib/pact_broker/resources/latest_pacts.rb +49 -0
- data/lib/pact_broker/resources/pact.rb +49 -0
- data/lib/pact_broker/resources/pacticipant.rb +80 -0
- data/lib/pact_broker/resources/pacticipants.rb +41 -0
- data/lib/pact_broker/services/pact_service.rb +11 -9
- data/lib/pact_broker/version.rb +1 -1
- data/pact_broker.gemspec +2 -3
- data/spec/lib/pact_broker/api/representors/pact_collection_representor_spec.rb +23 -0
- data/spec/lib/pact_broker/api/representors/representable_pact_spec.rb +29 -0
- data/spec/lib/pact_broker/models/order_versions_spec.rb +23 -0
- data/spec/lib/pact_broker/repositories/pact_repository_spec.rb +39 -0
- data/spec/service_consumers/pact_helper.rb +2 -19
- data/spec/service_consumers/provider_states_for_pact_broker_client.rb +1 -48
- data/spec/spec_helper.rb +19 -0
- data/spec/support/provider_state_builder.rb +91 -0
- metadata +32 -29
- data/lib/pact_broker/api/base_api.rb +0 -40
- data/lib/pact_broker/api/index_api.rb +0 -23
- data/lib/pact_broker/api/pact_api.rb +0 -33
- data/lib/pact_broker/api/pacticipant_api.rb +0 -54
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'pact_broker/logging'
|
2
|
-
require 'pact_broker/repositories'
|
3
|
-
require 'sequel'
|
4
|
-
require 'sinatra'
|
5
|
-
require 'sinatra/json'
|
6
|
-
require 'sinatra/namespace'
|
7
|
-
require 'sinatra/param'
|
8
|
-
require 'pact_broker/models'
|
9
|
-
require 'pact_broker/services'
|
10
|
-
|
11
|
-
module PactBroker
|
12
|
-
|
13
|
-
module Api
|
14
|
-
|
15
|
-
class BaseApi < Sinatra::Base
|
16
|
-
|
17
|
-
helpers do
|
18
|
-
include PactBroker::Logging
|
19
|
-
include PactBroker::Services
|
20
|
-
end
|
21
|
-
|
22
|
-
set :raise_errors, false
|
23
|
-
set :show_exceptions, false
|
24
|
-
|
25
|
-
|
26
|
-
error do
|
27
|
-
e = env['sinatra.error']
|
28
|
-
logger.error e
|
29
|
-
content_type :json
|
30
|
-
status 500
|
31
|
-
{:message => e.message, :backtrace => e.backtrace }.to_json
|
32
|
-
end
|
33
|
-
|
34
|
-
helpers Sinatra::JSON
|
35
|
-
helpers Sinatra::Param
|
36
|
-
register Sinatra::Namespace
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'pact_broker/logging'
|
3
|
-
|
4
|
-
module PactBroker
|
5
|
-
module Api
|
6
|
-
|
7
|
-
class IndexApi < Sinatra::Base
|
8
|
-
|
9
|
-
helpers do
|
10
|
-
include PactBroker::Logging
|
11
|
-
end
|
12
|
-
|
13
|
-
# content_type :html, 'text/html'
|
14
|
-
#content_type :json, 'application/json' # Grape seems to be upset if we specify HTML without JSON
|
15
|
-
|
16
|
-
#default_format :json
|
17
|
-
#desc 'rea-rels:links'
|
18
|
-
get '/' do
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative 'base_api'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
|
5
|
-
module Api
|
6
|
-
|
7
|
-
class PactApi < BaseApi
|
8
|
-
|
9
|
-
namespace '/pacticipants/:consumer/versions/:number/pacts' do
|
10
|
-
put '/:provider' do
|
11
|
-
pact, created = pact_service.create_or_update_pact(
|
12
|
-
provider: params[:provider],
|
13
|
-
consumer: params[:consumer],
|
14
|
-
number: params[:number],
|
15
|
-
json_content: request.body.read)
|
16
|
-
created ? status(201) : status(200)
|
17
|
-
end
|
18
|
-
|
19
|
-
get '/:provider' do
|
20
|
-
pact = nil
|
21
|
-
pact = pact_service.find_pact(consumer: params[:consumer], provider: params[:provider], number: params[:number])
|
22
|
-
if pact
|
23
|
-
status 200
|
24
|
-
headers 'X-Pact-Consumer-Version' => pact.consumer_version_number
|
25
|
-
json pact
|
26
|
-
else
|
27
|
-
status 404
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require_relative 'base_api'
|
2
|
-
require_relative 'representors'
|
3
|
-
|
4
|
-
module PactBroker
|
5
|
-
module Api
|
6
|
-
|
7
|
-
class PacticipantApi < BaseApi
|
8
|
-
|
9
|
-
get "/pacticipants" do
|
10
|
-
pacticipants = pacticipant_service.find_all_pacticipants
|
11
|
-
pacticipants.extend(Representors::PacticipantCollectionRepresenter)
|
12
|
-
content_type 'application/json+hal;charset=utf-8'
|
13
|
-
pacticipants.to_json
|
14
|
-
end
|
15
|
-
|
16
|
-
namespace '/pacticipants' do
|
17
|
-
|
18
|
-
get '/:name' do
|
19
|
-
pacticipant = pacticipant_service.find_pacticipant_by_name(params[:name])
|
20
|
-
if pacticipant
|
21
|
-
pacticipant.extend(Representors::PacticipantRepresenter)
|
22
|
-
content_type 'application/json+hal;charset=utf-8'
|
23
|
-
pacticipant.to_json
|
24
|
-
else
|
25
|
-
status 404
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
get '/:name/repository_url' do
|
30
|
-
repository_url = pacticipant_service.find_pacticipant_repository_url_by_pacticipant_name(params[:name])
|
31
|
-
if repository_url
|
32
|
-
content_type 'text/plain'
|
33
|
-
repository_url
|
34
|
-
else
|
35
|
-
status 404
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
patch '/:name' do
|
40
|
-
logger.info "Recieved request to patch #{params[:name]} with #{params}"
|
41
|
-
pacticipant, created = pacticipant_service.create_or_update_pacticipant(
|
42
|
-
name: params[:name],
|
43
|
-
repository_url: params[:repository_url]
|
44
|
-
)
|
45
|
-
created ? status(201) : status(200)
|
46
|
-
pacticipant.extend(Representors::PacticipantRepresenter)
|
47
|
-
content_type 'application/json+hal;charset=utf-8'
|
48
|
-
pacticipant.to_json
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|