Class: EyServicesFake::MockingBirdService

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_services_fake/mocking_bird_service.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.service_account_cancel_handlerObject

Returns the value of attribute service_account_cancel_handler.



73
74
75
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 73

def 
  @service_account_cancel_handler
end

.service_account_creation_handlerObject

Returns the value of attribute service_account_creation_handler.



70
71
72
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 70

def 
  @service_account_creation_handler
end

.service_deprovisioning_handlerObject

Returns the value of attribute service_deprovisioning_handler.



72
73
74
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 72

def service_deprovisioning_handler
  @service_deprovisioning_handler
end

.service_provisioning_handlerObject

Returns the value of attribute service_provisioning_handler.



71
72
73
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 71

def service_provisioning_handler
  @service_provisioning_handler
end

Class Method Details

.account_sso_hook(params) ⇒ Object



150
151
152
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 150

def self.(params)
  #no-op
end

.base_urlObject



105
106
107
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 105

def self.base_url
  "http://mock.service/"
end

.implement_the_app(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 6

def self.implement_the_app(app)
  app.class_eval do
  enable :raise_errors
  disable :dump_errors
  disable :show_exceptions

  class << self
    attr_accessor :parent
  end
  def parent
    self.class.parent
  end

  delete '/api/1/some_provisioned_service' do
    content_type :json
    if parent.service_deprovisioning_handler
      instance_eval(&parent.service_deprovisioning_handler)
    else
      {}.to_json
    end
  end

  delete '/api/1/account/:account_id' do ||
    content_type :json
    if parent.
      instance_eval(&parent.)
    else
      {}.to_json
    end
  end

  post '/api/1/service_accounts_callback' do
    content_type :json
    if parent.
      instance_eval(&parent.)
    else
       = EY::ServicesAPI::ServiceAccountCreation.from_request(request.body.read)
      response_params = parent.(123)
      EY::ServicesAPI::ServiceAccountResponse.new(response_params).to_hash.to_json
    end
  end

  post '/api/1/account/:account_id/provisioned_services_callback' do ||
    content_type :json
    if parent.service_provisioning_handler
      instance_eval(&parent.service_provisioning_handler)
    else
      provisioned_service = EY::ServicesAPI::ProvisionedServiceCreation.from_request(request.body.read)
      standard_response_params = parent.service_provisioned_params
      EY::ServicesAPI::ProvisionedServiceResponse.new(parent.service_provisioned_params).to_hash.to_json
    end
  end

  get '/sso/account/:account_id' do ||
    parent.(params)
    "SSO Hello Service Account"
  end

  get '/sso/some_provisioned_service' do
    "SSO Hello Provisioned Service"
  end
  end
end

.registration_paramsObject



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 112

def self.registration_params
  {
    :name => "Mocking Bird",
    :label => "mocking_bird",
    :description => "a mock service",
    :service_accounts_url =>     "#{base_url}api/1/service_accounts_callback",
    :home_url =>                 "#{base_url}",
    :terms_and_conditions_url => "#{base_url}terms",
    :vars => ["some_var", "other_var"]
  }
end

.service_account_creation_params(account_id) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 127

def self.()
  {
    :provisioned_services_url => "#{base_url}api/1/account/#{}/provisioned_services_callback",
    :url => "#{base_url}api/1/account/#{}",
    :configuration_url => "#{base_url}sso/account/#{}",
    :configuration_required => false,
    :message => EY::ServicesAPI::Message.new(:message_type => "status", :subject => "some messages"),
  }
end

.service_provisioned_paramsObject



140
141
142
143
144
145
146
147
148
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 140

def self.service_provisioned_params
  {
    :vars => {"some_var" => "value", "other_var" => "blah"},
    :configuration_url => "#{base_url}sso/some_provisioned_service",
    :configuration_required => false,
    :url => "#{base_url}api/1/some_provisioned_service",
    :message => EY::ServicesAPI::Message.new(:message_type => "status", :subject => "some provisioned service messages")
  }
end

Instance Method Details

#appObject



90
91
92
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 90

def app
  @app ||= make_app
end

#base_urlObject



102
103
104
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 102

def base_url
  self.class.base_url
end

#make_appObject



83
84
85
86
87
88
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 83

def make_app
  app = Class.new(Sinatra::Base)
  self.class.implement_the_app(app)
  app.parent = self.class
  app
end

#register_service(registration_url) ⇒ Object



154
155
156
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 154

def register_service(registration_url)
  EY::ServicesAPI.connection.register_service(registration_url, self.class.registration_params)
end

#registration_paramsObject



109
110
111
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 109

def registration_params
  self.class.registration_params
end

#reset!Object



76
77
78
79
80
81
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 76

def reset!
  self.class. = nil
  self.class.service_provisioning_handler = nil
  self.class.service_deprovisioning_handler = nil
  self.class. = nil
end

#send_invoice(invoices_url, total_amount_cent, line_item_description) ⇒ Object



163
164
165
166
167
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 163

def send_invoice(invoices_url, total_amount_cent, line_item_description)
  invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => total_amount_cent,
                                         :line_item_description => line_item_description)
  EY::ServicesAPI.connection.send_invoice(invoices_url, invoice)
end

#send_message(message_url, message_type, message_subject, message_body) ⇒ Object



158
159
160
161
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 158

def send_message(message_url, message_type, message_subject, message_body)
  message = EY::ServicesAPI::Message.new(:message_type => message_type, :subject => message_subject, :body => message_body)
  EY::ServicesAPI.connection.send_message(message_url, message)
end

#service_account_creation_params(account_id) ⇒ Object



124
125
126
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 124

def ()
  self.class.()
end

#service_provisioned_paramsObject



137
138
139
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 137

def service_provisioned_params
  self.class.service_provisioned_params
end

#setup(auth_id, auth_key, base_url = nil, backend = nil) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/ey_services_fake/mocking_bird_service.rb', line 94

def setup(auth_id, auth_key, base_url = nil, backend = nil)
  require 'ey_services_api'
  connection = EY::ServicesAPI.setup!(:auth_id => auth_id, :auth_key => auth_key)
  if backend
    connection.backend = backend
  end
end