#!/usr/bin/env ruby # Used to run virtual web service on localhost. This makes tests more reliable and faster $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'soaspec' require 'sinatra' require 'sinatra/basic_auth' require 'nokogiri' require 'erb' require 'json' require 'faker' set :port, 4999 # Used to test attributes get '/test_attribute' do Soaspec::TestServer::TestAttribute.note end # This is the one being hit by SOAP actions post '/BLZService' do Soaspec::TestServer::GetBank.response_for request end # This is returned when a query for the WSDL is made get '/BLZService' do [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl] end # Simulate retrieving an ouath token. Passed to '/invoices' post '/as/token.oauth2' do [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body) ] #Soaspec::TestServer::Invoices.oauth_headers, ]# JSON.generate(Soaspec::TestServer::Invoices.oauth_body)] end get '/invoice/:id' do |id| JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION']) end authorize do |username, password| username == 'admin' && password == 'secret' end protect do get '/basic_secrets' do 'Secret data' end end # Used for testing storage of data post '/test/puppy' do request_hash = JSON.parse(request.body.string) id = Soaspec::TestServer::PuppyService.new_id Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name'] Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c'] response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } } JSON.generate response_hash end # Used for testing retrieving storage of data get '/test/puppy/:id' do |id| result = Soaspec::TestServer::PuppyService.data[id.to_i] JSON.generate result end patch '/test/puppy/:id' do |id| request_hash = JSON.parse(request.body.string) Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name'] response_hash = { result: { Status: 'updated', With: request_hash['Name'] } } JSON.generate response_hash end