Class: Yandex::Webmaster::Host

Inherits:
Base show all
Extended by:
Forwardable
Defined in:
lib/yandex-webmaster/host.rb

Constant Summary

Constants included from Request

Request::METHODS, Request::METHODS_WITH_BODIES

Constants included from Connection

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

Instance Attribute Summary

Attributes inherited from Base

#configuration

Attributes included from Authorization

#scopes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attributes=, const_missing, define_attributes, #initialize, #method_missing

Methods included from Request

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

Methods included from Connection

#connection

Methods included from Authorization

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

Constructor Details

This class inherits a constructor from Yandex::Webmaster::Base

Dynamic Method Handling

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

Class Method Details

.create(name, factory) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/yandex-webmaster/host.rb', line 44

def self.create(name, factory)
  xml = "<host><name>#{name}</name></host>"
  response = factory.request(:post, '/hosts', xml)
  if response.status.to_i == 201
    self.new({
      :href => response.headers['Location'],
      :configuration => factory.configuration
    })          
  end
end

Instance Method Details

#deleteObject



78
79
80
81
82
# File 'lib/yandex-webmaster/host.rb', line 78

def delete            
  response = self.request(:delete, self.href)
  @deleted = true if response.status.to_i == 204        
  self
end

#deleted?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/yandex-webmaster/host.rb', line 86

def deleted?
  !!@deleted
end

#idInteger

Id of the host

Returns:

  • (Integer)


58
59
60
61
# File 'lib/yandex-webmaster/host.rb', line 58

def id
  return @id if defined?(@id)
  @id = self.href.match(/\/(\d+)\z/)[1].to_i
end


146
147
148
149
150
151
# File 'lib/yandex-webmaster/host.rb', line 146

def load_incoming_links
  self.validate_resource!(:incoming_links)

  self.attributes = self.request(:get, self.resources[:incoming_links]).body
  self
end

#load_indexed_urlsYandex::Webmaster::Host



134
135
136
137
138
139
# File 'lib/yandex-webmaster/host.rb', line 134

def load_indexed_urls
  self.validate_resource!(:indexed_urls)

  self.attributes = self.request(:get, self.resources[:indexed_urls]).body
  self
end

#load_sitemapsObject



175
176
177
178
179
180
# File 'lib/yandex-webmaster/host.rb', line 175

def load_sitemaps
  self.validate_resource!(:sitemaps)
  
  self.sitemaps = self.fetch_value(self.request(:get, self.resources[:sitemaps]), :sitemap)
  self
end

#load_statsYandex::Webmaster::Host



122
123
124
125
126
127
# File 'lib/yandex-webmaster/host.rb', line 122

def load_stats
  self.validate_resource!(:host_information)

  self.attributes = self.request(:get, self.resources[:host_information]).body
  self
end

#load_top_queriesYandex::Webmaster::Host



158
159
160
161
162
163
# File 'lib/yandex-webmaster/host.rb', line 158

def load_top_queries
  self.validate_resource!(:top_queries)

  self.attributes = self.fetch_value(self.request(:get, self.resources[:top_queries]), :top_queries)
  self        
end

#load_verificationObject



110
111
112
113
114
115
# File 'lib/yandex-webmaster/host.rb', line 110

def load_verification
  self.validate_resource!(:verify_host)

  self.verification = self.fetch_value(self.request(:get, self.resources[:verify_host]), :verification)
  self
end

#resourcesHash

Load information about resources that are available for the host

Returns:



66
67
68
69
70
71
72
# File 'lib/yandex-webmaster/host.rb', line 66

def resources
  return @resources if defined?(@resources)

  @resources = self.fetch_value(self.request(:get, self.href), :link).inject({}) do |h, resource|
    h[resource[:rel].underscore.to_sym] = resource[:href]; h        
  end
end

#sitemaps(reload = false) ⇒ Yandex::Webmaster::Host



170
171
172
173
# File 'lib/yandex-webmaster/host.rb', line 170

def sitemaps(reload = false)        
  self.load_sitemaps if reload || @sitemaps.nil?
  @sitemaps        
end

#verification(reload = false) ⇒ Yandex::Webmaster::Hosts::Verification



105
106
107
108
# File 'lib/yandex-webmaster/host.rb', line 105

def verification(reload = false)
  self.load_verification if reload || @verification.nil?
  @verification
end

#verify(type) ⇒ Object

Load information about verification for the host



92
93
94
95
96
97
98
99
# File 'lib/yandex-webmaster/host.rb', line 92

def verify(type)
  self.validate_resource!(:verify_host)

  status = self.verification.run(type)
  @verification = nil

  status
end