Module: RestEasy::ClassMethods

Defined in:
lib/rest_easy.rb

Overview

── Module extension (ClassMethods) ──────────────────────────────────

Instance Method Summary collapse

Instance Method Details

#authenticationObject



127
128
129
# File 'lib/rest_easy.rb', line 127

def authentication
  config.authentication
end

#configObject



72
73
74
# File 'lib/rest_easy.rb', line 72

def config
  self::Settings.config
end

#configure(&block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rest_easy.rb', line 80

def configure(&block)
  if block_given?
    if block.arity == 0
      dsl = Resource::ConfigureDSL.new(self::Settings.config)
      dsl.instance_eval(&block)
    else
      yield self::Settings.config
    end

    # Backwards compatibility: propagate the deprecated attribute_convention
    # to conversions, but only on changes — so repeated `configure` calls
    # don't re-warn and don't clobber a `conversions.json_attributes` set in
    # a later call.
    ac = self::Settings.config.attribute_convention
    if ac && @_propagated_attribute_convention != ac
      warn "RestEasy: attribute_convention is deprecated, use `conversions.json_attributes = #{ac.inspect}` instead"
      self::Settings.config.conversions.json_attributes = ac
      @_propagated_attribute_convention = ac
    end
  end
end

#connection(&block) ⇒ Object



102
103
104
105
106
107
# File 'lib/rest_easy.rb', line 102

def connection(&block)
  if block_given?
    @connection_block = block
  end
  @connection_block
end

#delete(path:, headers: {}) ⇒ Object



145
146
147
# File 'lib/rest_easy.rb', line 145

def delete(path:, headers: {})
  request_with_auth(:delete, path, headers:)
end

#faraday_connectionObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rest_easy.rb', line 109

def faraday_connection
  @faraday_connection ||= Faraday.new(url: config.base_url) do |f|
    f.request :json
    f.response :json
    if config.logger
      # Faraday's logger emits headers as `Name: "value"` — the filters
      # depend on that format. If the format changes, redaction silently
      # breaks; the integration specs catch the common case.
      f.response :logger, config.logger, bodies: config.log_bodies do |l|
        STANDARD_AUTH_HEADERS.each do |name|
          l.filter(/(#{Regexp.escape(name)}:\s*")[^"]+/i, '\1[FILTERED]')
        end
      end
    end
    @connection_block&.call(f)
  end
end

#get(path:, params: {}, headers: {}) ⇒ Object

── HTTP primitives ─────────────────────────────────────────────────



133
134
135
# File 'lib/rest_easy.rb', line 133

def get(path:, params: {}, headers: {})
  request_with_auth(:get, path, params:, headers:)
end

#post(path:, body: nil, headers: {}) ⇒ Object



137
138
139
# File 'lib/rest_easy.rb', line 137

def post(path:, body: nil, headers: {})
  request_with_auth(:post, path, body:, headers:)
end

#put(path:, body: nil, headers: {}) ⇒ Object



141
142
143
# File 'lib/rest_easy.rb', line 141

def put(path:, body: nil, headers: {})
  request_with_auth(:put, path, body:, headers:)
end

#settings(&block) ⇒ Object



76
77
78
# File 'lib/rest_easy.rb', line 76

def settings(&block)
  self::Settings.class_eval(&block) if block_given?
end