Class: Aitch::Namespace

Inherits:
Object show all
Defined in:
lib/aitch/namespace.rb

Instance Method Summary collapse

Instance Method Details

#configObject Also known as: configuration


9
10
11
# File 'lib/aitch/namespace.rb', line 9

def config
  @config ||= Configuration.new
end

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

Yields:


5
6
7
# File 'lib/aitch/namespace.rb', line 5

def configure
  yield config
end

#execute(request_method: nil, url: nil, params: nil, data: nil, body: nil, headers: nil, options: nil, &block) ⇒ Object


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
# File 'lib/aitch/namespace.rb', line 14

def execute(
  request_method: nil,
  url: nil,
  params: nil,
  data: nil,
  body: nil,
  headers: nil,
  options: nil,
  &block
)
  data = data || params || body || {}
  headers ||= {}
  options ||= {}

  if block_given?
    dsl = DSL.new
    dsl.instance_eval(&block)
    args = dsl.to_h
  else
    args = {
      url: url,
      data: data,
      headers: headers,
      options: options
    }
  end

  args.merge!(
    request_method: request_method,
    options: config.to_h.merge(Utils.symbolize_keys(args[:options]))
  )

  Request.new(args).perform
end

#execute!(*args, &block) ⇒ Object


49
50
51
52
53
54
55
56
# File 'lib/aitch/namespace.rb', line 49

def execute!(*args, &block)
  options = extract_args!(args)
  response = execute(**options, &block)

  raise response.error if response.error?

  response
end