Module: Hyperclient

Defined in:
lib/hyperclient.rb,
lib/hyperclient/http.rb,
lib/hyperclient/version.rb,
lib/hyperclient/resource.rb,
lib/hyperclient/response.rb,
lib/hyperclient/discoverer.rb,
lib/hyperclient/resource_factory.rb

Overview

The Hyperclient module has various methods to so you can setup your API client.

Examples:

class MyAPI
  extend Hyperclient
entry_point 'http://api.myapp.com'
end

Defined Under Namespace

Modules: ClassMethods Classes: Discoverer, HTTP, Resource, ResourceFactory, Response

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Delegate the method to the API if it exists.

This way we can call our API client with the resources name instead of having to add the methods to it.



27
28
29
30
31
32
33
# File 'lib/hyperclient.rb', line 27

def method_missing(method, *args, &block)
  if entry.respond_to?(method)
    entry.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extend the parent class with our class methods.



14
15
16
# File 'lib/hyperclient.rb', line 14

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#entryObject

Initializes the API with the entry point.



19
20
21
# File 'lib/hyperclient.rb', line 19

def entry
  @entry ||= Resource.new('/', resource_options)
end

#resource_optionsObject (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a Hash with the options to initialize the entry point Resource.



68
69
70
# File 'lib/hyperclient.rb', line 68

def resource_options
  {name: 'Entry point'}.merge(self.class.http_options)
end