Module: SWD

Defined in:
lib/swd.rb,
lib/swd/cache.rb,
lib/swd/resource.rb,
lib/swd/response.rb,
lib/swd/exception.rb

Defined Under Namespace

Classes: BadRequest, Cache, Exception, Forbidden, HttpError, NotFound, Resource, Response, Unauthorized

Constant Summary collapse

VERSION =
::File.read(
  ::File.join(::File.dirname(__FILE__), '../VERSION')
).strip

Class Method Summary collapse

Class Method Details

.cacheObject



19
20
21
# File 'lib/swd.rb', line 19

def self.cache
  @@cache
end

.cache=(cache) ⇒ Object



16
17
18
# File 'lib/swd.rb', line 16

def self.cache=(cache)
  @@cache = cache
end

.debug(&block) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/swd.rb', line 45

def self.debug(&block)
  original = self.debugging?
  self.debugging = true
  yield
ensure
  self.debugging = original
end

.debug!Object



42
43
44
# File 'lib/swd.rb', line 42

def self.debug!
  self.debugging = true
end

.debugging=(boolean) ⇒ Object



39
40
41
# File 'lib/swd.rb', line 39

def self.debugging=(boolean)
  @@debugging = boolean
end

.debugging?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/swd.rb', line 36

def self.debugging?
  @@debugging
end

.discover!(attributes = {}) ⇒ Object



23
24
25
# File 'lib/swd.rb', line 23

def self.discover!(attributes = {})
  Resource.new(attributes).discover!(attributes[:cache])
end

.http_clientObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/swd.rb', line 54

def self.http_client
  Faraday.new(headers: {user_agent: "SWD #{VERSION}"}) do |faraday|
    faraday.response :raise_error
    faraday.response :json
    faraday.response :follow_redirects
    faraday.response :logger, SWD.logger if debugging?
    faraday.adapter Faraday.default_adapter
    http_config.try(:call, faraday)
  end
end

.http_config(&block) ⇒ Object



64
65
66
# File 'lib/swd.rb', line 64

def self.http_config(&block)
  @@http_config ||= block
end

.loggerObject



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

def self.logger
  @@logger
end

.logger=(logger) ⇒ Object



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

def self.logger=(logger)
  @@logger = logger
end

.url_builderObject



68
69
70
# File 'lib/swd.rb', line 68

def self.url_builder
  @@url_builder ||= URI::HTTPS
end

.url_builder=(builder) ⇒ Object



71
72
73
# File 'lib/swd.rb', line 71

def self.url_builder=(builder)
  @@url_builder = builder
end