yandex-webmaster 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.document +5 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +72 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +259 -0
  6. data/Rakefile +46 -0
  7. data/lib/yandex-webmaster.rb +80 -0
  8. data/lib/yandex-webmaster/api/attributes.rb +23 -0
  9. data/lib/yandex-webmaster/api/attributes/accessor_builder.rb +59 -0
  10. data/lib/yandex-webmaster/api/attributes/reader_builder.rb +35 -0
  11. data/lib/yandex-webmaster/api/attributes/types/base.rb +27 -0
  12. data/lib/yandex-webmaster/api/attributes/types/boolean.rb +22 -0
  13. data/lib/yandex-webmaster/api/attributes/types/date.rb +17 -0
  14. data/lib/yandex-webmaster/api/attributes/types/date_time.rb +17 -0
  15. data/lib/yandex-webmaster/api/attributes/types/float.rb +17 -0
  16. data/lib/yandex-webmaster/api/attributes/types/integer.rb +17 -0
  17. data/lib/yandex-webmaster/api/attributes/types/symbol.rb +17 -0
  18. data/lib/yandex-webmaster/api/attributes/types/time.rb +17 -0
  19. data/lib/yandex-webmaster/api/attributes/writer_builder.rb +36 -0
  20. data/lib/yandex-webmaster/api/attributes_builder.rb +65 -0
  21. data/lib/yandex-webmaster/api_factory.rb +32 -0
  22. data/lib/yandex-webmaster/authorization.rb +59 -0
  23. data/lib/yandex-webmaster/base.rb +120 -0
  24. data/lib/yandex-webmaster/client.rb +16 -0
  25. data/lib/yandex-webmaster/configuration.rb +99 -0
  26. data/lib/yandex-webmaster/connection.rb +87 -0
  27. data/lib/yandex-webmaster/core_ext/array.rb +23 -0
  28. data/lib/yandex-webmaster/core_ext/class.rb +55 -0
  29. data/lib/yandex-webmaster/core_ext/date.rb +7 -0
  30. data/lib/yandex-webmaster/core_ext/date_time.rb +7 -0
  31. data/lib/yandex-webmaster/core_ext/hash.rb +92 -0
  32. data/lib/yandex-webmaster/core_ext/nil_class.rb +7 -0
  33. data/lib/yandex-webmaster/core_ext/object.rb +19 -0
  34. data/lib/yandex-webmaster/core_ext/string.rb +23 -0
  35. data/lib/yandex-webmaster/errors.rb +23 -0
  36. data/lib/yandex-webmaster/host.rb +220 -0
  37. data/lib/yandex-webmaster/hosts/crawling.rb +26 -0
  38. data/lib/yandex-webmaster/hosts/sitemap.rb +73 -0
  39. data/lib/yandex-webmaster/hosts/sitemap_info.rb +55 -0
  40. data/lib/yandex-webmaster/hosts/top_info.rb +19 -0
  41. data/lib/yandex-webmaster/hosts/verification.rb +81 -0
  42. data/lib/yandex-webmaster/request.rb +62 -0
  43. data/lib/yandex-webmaster/request/oauth2.rb +28 -0
  44. data/lib/yandex-webmaster/response/hashify.rb +59 -0
  45. data/lib/yandex-webmaster/version.rb +14 -0
  46. data/test/helper.rb +18 -0
  47. data/test/test_webmaster.rb +7 -0
  48. data/yandex-webmaster.gemspec +167 -0
  49. metadata +546 -0
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module Yandex
4
+ module Webmaster
5
+ module Hosts
6
+ class TopInfo < Base
7
+
8
+ define_attributes :as => 'api_attributes' do
9
+ attr :query, String, :writer => :protected
10
+ attr :count, Integer, :writer => :protected
11
+ attr :position, Integer, :writer => :protected
12
+ attr :is_custom, Boolean, :writer => :protected
13
+ end
14
+
15
+ attr_accessor :host
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ require 'xml/libxml'
4
+
5
+ module Yandex
6
+ module Webmaster
7
+ module Hosts
8
+ class Verification < Base
9
+
10
+ STATES = [
11
+ 'in_progress',
12
+ 'never_verified',
13
+ 'verification_failed',
14
+ 'verified',
15
+ 'waiting'
16
+ ].freeze
17
+
18
+ CHECKABLE_TYPES = [
19
+ 'dns_record',
20
+ 'html_file',
21
+ 'meta_tag',
22
+ 'txt_file',
23
+ 'whois'
24
+ ].freeze
25
+
26
+ NON_CHECKABLE_TYPES = [
27
+ 'auto',
28
+ 'manual',
29
+ 'pdd',
30
+ 'pdd_external',
31
+ 'delegation'
32
+ ].freeze
33
+
34
+ TYPES = (CHECKABLE_TYPES + NON_CHECKABLE_TYPES).flatten.freeze
35
+
36
+ define_attributes :as => 'api_attributes' do
37
+ attr :state, String, :writer => :protected
38
+ attr :type, String, :writer => :protected
39
+ attr :possible_to_cancel, Boolean, :writer => :protected
40
+ attr :date, Date, :writer => :protected
41
+ attr :uin, String, :writer => :protected
42
+ end
43
+
44
+ attr_accessor :host
45
+
46
+ def initialize(attributes = {})
47
+ super(attributes)
48
+
49
+ self.state ||= 'never_verified'
50
+ end
51
+
52
+ # @return [Boolean]
53
+ #
54
+ def verified?
55
+ self.state == 'verified'
56
+ end
57
+
58
+ def run(type)
59
+ raise ArgumentError if !CHECKABLE_TYPES.include?(type.to_s.underscore.downcase)
60
+
61
+ # data = XML::Document.string("<host><type>#{type.underscore.upcase}</type></host>").to_s
62
+ data = "<host><type>#{type.to_s.underscore.upcase}</type></host>"
63
+ response = self.request(:put, self.host.resources[:verify_host], :data => data)
64
+ # return true if response.status.to_i == 204
65
+ end
66
+
67
+ protected
68
+
69
+ def state=(value)
70
+ value = value.downcase.underscore
71
+ @state = value if STATES.include?(value)
72
+ end
73
+
74
+ def type=(value)
75
+ value = value.downcase.underscore
76
+ @type = value if TYPES.include?(value)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ module Yandex
4
+ module Webmaster
5
+
6
+ # Defines HTTP verbs
7
+ module Request
8
+
9
+ METHODS = [:get, :post, :put, :delete]
10
+ METHODS_WITH_BODIES = [:post, :put]
11
+
12
+ def get_request(path, params={}, options={})
13
+ request(:get, path, params, options)
14
+ end
15
+
16
+ def post_request(path, params={}, options={})
17
+ request(:post, path, params, options)
18
+ end
19
+
20
+ def put_request(path, params={}, options={})
21
+ request(:put, path, params, options)
22
+ end
23
+
24
+ def delete_request(path, params={}, options={})
25
+ request(:delete, path, params, options)
26
+ end
27
+
28
+ def request(method, path, params = {}, options = {})
29
+ if !METHODS.include?(method)
30
+ raise ArgumentError, "unkown http method: #{method}"
31
+ end
32
+
33
+ puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
34
+
35
+ conn = connection(options)
36
+ if conn.path_prefix != '/' && path.index(conn.path_prefix) != 0 && !path.start_with?('https://', 'http://')
37
+ path = (conn.path_prefix + path).gsub(/\/(\/)*/, '/')
38
+ end
39
+
40
+ response = conn.send(method) do |request|
41
+ case method.to_sym
42
+ when *(METHODS - METHODS_WITH_BODIES)
43
+ request.body = params.delete('data') if params.has_key?('data')
44
+ request.url(path, params)
45
+ when *METHODS_WITH_BODIES
46
+ request.url(path)
47
+ request.body = self.extract_data_from_params(params) unless params.empty?
48
+ request.headers['Content-Length'] = request.body.size.to_s
49
+ end
50
+ end
51
+ end
52
+
53
+ protected
54
+
55
+ def extract_data_from_params(params) # :nodoc:
56
+ return params['data'] if params.is_a?(Hash) && params.has_key?('data') && !params['data'].nil?
57
+ return params[:data] if params.is_a?(Hash) && params.has_key?(:data) && !params[:data].nil?
58
+ return params
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'faraday'
4
+
5
+ module Yandex
6
+ module Webmaster
7
+ module Request
8
+ class OAuth2 < Faraday::Middleware
9
+
10
+ AUTH_HEADER = 'Authorization'.freeze
11
+
12
+ dependency 'oauth2'
13
+
14
+ def call(env)
15
+ env[:request_headers].merge!(AUTH_HEADER => "OAuth #{@token}") if @token.present?
16
+
17
+ @app.call env
18
+ end
19
+
20
+ def initialize(app, *args)
21
+ super app
22
+ @app = app
23
+ @token = args.shift
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'faraday'
4
+ require 'xml/libxml'
5
+
6
+ module Yandex
7
+ module Webmaster
8
+ class Response::Hashify < Faraday::Response::Middleware
9
+ def parse(body)
10
+ self.from_xml(body) if body.present?
11
+ end
12
+
13
+ def from_xml(xml, strict = true)
14
+ begin
15
+ XML.default_load_external_dtd = false
16
+ XML.default_pedantic_parser = strict
17
+ result = XML::Parser.string(xml).parse
18
+ return xml_node_to_hash(result.root)
19
+ rescue Exception => e
20
+ # raise custom exception here
21
+ end
22
+ end
23
+
24
+ def xml_node_to_hash(node)
25
+ if node.element?
26
+ if node.children? || node.attributes?
27
+ result_hash = {}
28
+
29
+ node.each_child do |child|
30
+ result = xml_node_to_hash(child)
31
+
32
+ if child.name == "text"
33
+ return result if !child.next? && !child.prev? && result.present?
34
+ elsif result_hash[child.name.underscore.to_sym] && result.present?
35
+ if result_hash[child.name.underscore.to_sym].is_a?(Object::Array)
36
+ result_hash[child.name.underscore.to_sym] << result
37
+ else
38
+ result_hash[child.name.underscore.to_sym] = [result_hash[child.name.underscore.to_sym]] << result
39
+ end
40
+ elsif result.present?
41
+ result_hash[child.name.underscore.to_sym] = result
42
+ end
43
+ end
44
+
45
+ node.each_attr do |attr|
46
+ result_hash[attr.name.underscore.to_sym] = attr.value
47
+ end
48
+
49
+ return result_hash
50
+ else
51
+ return nil
52
+ end
53
+ else
54
+ return node.content.to_s
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ module Yandex
4
+ module Webmaster
5
+ module Version
6
+ MAJOR = 0
7
+ MINOR = 1
8
+ PATCH = 1
9
+ BUILD = nil
10
+
11
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'webmaster'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWebmaster < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,167 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "yandex-webmaster"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Igor Alexandrov"]
12
+ s.date = "2013-05-12"
13
+ s.email = "igor.alexandrov@gmail.com"
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "lib/yandex-webmaster.rb",
26
+ "lib/yandex-webmaster/api/attributes.rb",
27
+ "lib/yandex-webmaster/api/attributes/accessor_builder.rb",
28
+ "lib/yandex-webmaster/api/attributes/reader_builder.rb",
29
+ "lib/yandex-webmaster/api/attributes/types/base.rb",
30
+ "lib/yandex-webmaster/api/attributes/types/boolean.rb",
31
+ "lib/yandex-webmaster/api/attributes/types/date.rb",
32
+ "lib/yandex-webmaster/api/attributes/types/date_time.rb",
33
+ "lib/yandex-webmaster/api/attributes/types/float.rb",
34
+ "lib/yandex-webmaster/api/attributes/types/integer.rb",
35
+ "lib/yandex-webmaster/api/attributes/types/symbol.rb",
36
+ "lib/yandex-webmaster/api/attributes/types/time.rb",
37
+ "lib/yandex-webmaster/api/attributes/writer_builder.rb",
38
+ "lib/yandex-webmaster/api/attributes_builder.rb",
39
+ "lib/yandex-webmaster/api_factory.rb",
40
+ "lib/yandex-webmaster/authorization.rb",
41
+ "lib/yandex-webmaster/base.rb",
42
+ "lib/yandex-webmaster/client.rb",
43
+ "lib/yandex-webmaster/configuration.rb",
44
+ "lib/yandex-webmaster/connection.rb",
45
+ "lib/yandex-webmaster/core_ext/array.rb",
46
+ "lib/yandex-webmaster/core_ext/class.rb",
47
+ "lib/yandex-webmaster/core_ext/date.rb",
48
+ "lib/yandex-webmaster/core_ext/date_time.rb",
49
+ "lib/yandex-webmaster/core_ext/hash.rb",
50
+ "lib/yandex-webmaster/core_ext/nil_class.rb",
51
+ "lib/yandex-webmaster/core_ext/object.rb",
52
+ "lib/yandex-webmaster/core_ext/string.rb",
53
+ "lib/yandex-webmaster/errors.rb",
54
+ "lib/yandex-webmaster/host.rb",
55
+ "lib/yandex-webmaster/hosts/crawling.rb",
56
+ "lib/yandex-webmaster/hosts/sitemap.rb",
57
+ "lib/yandex-webmaster/hosts/sitemap_info.rb",
58
+ "lib/yandex-webmaster/hosts/top_info.rb",
59
+ "lib/yandex-webmaster/hosts/verification.rb",
60
+ "lib/yandex-webmaster/request.rb",
61
+ "lib/yandex-webmaster/request/oauth2.rb",
62
+ "lib/yandex-webmaster/response/hashify.rb",
63
+ "lib/yandex-webmaster/version.rb",
64
+ "test/helper.rb",
65
+ "test/test_webmaster.rb",
66
+ "yandex-webmaster.gemspec"
67
+ ]
68
+ s.homepage = "http://github.com/igor-alexandrov/yandex-webmaster"
69
+ s.licenses = ["MIT"]
70
+ s.require_paths = ["lib"]
71
+ s.rubygems_version = "1.8.24"
72
+ s.summary = "Ruby wrapper for Yandex.Webmaster API"
73
+
74
+ if s.respond_to? :specification_version then
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
79
+ s.add_runtime_dependency(%q<oauth2>, [">= 0"])
80
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 0"])
81
+ s.add_runtime_dependency(%q<yandex-webmaster>, [">= 0"])
82
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
83
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
84
+ s.add_development_dependency(%q<bundler>, [">= 0"])
85
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
86
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
87
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
88
+ s.add_development_dependency(%q<bundler>, [">= 0"])
89
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
90
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
91
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
92
+ s.add_development_dependency(%q<bundler>, [">= 0"])
93
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
94
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
95
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
96
+ s.add_development_dependency(%q<bundler>, [">= 0"])
97
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
98
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
99
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
100
+ s.add_development_dependency(%q<bundler>, [">= 0"])
101
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
102
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
103
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
104
+ s.add_development_dependency(%q<bundler>, [">= 0"])
105
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
106
+ else
107
+ s.add_dependency(%q<faraday>, [">= 0"])
108
+ s.add_dependency(%q<oauth2>, [">= 0"])
109
+ s.add_dependency(%q<libxml-ruby>, [">= 0"])
110
+ s.add_dependency(%q<yandex-webmaster>, [">= 0"])
111
+ s.add_dependency(%q<shoulda>, [">= 0"])
112
+ s.add_dependency(%q<rdoc>, [">= 0"])
113
+ s.add_dependency(%q<bundler>, [">= 0"])
114
+ s.add_dependency(%q<jeweler>, [">= 0"])
115
+ s.add_dependency(%q<shoulda>, [">= 0"])
116
+ s.add_dependency(%q<rdoc>, [">= 0"])
117
+ s.add_dependency(%q<bundler>, [">= 0"])
118
+ s.add_dependency(%q<jeweler>, [">= 0"])
119
+ s.add_dependency(%q<shoulda>, [">= 0"])
120
+ s.add_dependency(%q<rdoc>, [">= 0"])
121
+ s.add_dependency(%q<bundler>, [">= 0"])
122
+ s.add_dependency(%q<jeweler>, [">= 0"])
123
+ s.add_dependency(%q<shoulda>, [">= 0"])
124
+ s.add_dependency(%q<rdoc>, [">= 0"])
125
+ s.add_dependency(%q<bundler>, [">= 0"])
126
+ s.add_dependency(%q<jeweler>, [">= 0"])
127
+ s.add_dependency(%q<shoulda>, [">= 0"])
128
+ s.add_dependency(%q<rdoc>, [">= 0"])
129
+ s.add_dependency(%q<bundler>, [">= 0"])
130
+ s.add_dependency(%q<jeweler>, [">= 0"])
131
+ s.add_dependency(%q<shoulda>, [">= 0"])
132
+ s.add_dependency(%q<rdoc>, [">= 0"])
133
+ s.add_dependency(%q<bundler>, [">= 0"])
134
+ s.add_dependency(%q<jeweler>, [">= 0"])
135
+ end
136
+ else
137
+ s.add_dependency(%q<faraday>, [">= 0"])
138
+ s.add_dependency(%q<oauth2>, [">= 0"])
139
+ s.add_dependency(%q<libxml-ruby>, [">= 0"])
140
+ s.add_dependency(%q<yandex-webmaster>, [">= 0"])
141
+ s.add_dependency(%q<shoulda>, [">= 0"])
142
+ s.add_dependency(%q<rdoc>, [">= 0"])
143
+ s.add_dependency(%q<bundler>, [">= 0"])
144
+ s.add_dependency(%q<jeweler>, [">= 0"])
145
+ s.add_dependency(%q<shoulda>, [">= 0"])
146
+ s.add_dependency(%q<rdoc>, [">= 0"])
147
+ s.add_dependency(%q<bundler>, [">= 0"])
148
+ s.add_dependency(%q<jeweler>, [">= 0"])
149
+ s.add_dependency(%q<shoulda>, [">= 0"])
150
+ s.add_dependency(%q<rdoc>, [">= 0"])
151
+ s.add_dependency(%q<bundler>, [">= 0"])
152
+ s.add_dependency(%q<jeweler>, [">= 0"])
153
+ s.add_dependency(%q<shoulda>, [">= 0"])
154
+ s.add_dependency(%q<rdoc>, [">= 0"])
155
+ s.add_dependency(%q<bundler>, [">= 0"])
156
+ s.add_dependency(%q<jeweler>, [">= 0"])
157
+ s.add_dependency(%q<shoulda>, [">= 0"])
158
+ s.add_dependency(%q<rdoc>, [">= 0"])
159
+ s.add_dependency(%q<bundler>, [">= 0"])
160
+ s.add_dependency(%q<jeweler>, [">= 0"])
161
+ s.add_dependency(%q<shoulda>, [">= 0"])
162
+ s.add_dependency(%q<rdoc>, [">= 0"])
163
+ s.add_dependency(%q<bundler>, [">= 0"])
164
+ s.add_dependency(%q<jeweler>, [">= 0"])
165
+ end
166
+ end
167
+