Class: Hyperion

Inherits:
Object
  • Object
show all
Extended by:
Formats, Headers, Logger, TestFrameworkHooks
Includes:
Formats, Headers, Logger
Defined in:
lib/hyperion/formats.rb,
lib/hyperion/headers.rb,
lib/hyperion/aux/util.rb,
lib/hyperion/hyperion.rb,
lib/hyperion/aux/typho.rb,
lib/hyperion/requestor.rb,
lib/hyperion_test/fake.rb,
lib/hyperion/aux/logger.rb,
lib/hyperion/aux/version.rb,
lib/hyperion_test/fake_server.rb,
lib/hyperion_test/fake_server/types.rb,
lib/hyperion_test/fake_server/config.rb,
lib/hyperion_test/fake_server/dispatcher.rb,
lib/hyperion/result_handling/dispatch_dsl.rb,
lib/hyperion/result_handling/result_maker.rb,
lib/hyperion/result_handling/dispatching_hyperion_result.rb

Defined Under Namespace

Modules: DispatchDsl, Formats, Headers, Logger, Requestor Classes: Config, DispatchingHyperionResult, FakeServer, ResultMaker, Typho, Util

Constant Summary collapse

VERSION =
'0.1.6'

Constants included from Headers

Headers::ContentTypes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

log_stub, logger, with_request_logging

Methods included from TestFrameworkHooks

can_hook_teardown?, hook_teardown, rspec_after_example_hooks, rspec_hooks, teardown_registered?

Methods included from Headers

content_type_for, format_for, route_headers, short_mimetype

Methods included from Formats

get_from, read, write

Constructor Details

#initialize(route) ⇒ Hyperion

Returns a new instance of Hyperion.



27
28
29
# File 'lib/hyperion/hyperion.rb', line 27

def initialize(route)
  @route = route
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:

  • (config)


43
44
45
# File 'lib/hyperion/hyperion.rb', line 43

def self.configure
  yield(config)
end

.fake(base_uri, &routes) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/hyperion_test/fake.rb', line 18

def fake(base_uri, &routes)
  base_uri = normalized_base(base_uri)
  if !@running
    hook_teardown if can_hook_teardown? && !teardown_registered?
    @running = true
  end
  servers[base_uri].configure(&routes)
end

.request(route, body = nil, additional_headers = {}) {|result| ... } ⇒ HyperionResult, Object

If a block is provided, returns the block’s return value; otherwise, returns the result.

Parameters:

  • route (RestRoute)
  • body (String) (defaults to: nil)

    the body to send with POST or PUT

  • additional_headers (Hash) (defaults to: {})

    headers to send in addition to the ones already determined by the route. Example: {‘User-Agent’ => ‘Mozilla/5.0’}

Yields:

  • (result)

    yields the result if a block is provided

Yield Parameters:

Returns:

  • (HyperionResult, Object)

    If a block is provided, returns the block’s return value; otherwise, returns the result.



22
23
24
# File 'lib/hyperion/hyperion.rb', line 22

def self.request(route, body=nil, additional_headers={}, &block)
  self.new(route).request(body, additional_headers, &block)
end

.teardownObject



27
28
29
30
31
# File 'lib/hyperion_test/fake.rb', line 27

def teardown
  servers.values.each(&:teardown)
  servers.clear
  @running = false
end

Instance Method Details

#request(body = nil, additional_headers = {}, &dispatch) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/hyperion/hyperion.rb', line 32

def request(body=nil, additional_headers={}, &dispatch)
  uri = transform_uri(route.uri).to_s
  with_request_logging(route, uri, route_headers(route)) do
    typho_result = Typho.request(uri,
                                 method: route.method,
                                 headers: build_headers(additional_headers),
                                 body: write(body, route.payload_descriptor))
    hyperion_result_for(typho_result, dispatch)
  end
end