Class: PostyClient::Resources::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/posty_client/resources/domain.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors, #name, #new_resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_uri, #base_uri, #create, #delete, #load, #new_resource?, #request_with_error_handling, resource_name, #resource_name, #save, #update

Constructor Details

#initialize(name = nil) ⇒ Domain

Returns a new instance of Domain.



21
22
23
24
# File 'lib/posty_client/resources/domain.rb', line 21

def initialize(name=nil)
  @name = name
  load if name
end

Class Method Details

.allObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/posty_client/resources/domain.rb', line 5

def self.all
  response = RestClient.get([base_uri, resource_name].join('/'))

  return nil unless response.code == 200

  data = JSON.parse(response)

  data.collect do |datum|
    model = self.new
    model.attributes = datum.flatten.last
    model.new_resource = false

    model
  end
end

Instance Method Details

#aliasesObject



30
31
32
# File 'lib/posty_client/resources/domain.rb', line 30

def aliases
  DomainAlias.find_all_by_domain(self)
end

#resource_slugObject



38
39
40
# File 'lib/posty_client/resources/domain.rb', line 38

def resource_slug
  [base_uri, 'domains'].join('/')
end

#slugObject



34
35
36
# File 'lib/posty_client/resources/domain.rb', line 34

def slug
  [resource_slug, name].join('/')
end

#usersObject



26
27
28
# File 'lib/posty_client/resources/domain.rb', line 26

def users
  User.find_all_by_domain(self)
end