Module: ApiBee

Defined in:
lib/api_bee.rb,
lib/api_bee/node.rb,
lib/api_bee/proxy.rb,
lib/api_bee/version.rb,
lib/api_bee/adapters/hash.rb

Defined Under Namespace

Modules: Adapters Classes: Config, Node, Proxy

Constant Summary collapse

VERSION =
"0.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Class Method Details

.new_configObject

new config object with defaults



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/api_bee.rb', line 25

def new_config
  Config.new(
    # This field is expected in API responses
    # and should point to an individual resource with more data
    :uri_property_name            => :href,
    # Total number of entries
    # Used to paginate lists
    :total_entries_property_name  => :total_entries,
    # Name of array property
    # that contains cureent page's entries
    :entries_property_name        => :entries
  )
end

.setup(adapter_klass, *args) {|config| ... } ⇒ Object

Yields:

Raises:

  • (NoMethodError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api_bee.rb', line 7

def setup(adapter_klass, *args)
  
  adapter = if adapter_klass.is_a?(::Symbol)
    require File.join('api_bee', 'adapters', adapter_klass.to_s)
    klass = adapter_klass.to_s.gsub(/(^.{1})/){$1.upcase}
    Adapters.const_get(klass).new(*args)
  else
    adapter_klass.new *args
  end

  raise NoMethodError, "Adapter must implement #get(path, *args) method" unless adapter.respond_to?(:get)
  
  config = new_config
  yield config if block_given?
  Proxy.new adapter, config
end