Module: RestEasy::ClassMethods

Defined in:
lib/rest_easy.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#authenticationObject



114
115
116
# File 'lib/rest_easy.rb', line 114

def authentication
  config.authentication
end

#configObject



69
70
71
# File 'lib/rest_easy.rb', line 69

def config
  self::Settings.config
end

#configure(&block) ⇒ Object



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

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



99
100
101
102
103
104
# File 'lib/rest_easy.rb', line 99

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

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



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

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

#faraday_connectionObject



106
107
108
109
110
111
112
# File 'lib/rest_easy.rb', line 106

def faraday_connection
  @faraday_connection ||= Faraday.new(url: config.base_url) do |f|
    f.request :json
    f.response :json
    @connection_block&.call(f)
  end
end

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

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



120
121
122
# File 'lib/rest_easy.rb', line 120

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

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



124
125
126
# File 'lib/rest_easy.rb', line 124

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

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



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

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

#settings(&block) ⇒ Object



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

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