Class: ApiRecipes::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/api_recipes/api.rb

Constant Summary collapse

BASE_CONFIGS_KEYS =
[:protocol, :host, :port, :api_version, :timeout, :on_bad_code, :mime_type, :verify_with]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, configs, object) ⇒ Api

Returns a new instance of Api.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/api_recipes/api.rb', line 9

def initialize(name, configs, object)
  @name = name
  @configs = ApiRecipes::Settings::DEFAULT.merge configs
  @object = object

  # Generate   some_api.some_endpoint  methods
  # e.g.  github.users
  endpoints = @configs[:endpoints]
  if endpoints && endpoints.is_a?(Hash)
    endpoints.each do |ep_name, params|
      unless respond_to? ep_name
        # TODO: store endpoints, routes and routes_urls
        define_singleton_method ep_name do |*request_params, &block|
          # puts "API params: #{params}"
          Endpoint.new api: self, name: ep_name, path: path, params: params, request_params: request_params, &block
        end
      end
    end
  end
end

Instance Attribute Details

#authorizationObject

Returns the value of attribute authorization.



4
5
6
# File 'lib/api_recipes/api.rb', line 4

def authorization
  @authorization
end

#base_configsObject (readonly)

Returns the value of attribute base_configs.



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

def base_configs
  @base_configs
end

#basic_authObject

Returns the value of attribute basic_auth.



4
5
6
# File 'lib/api_recipes/api.rb', line 4

def basic_auth
  @basic_auth
end

#configsObject

Returns the value of attribute configs.



4
5
6
# File 'lib/api_recipes/api.rb', line 4

def configs
  @configs
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/api_recipes/api.rb', line 4

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end