Class: Apiture::RequestContext

Inherits:
Object
  • Object
show all
Includes:
Utils::Inflections
Defined in:
lib/apiture/request_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Inflections

acronym_regex, acronyms, #camelize, #constantize, #underscore

Constructor Details

#initialize(options, group, endpoint, attributes) ⇒ RequestContext

Returns a new instance of RequestContext.



20
21
22
# File 'lib/apiture/request_context.rb', line 20

def initialize(options, group, endpoint, attributes)
  @options, @group, @endpoint, @attributes = options, group, endpoint, attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18
19
20
# File 'lib/apiture/request_context.rb', line 18

def attributes
  @attributes
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



18
19
20
# File 'lib/apiture/request_context.rb', line 18

def endpoint
  @endpoint
end

#groupObject (readonly)

Returns the value of attribute group.



18
19
20
# File 'lib/apiture/request_context.rb', line 18

def group
  @group
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/apiture/request_context.rb', line 18

def options
  @options
end

Instance Method Details

#authenticatorObject



48
49
50
# File 'lib/apiture/request_context.rb', line 48

def authenticator
  group.authenticator
end

#get_attribute(name) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/apiture/request_context.rb', line 56

def get_attribute(name)
  name = name.to_sym
  unless attributes.has_key?(name)
    name = underscore(name).to_sym
  end
  attributes[name]
end

#loggerObject



52
53
54
# File 'lib/apiture/request_context.rb', line 52

def logger
  group.logger
end

#performObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/apiture/request_context.rb', line 24

def perform
  url = endpoint.url.dup

  if url.base_host
    url.subdomain = options[:subdomain]
  end

  if options[:url_options]
    url.merge_components(options[:url_options])
  end

  env = {
    method: endpoint.request_method,
    url: url,
    params: {},
    request_headers: {},
    logger: logger,
    context: self
  }

  endpoint.middleware_stack.call(env)
  perform_request(env)
end