Module: RestApi

Defined in:
app/models/rest_api/cacheable.rb,
app/models/rest_api.rb,
app/models/rest_api/info.rb,
app/models/rest_api/environment.rb,
app/models/rest_api/log_subscriber.rb,
app/models/rest_api/railties/controller_runtime.rb,
app/models/rest_api/base.rb

Overview

Inspired by Seamus Abshere cache_method, no code reuse github.com/seamusabshere/cache_method

Invoke cache_method <symbol for method name>, <key string, array, or lambda> for any static method on this class

Defined Under Namespace

Modules: Cacheable, Railties Classes: ApiNotAvailable, Authorization, BadServerResponseError, Base, Environment, Info, LogSubscriber, MissingAuthorizationError, OpenshiftJsonFormat, ResourceExistsError, ResourceNotFound, UserAwareConnection

Class Method Summary collapse

Class Method Details

.application_domain_suffixObject



117
118
119
# File 'app/models/rest_api.rb', line 117

def application_domain_suffix
  @application_domain_suffix ||= RestApi::Environment.cached.find(:one).domain_suffix
end

.configObject

FIXME: May be desirable to replace this with a standard ActiveSupport config object



113
114
115
# File 'app/models/rest_api.rb', line 113

def config
  RestApi::Base.instance_variable_get("@last_config") || {}
end

.debug(set = true, &block) ⇒ Object

All code in the block will dump detailed HTTP logs



57
58
59
60
61
62
63
64
65
66
# File 'app/models/rest_api.rb', line 57

def debug(set=true,&block)
  @debug = set
  if block_given?
    begin
      yield block
    ensure
      @debug = false
    end
  end
end

.debug?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/rest_api.rb', line 67

def debug?
  @debug || ENV['REST_API_DEBUG']
end

.force_http_debugObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/rest_api.rb', line 70

def force_http_debug
  unless ActiveResource::Connection.respond_to? :configure_http_with_debug
    ActiveResource::Connection.class_eval do
      def configure_http_with_debug(http)
        configure_http_without_debug(http)
        http.set_debug_output $stderr
        http
      end
      alias_method_chain :configure_http, :debug
    end
  end
end

.infoObject

Return the version information about the REST API



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/rest_api.rb', line 93

def info
  RestApi::Info.cached.find :one
rescue Exception => e
  raise ApiNotAvailable, <<-EXCEPTION, e.backtrace

The REST API could not be reached at #{RestApi::Base.site}

  Rails environment:     #{Rails.env}
  Current configuration: #{config.inspect} #{config[:symbol] ? "(via :#{config[:symbol]})" : ''}

  #{e.message}
  #{e.backtrace.join("\n  ")}
  EXCEPTION
end

.reset!Object



108
109
110
# File 'app/models/rest_api.rb', line 108

def reset!
  @info = nil
end

.siteObject



121
122
123
# File 'app/models/rest_api.rb', line 121

def site
  RestApi::Base.site
end

.test?Boolean

Is the API reachable?

Returns:

  • (Boolean)


86
87
88
# File 'app/models/rest_api.rb', line 86

def test?
  info.present? rescue false
end