Class: OneOne::Client
- Inherits:
-
Object
- Object
- OneOne::Client
- Defined in:
- lib/one_one/client.rb
Constant Summary collapse
- API_VERSION =
1
- API_URL =
'https://cloudpanel-api.1and1.com'
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
-
.resources ⇒ Object
This is used to lazy-load resources.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
-
#method_missing(name, *args, &block) ⇒ Object
This attaches resources to the client Resources map to a specific model.
- #resources ⇒ Object
- #token_valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/one_one/client.rb', line 11 def initialize() @token = [:token] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
This attaches resources to the client Resources map to a specific model
39 40 41 42 43 44 45 46 |
# File 'lib/one_one/client.rb', line 39 def method_missing(name, *args, &block) if self.class.resources.keys.include?(name) resources[name] ||= self.class.resources[name].new(connection: connection) resources[name] else super end end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/one_one/client.rb', line 9 def token @token end |
Class Method Details
.resources ⇒ Object
This is used to lazy-load resources. It is stored in the @resources instance variable when a caller requests the resource.
24 25 26 27 28 29 30 31 |
# File 'lib/one_one/client.rb', line 24 def self.resources { servers: ServerResource, images: ImageResource, server_appliances: ServerApplianceResource, firewall_policies: FirewallPolicyResource } end |
Instance Method Details
#connection ⇒ Object
15 16 17 18 19 |
# File 'lib/one_one/client.rb', line 15 def connection Faraday.new() do |req| req.adapter :net_http end end |
#resources ⇒ Object
33 34 35 |
# File 'lib/one_one/client.rb', line 33 def resources @resources ||= {} end |
#token_valid? ⇒ Boolean
48 49 50 51 |
# File 'lib/one_one/client.rb', line 48 def token_valid? res = connection.get('/v1/') binding.pry end |