Class: Webmaster::Hosts::Verification

Inherits:
Base show all
Includes:
Virtus
Defined in:
lib/webmaster/hosts/verification.rb

Constant Summary collapse

STATES =
[
  'in_progress',
  'never_verified',
  'verification_failed',
  'verified',
  'waiting'
].freeze
CHECKABLE_TYPES =
[        
  'dns_record',
  'html_file',        
  'meta_tag',        
  'txt_file',
  'whois'
].freeze
NON_CHECKABLE_TYPES =
[
  'auto',
  'manual',        
  'pdd',        
  'pdd_external',
  'delegation'        
].freeze
TYPES =
(CHECKABLE_TYPES + NON_CHECKABLE_TYPES).flatten.freeze

Constants included from Api::Request

Api::Request::METHODS, Api::Request::METHODS_WITH_BODIES

Constants included from Api::Connection

Api::Connection::ACCEPT, Api::Connection::ACCEPT_CHARSET, Api::Connection::ALLOWED_OPTIONS, Api::Connection::CONTENT_TYPE, Api::Connection::USER_AGENT

Instance Attribute Summary collapse

Attributes inherited from Base

#configuration

Attributes included from Api::Authorization

#scopes

Instance Method Summary collapse

Methods inherited from Base

#arguments, #attributes=, #inspect, #method_missing, #set, #with

Methods included from Api::Request

#delete_request, #get_request, #post_request, #put_request, #request

Methods included from Api::Connection

#connection

Methods included from Api::Authorization

#auth_code, #authenticate, #authenticated?, #authorize_url, #oauth, #token

Constructor Details

#initialize(attributes = {}) ⇒ Verification

Returns a new instance of Verification.



45
46
47
48
49
# File 'lib/webmaster/hosts/verification.rb', line 45

def initialize(attributes = {})
  super(attributes)

  self.state ||= 'never_verified'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Webmaster::Base

Instance Attribute Details

#hostObject

Returns the value of attribute host.



43
44
45
# File 'lib/webmaster/hosts/verification.rb', line 43

def host
  @host
end

Instance Method Details

#run(type) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
# File 'lib/webmaster/hosts/verification.rb', line 57

def run(type)
  raise ArgumentError if !CHECKABLE_TYPES.include?(type.underscore.downcase)

  # data = XML::Document.string("<host><type>#{type.underscore.upcase}</type></host>").to_s
  data = "<host><type>#{type.underscore.upcase}</type></host>"
  response = self.request(:put, self.host.resources[:verify_host], :data => data)
  # return true if response.status.to_i == 204
end

#state=(value) ⇒ Object



66
67
68
69
# File 'lib/webmaster/hosts/verification.rb', line 66

def state=(value)
  value = value.downcase.underscore
  @state = value if STATES.include?(value)
end

#type=(value) ⇒ Object



71
72
73
74
# File 'lib/webmaster/hosts/verification.rb', line 71

def type=(value)
  value = value.downcase.underscore
  @type = value if TYPES.include?(value)
end

#verified?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/webmaster/hosts/verification.rb', line 53

def verified?
  self.state == 'verified'
end