Module: EbayRequest

Defined in:
lib/ebay_request.rb,
lib/ebay_request/version.rb

Defined Under Namespace

Classes: Auth, Base, BusinessPolicies, Config, Error, Finding, Response, Shopping, Site, Trading

Constant Summary collapse

VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config_repositoryObject

Returns the value of attribute config_repository.



26
27
28
# File 'lib/ebay_request.rb', line 26

def config_repository
  @config_repository
end

.json_loggerObject

Returns the value of attribute json_logger.



27
28
29
# File 'lib/ebay_request.rb', line 27

def json_logger
  @json_logger
end

.loggerObject

Returns the value of attribute logger.



24
25
26
# File 'lib/ebay_request.rb', line 24

def logger
  @logger
end

.warn_loggerObject

Returns the value of attribute warn_logger.



25
26
27
# File 'lib/ebay_request.rb', line 25

def warn_logger
  @warn_logger
end

Class Method Details

.config(key = nil) ⇒ Object



29
30
31
32
# File 'lib/ebay_request.rb', line 29

def config(key = nil)
  @config_repository ||= {}
  @config_repository[key || :default] ||= Config.new
end

.configure(key = nil) ⇒ Object



34
35
36
# File 'lib/ebay_request.rb', line 34

def configure(key = nil)
  yield(config(key)) && config(key)
end

.configured?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ebay_request.rb', line 38

def configured?
  !@config_repository.nil?
end

.fix_utf(response) ⇒ Object



71
72
73
74
75
# File 'lib/ebay_request.rb', line 71

def fix_utf(response)
  response.encode(
    "UTF-8", undef: :replace, invalid: :replace, replace: " "
  )
end

.log(options) ⇒ Object



42
43
44
45
46
# File 'lib/ebay_request.rb', line 42

def log(options)
  log_info(options)
  log_warn(options)
  log_json(options)
end

.log_info(o) ⇒ Object

rubocop:disable Metrics/AbcSize



49
50
51
52
53
54
55
56
# File 'lib/ebay_request.rb', line 49

def log_info(o)
  return if logger.nil?
  logger.info "[EbayRequest] | Url      | #{o[:url]}"
  logger.info "[EbayRequest] | Headers  | #{o[:headers]}"
  logger.info "[EbayRequest] | Body     | #{o[:request_payload]}"
  logger.info "[EbayRequest] | Response | #{fix_utf(o[:response_payload])}"
  logger.info "[EbayRequest] | Time     | #{o[:time]} #{o[:callname]}"
end

.log_json(options) ⇒ Object



66
67
68
69
# File 'lib/ebay_request.rb', line 66

def log_json(options)
  return if json_logger.nil?
  json_logger.info(options)
end

.log_warn(o) ⇒ Object

rubocop:enable Metrics/AbcSize



59
60
61
62
63
64
# File 'lib/ebay_request.rb', line 59

def log_warn(o)
  return if warn_logger.nil? || o[:warnings].empty?
  warn_logger.warn(
    "[EbayRequest] | #{o[:callname]} | #{o[:warnings].inspect}"
  )
end