Module: Her::Model::HTTP::ClassMethods

Defined in:
lib/castle-her/model/http.rb

Overview

For each HTTP method, define these class methods:

  • <method>(path, params)

  • <method>_raw(path, params, &block)

  • <method>_collection(path, params, &block)

  • <method>_resource(path, params, &block)

  • custom_<method>(*paths)

Examples:

class User
  include Her::Model
  custom_get :active
end

User.get(:popular) # GET "/users/popular"
User.active # GET "/users/active"

Instance Method Summary collapse

Instance Method Details

#use_api(value = nil) ⇒ Object Also known as: her_api, uses_api

Change which API the model will use to make its HTTP requests

Examples:

secondary_api = Her::API.new :url => "https://api.example" do |connection|
  connection.use Faraday::Request::UrlEncoded
  connection.use Her::Middleware::DefaultParseJSON
end

class User
  include Her::Model
  use_api secondary_api
end


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/castle-her/model/http.rb', line 37

def use_api(value = nil)
  @_her_use_api ||= begin
    superclass.use_api if superclass.respond_to?(:use_api)
  end

  unless value
    return (@_her_use_api.respond_to? :call) ? @_her_use_api.call : @_her_use_api
  end

  @_her_use_api = value
end