class Pupper::Backend
Provides an interface to build an API Client, that can be used by [Model]
Attributes
base_url[W]
Sets the base URL the API client will call @return [String] the URL (plus - optionally - a path)
headers[W]
Sets the base URL the API client will call @return [String] the URL (plus - optionally - a path)
client[R]
model[R]
Public Class Methods
base_url()
click to toggle source
# File lib/pupper/backend.rb, line 21 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
headers()
click to toggle source
# File lib/pupper/backend.rb, line 17 def headers @headers ||= {} end
new()
click to toggle source
# 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
Public Instance Methods
register_model(model)
click to toggle source
# File lib/pupper/backend.rb, line 55 def register_model(model) @model = model end