Module: Jeckle::HTTP::APIMapping

Defined in:
lib/jeckle/http.rb

Instance Method Summary collapse

Instance Method Details

#api(registered_api_name) ⇒ Object

The API name that Jeckle uses to find all the api settings like domain, headers, etc.

Examples:


Jeckle.configure do |config|
  config.register :dribbble do |api|
    api.base_uri = 'http://api.dribbble.com'
  end
end

class Shot
  include Jeckle::Resource
  api :dribbble
end


57
58
59
60
61
# File 'lib/jeckle/http.rb', line 57

def api(registered_api_name)
  api_mapping[:default_api] = Jeckle::Setup.registered_apis.fetch(registered_api_name)
rescue KeyError => e
  raise Jeckle::NoSuchAPIError, registered_api_name
end

#api_mappingObject



70
71
72
# File 'lib/jeckle/http.rb', line 70

def api_mapping
  @api_mapping ||= {}
end

#default_api(registered_api_name) ⇒ Object

Deprecated.

Please use #api instead



65
66
67
68
# File 'lib/jeckle/http.rb', line 65

def default_api(registered_api_name)
  warn "[DEPRECATION] `default_api` is deprecated.  Please use `api` instead."
  api(registered_api_name)
end

#inherited(base) ⇒ Object



8
9
10
11
12
# File 'lib/jeckle/http.rb', line 8

def inherited(base)
  base.class_eval do
    @api_mapping = superclass.api_mapping.dup
  end
end

#resource_nameObject

The name of the resource that Jeckle uses to make the request

To overwrite this behaviour, rewrite the resource name method in the class:

module OtherApi
  class Project
    include Jeckle::Resource

    def self.resource_name
      '/project'
    end
  end
end

Examples:


module Dribble
  class Shot
    include Jeckle::Resource
  end
end

Shot.resource_name # => Will request for '/shots' resource


38
39
40
# File 'lib/jeckle/http.rb', line 38

def resource_name
  @resource_name ||= model_name.element.pluralize
end

#run_request(endpoint, options = {}) ⇒ Object



74
75
76
# File 'lib/jeckle/http.rb', line 74

def run_request(endpoint, options = {})
  Jeckle::Request.run api_mapping[:default_api], endpoint, options
end