Class: Pupper::Backend
- Inherits:
-
Object
- Object
- Pupper::Backend
- Defined in:
- lib/pupper/backend.rb
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.
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_url ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/pupper/backend.rb', line 7 def client @client end |
#model ⇒ Object (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 |