Class: Pupper::Backend
- Inherits:
-
Object
- Object
- Pupper::Backend
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize ⇒ Backend
constructor
A new instance of Backend.
- #register_model(model) ⇒ Object
Constructor Details
#initialize ⇒ Backend
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_url ⇒ Object
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" |
.headers ⇒ Object
17 18 19 |
# File 'lib/pupper/backend.rb', line 17 def headers @headers ||= {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/pupper/backend.rb', line 8 def client @client end |
#model ⇒ Object (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 |