Module: Flexirest::Configuration::ClassMethods
- Defined in:
- lib/flexirest/configuration.rb
Constant Summary collapse
- DEFAULT_BASIC_URL_METHOD =
:url
- @@base_url =
nil
- @@alias_type =
nil
- @@username =
nil
- @@password =
nil
- @@request_body_type =
:form_encoded
- @@disable_automatic_date_parsing =
nil
Instance Method Summary collapse
- #_reset_configuration! ⇒ Object
- #adapter ⇒ Object
- #adapter=(adapter) ⇒ Object
- #alias_type(value = nil) ⇒ Object
- #api_auth_access_id ⇒ Object
- #api_auth_credentials(access_id, secret_key, options = {}) ⇒ Object
- #api_auth_options ⇒ Object
- #api_auth_secret_key ⇒ Object
- #base_url(value = nil) ⇒ Object
- #base_url=(value) ⇒ Object
- #basic_auth_method(value = nil) ⇒ Object
- #disable_automatic_date_parsing(value = nil) ⇒ Object
- #disable_automatic_date_parsing=(value) ⇒ Object
- #faraday_config(&block) ⇒ Object
- #ignore_root(value = nil) ⇒ Object
- #lazy_load! ⇒ Object
- #lazy_load? ⇒ Boolean
- #password(value = nil, &block) ⇒ Object
- #password=(value) ⇒ Object
- #proxy(value = nil) ⇒ Object
- #quiet(value = nil) ⇒ Object
- #quiet!(options = {}) ⇒ Object
- #request_body_type(value = nil) ⇒ Object
- #request_body_type=(value) ⇒ Object
- #translator(value = nil) ⇒ Object
- #username(value = nil, &block) ⇒ Object
- #username=(value) ⇒ Object
- #using_api_auth? ⇒ Boolean
- #verbose(value = nil) ⇒ Object
- #verbose! ⇒ Object
- #whiny_missing(value = nil) ⇒ Object
- #wrap_root(value = nil) ⇒ Object
Instance Method Details
#_reset_configuration! ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/flexirest/configuration.rb', line 330 def _reset_configuration! @base_url = nil @@base_url = nil @request_body_type = nil @@request_body_type = nil @whiny_missing = nil @lazy_load = false @faraday_config = default_faraday_config @adapter = Faraday.default_adapter @api_auth_access_id = nil @api_auth_secret_key = nil @basic_auth_method = :url end |
#adapter ⇒ Object
217 218 219 |
# File 'lib/flexirest/configuration.rb', line 217 def adapter @adapter ||= Faraday.default_adapter end |
#adapter=(adapter) ⇒ Object
212 213 214 215 |
# File 'lib/flexirest/configuration.rb', line 212 def adapter=(adapter) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Adapter set to be #{adapter}" @adapter = adapter end |
#alias_type(value = nil) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/flexirest/configuration.rb', line 151 def alias_type(value = nil) @alias_type ||= nil if value.nil? if @alias_type.nil? if value.nil? && superclass.respond_to?(:alias_type) superclass.alias_type else @@alias_type || nil end else @alias_type end else @alias_type = value end end |
#api_auth_access_id ⇒ Object
258 259 260 261 262 263 264 265 266 267 |
# File 'lib/flexirest/configuration.rb', line 258 def api_auth_access_id @api_auth_access_id ||= nil if !@api_auth_access_id.nil? return @api_auth_access_id elsif self.superclass.respond_to?(:api_auth_access_id) return self.superclass.api_auth_access_id end return nil end |
#api_auth_credentials(access_id, secret_key, options = {}) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/flexirest/configuration.rb', line 242 def api_auth_credentials(access_id, secret_key, = {}) begin require 'api-auth' rescue LoadError raise MissingOptionalLibraryError.new("You must include the gem 'api-auth' in your Gemfile to set api-auth credentials.") end @api_auth_access_id = access_id @api_auth_secret_key = secret_key @api_auth_options = end |
#api_auth_options ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/flexirest/configuration.rb', line 279 def if !@api_auth_options.nil? return @api_auth_options elsif self.superclass.respond_to?(:api_auth_options) return self.superclass. end return {} end |
#api_auth_secret_key ⇒ Object
269 270 271 272 273 274 275 276 277 |
# File 'lib/flexirest/configuration.rb', line 269 def api_auth_secret_key if !@api_auth_secret_key.nil? return @api_auth_secret_key elsif self.superclass.respond_to?(:api_auth_secret_key) return self.superclass.api_auth_secret_key end return nil end |
#base_url(value = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/flexirest/configuration.rb', line 43 def base_url(value = nil) @base_url ||= nil @@base_url ||= nil if value.nil? value = if @base_url.nil? @@base_url else @base_url end if value.nil? && superclass.respond_to?(:base_url) value = superclass.base_url end value else if value.is_a?(Array) value.each_with_index do |v, k| value[k] = v.gsub(/\/$/, '') end else value = value.gsub(/\/$/, '') end @base_url = value end end |
#base_url=(value) ⇒ Object
68 69 70 71 72 |
# File 'lib/flexirest/configuration.rb', line 68 def base_url=(value) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Base URL set to be #{value}" value = value.gsub(/\/+$/, '') @@base_url = value end |
#basic_auth_method(value = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/flexirest/configuration.rb', line 136 def basic_auth_method(value = nil) if value.nil? # Used as a getter method if @basic_auth_method.nil? && superclass.respond_to?(:basic_auth_method) superclass.basic_auth_method else @basic_auth_method || DEFAULT_BASIC_URL_METHOD end else # Used as a setter method unless [:header, :url].include?(value) raise %(Invalid basic_auth_method #{value.inspect}. Valid methods are :url (default) and :header.) end @basic_auth_method = value end end |
#disable_automatic_date_parsing(value = nil) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/flexirest/configuration.rb', line 190 def disable_automatic_date_parsing(value = nil) @disable_automatic_date_parsing ||= nil if value.nil? if @disable_automatic_date_parsing.nil? if value.nil? && superclass.respond_to?(:disable_automatic_date_parsing) superclass.disable_automatic_date_parsing else @@disable_automatic_date_parsing || false end else @disable_automatic_date_parsing end else @disable_automatic_date_parsing = value end end |
#disable_automatic_date_parsing=(value) ⇒ Object
207 208 209 210 |
# File 'lib/flexirest/configuration.rb', line 207 def disable_automatic_date_parsing=(value) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Request Body Type set to be #{value}" @@disable_automatic_date_parsing = value end |
#faraday_config(&block) ⇒ Object
221 222 223 224 225 226 227 |
# File 'lib/flexirest/configuration.rb', line 221 def faraday_config(&block) if block @faraday_config = block else @faraday_config ||= default_faraday_config end end |
#ignore_root(value = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flexirest/configuration.rb', line 19 def ignore_root(value=nil) if value.nil? value = if @ignore_root.nil? && superclass.respond_to?(:ignore_root) superclass.ignore_root else @ignore_root end else @ignore_root = value end end |
#lazy_load! ⇒ Object
229 230 231 |
# File 'lib/flexirest/configuration.rb', line 229 def lazy_load! @lazy_load = true end |
#lazy_load? ⇒ Boolean
233 234 235 |
# File 'lib/flexirest/configuration.rb', line 233 def lazy_load? @lazy_load ||= false end |
#password(value = nil, &block) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/flexirest/configuration.rb', line 105 def password(value = nil, &block) if value.nil? if block_given? @password = block else value = if @password.nil? @@password else @password end if value.nil? && superclass.respond_to?(:password) value = superclass.password end value end else if value.respond_to?(:call) @password = value else @password = value end end end |
#password=(value) ⇒ Object
129 130 131 132 |
# File 'lib/flexirest/configuration.rb', line 129 def password=(value) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Password set..." @@password = value end |
#proxy(value = nil) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/flexirest/configuration.rb', line 318 def proxy(value = nil) @proxy ||= nil value ? @proxy = value : @proxy || nil if !@proxy.nil? return @proxy elsif self.superclass.respond_to?(:proxy) return self.superclass.proxy end nil end |
#quiet(value = nil) ⇒ Object
303 304 305 306 307 308 309 310 |
# File 'lib/flexirest/configuration.rb', line 303 def quiet(value = nil) @quiet ||= false if value == true || value == false @quiet = value @verbose = false if @quiet != false end @quiet end |
#quiet!(options = {}) ⇒ Object
298 299 300 301 |
# File 'lib/flexirest/configuration.rb', line 298 def quiet!( = {}) @quiet = true @verbose = false end |
#request_body_type(value = nil) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/flexirest/configuration.rb', line 168 def request_body_type(value = nil) @request_body_type ||= nil if value.nil? if @request_body_type.nil? if value.nil? && superclass.respond_to?(:request_body_type) superclass.request_body_type else @@request_body_type || :form_encoded end else @request_body_type end else @request_body_type = value end end |
#request_body_type=(value) ⇒ Object
185 186 187 188 |
# File 'lib/flexirest/configuration.rb', line 185 def request_body_type=(value) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Request Body Type set to be #{value}" @@request_body_type = value end |
#translator(value = nil) ⇒ Object
312 313 314 315 316 |
# File 'lib/flexirest/configuration.rb', line 312 def translator(value = nil) Flexirest::Logger.warn("DEPRECATION: The translator functionality of Flexirest has been replaced with proxy functionality, see https://github.com/andyjeffries/flexirest#proxying-apis for more information") unless value.nil? @translator ||= nil value ? @translator = value : @translator end |
#username(value = nil, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/flexirest/configuration.rb', line 74 def username(value = nil, &block) @username ||= nil @@username ||= nil if value.nil? if block_given? @username = block else value = if @username.nil? @@username else @username end if value.nil? && superclass.respond_to?(:username) value = superclass.username end value end else if value.respond_to?(:call) @username = value else @username = value end end end |
#username=(value) ⇒ Object
100 101 102 103 |
# File 'lib/flexirest/configuration.rb', line 100 def username=(value) Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Username set to be #{value}" @@username = value end |
#using_api_auth? ⇒ Boolean
254 255 256 |
# File 'lib/flexirest/configuration.rb', line 254 def using_api_auth? !self.api_auth_access_id.nil? && !self.api_auth_secret_key.nil? end |
#verbose(value = nil) ⇒ Object
293 294 295 296 |
# File 'lib/flexirest/configuration.rb', line 293 def verbose(value = nil) @verbose ||= false value ? @verbose = value : @verbose end |
#verbose! ⇒ Object
289 290 291 |
# File 'lib/flexirest/configuration.rb', line 289 def verbose! @verbose = true end |
#whiny_missing(value = nil) ⇒ Object
237 238 239 240 |
# File 'lib/flexirest/configuration.rb', line 237 def whiny_missing(value = nil) @whiny_missing ||= false value ? @whiny_missing = value : @whiny_missing end |
#wrap_root(value = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/flexirest/configuration.rb', line 31 def wrap_root(value=nil) if value.nil? value = if @wrap_root.nil? && superclass.respond_to?(:wrap_root) superclass.wrap_root else @wrap_root end else @wrap_root = value end end |