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.



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

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_url=(value) ⇒ String

Sets the base URL the API client will call

Returns:

  • (String)

    the URL (plus - optionally - a path)



15
16
17
# File 'lib/pupper/backend.rb', line 15

def base_url=(value)
  @base_url = value
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



53
54
55
# File 'lib/pupper/backend.rb', line 53

def register_model(model)
  @model = model
end