Class: Backdrop::APIBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/backdrop/api_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(default_url = nil) ⇒ APIBuilder

Returns a new instance of APIBuilder.



7
8
9
10
# File 'lib/backdrop/api_builder.rb', line 7

def initialize(default_url = nil)
  @config = Backdrop.configuration
  @url = default_url
end

Instance Method Details

#build(input) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/backdrop/api_builder.rb', line 12

def build(input)
  hashes = Array(input).map(&:to_h)
  url = extract_url(hashes)

  if input.respond_to?(:map)
    write_api(@url || url, hashes)
  else
    write_api(@url || url, hashes.first)
  end
end