Class: Pupper::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/pupper/backend.rb

Overview

Provides an interface to build an API Client, that can be used by [Model]

Defined Under Namespace

Classes: BaseUrlNotDefined

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBackend

Returns a new instance of Backend.



44
45
46
47
48
49
50
51
52
53
# File 'lib/pupper/backend.rb', line 44

def initialize
  @client = Faraday.new(base_url, ssl: Pupper.config.ssl) do |builder|
    builder.request :json
    builder.use Pupper::ParseJson
    builder.response :logger if Pupper.config.logging?
    builder.response :raise_error
    builder.adapter :typhoeus
    builder.headers = headers.merge!('User-Agent' => Pupper.config.user_agent)
  end
end

Class Attribute Details

.base_urlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pupper/backend.rb', line 21

def base_url
  if @base_url.nil?
    raise BaseUrlNotDefined, "      Add the following to \#{name} to make it work:\n\n        self.base_url = \"https://example.com/some/path\"\n\n      Making sure to change the URL to something useful :)))\n    ERR\n  end\n\n  @base_url\nend\n"

.headersObject



17
18
19
# File 'lib/pupper/backend.rb', line 17

def headers
  @headers ||= {}
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/pupper/backend.rb', line 8

def client
  @client
end

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/pupper/backend.rb', line 8

def model
  @model
end

Instance Method Details

#register_model(model) ⇒ Object



55
56
57
# File 'lib/pupper/backend.rb', line 55

def register_model(model)
  @model = model
end