Class: GodaddyApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/GodaddyApi/client.rb

Constant Summary collapse

API_URL =
'https://api.godaddy.com'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/GodaddyApi/client.rb', line 9

def initialize(options)
  @key = options[:key]
  @secret = options[:secret]
  @resources = {}
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



37
38
39
40
41
42
43
44
# File 'lib/GodaddyApi/client.rb', line 37

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

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/GodaddyApi/client.rb', line 7

def key
  @key
end

Class Method Details

.resourcesObject



21
22
23
24
25
26
27
28
29
# File 'lib/GodaddyApi/client.rb', line 21

def self.resources
  {
    images: ImageResource,
    keys: KeyResource,
    servers: ServerResource,
    limits: LimitResource,
    specs: SpecResource
  }
end

Instance Method Details

#connectionObject



15
16
17
18
19
# File 'lib/GodaddyApi/client.rb', line 15

def connection
  Faraday.new(connection_options) do |req|
    req.adapter :net_http
  end
end

#resourcesObject



31
32
33
# File 'lib/GodaddyApi/client.rb', line 31

def resources
  @resources ||= {}
end