Class: Pupper::Backend

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

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.



37
38
39
40
41
42
43
44
45
46
# File 'lib/pupper/backend.rb', line 37

def initialize
  @client = Faraday.new(base_url, ssl: { verify: Rails.env.production? }) do |builder|
    builder.request :json
    builder.use Pupper::ParseJson
    builder.response :logger if Rails.env.development?
    builder.response :raise_error
    builder.adapter :typhoeus
    builder.headers['User-Agent'] = Pupper.config.user_agent
  end
end

Class Attribute Details

.base_urlObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pupper/backend.rb', line 14

def base_url
  if @base_url.nil?
    raise BaseUrlNotDefined, <<-ERR
      Add the following to #{name} to make it work:

        self.base_url = "https://example.com/some/path"

      Making sure to change the URL to something useful :)))
    ERR
  end

  @base_url
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#register_model(model) ⇒ Object



48
49
50
# File 'lib/pupper/backend.rb', line 48

def register_model(model)
  @model = model
end