Class: Fabulous::Client
- Inherits:
-
Object
- Object
- Fabulous::Client
- Defined in:
- lib/fabulous/client.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #dns ⇒ Object
- #domains ⇒ Object
-
#initialize(configuration = nil) ⇒ Client
constructor
A new instance of Client.
- #request(action, params = {}) ⇒ Object
Constructor Details
#initialize(configuration = nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/fabulous/client.rb', line 7 def initialize(configuration = nil) @configuration = configuration || Fabulous.configuration || Configuration.new validate_configuration! end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/fabulous/client.rb', line 5 def configuration @configuration end |
Instance Method Details
#dns ⇒ Object
16 17 18 |
# File 'lib/fabulous/client.rb', line 16 def dns @dns ||= Resources::DNS.new(self) end |
#domains ⇒ Object
12 13 14 |
# File 'lib/fabulous/client.rb', line 12 def domains @domains ||= Resources::Domain.new(self) end |
#request(action, params = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fabulous/client.rb', line 20 def request(action, params = {}) params = build_params(action, params) # The Fabulous API uses GET requests with URL parameters url = "/#{action}" response = connection.get(url) do |req| req.params = params end # Debug output if ENV variable is set if ENV["DEBUG_FABULOUS"] puts "Request URL: #{configuration.base_url}#{url}" puts "Parameters: #{params.inspect}" puts "HTTP Status: #{response.status}" puts "Response Body:" puts response.body puts end Response.new(response.body).tap do |parsed_response| handle_errors(parsed_response) end rescue Faraday::TimeoutError => e raise TimeoutError, "Request timed out: #{e.}" rescue Faraday::Error => e raise RequestError, "Request failed: #{e.}" end |