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,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'faraday'
4
+ gem 'oauth2'
5
+ gem 'libxml-ruby'
6
+
7
+ group :development do
8
+ gem "shoulda"
9
+ gem "rdoc"
10
+ gem "bundler"
11
+ gem "jeweler"
12
+ end
13
+
14
+ group :documentation do
15
+ gem "yard"
16
+ end
17
+
18
+ group :test do
19
+ gem 'vcr'
20
+ gem 'webmock'
21
+ end
22
+
23
+ gemspec
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yandex-webmaster (0.1.1)
5
+ faraday
6
+ libxml-ruby
7
+ oauth2
8
+ yandex-webmaster
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ activesupport (3.2.13)
14
+ i18n (= 0.6.1)
15
+ multi_json (~> 1.0)
16
+ addressable (2.3.4)
17
+ crack (0.3.2)
18
+ faraday (0.8.7)
19
+ multipart-post (~> 1.1)
20
+ git (1.2.5)
21
+ httpauth (0.2.0)
22
+ i18n (0.6.1)
23
+ jeweler (1.8.4)
24
+ bundler (~> 1.0)
25
+ git (>= 1.2.5)
26
+ rake
27
+ rdoc
28
+ json (1.7.7)
29
+ jwt (0.1.8)
30
+ multi_json (>= 1.5)
31
+ libxml-ruby (2.6.0)
32
+ multi_json (1.7.3)
33
+ multi_xml (0.5.3)
34
+ multipart-post (1.2.0)
35
+ oauth2 (0.9.1)
36
+ faraday (~> 0.8)
37
+ httpauth (~> 0.1)
38
+ jwt (~> 0.1.4)
39
+ multi_json (~> 1.0)
40
+ multi_xml (~> 0.5)
41
+ rack (~> 1.2)
42
+ rack (1.5.2)
43
+ rake (10.0.4)
44
+ rdoc (4.0.1)
45
+ json (~> 1.4)
46
+ shoulda (3.5.0)
47
+ shoulda-context (~> 1.0, >= 1.0.1)
48
+ shoulda-matchers (>= 1.4.1, < 3.0)
49
+ shoulda-context (1.1.1)
50
+ shoulda-matchers (2.1.0)
51
+ activesupport (>= 3.0.0)
52
+ vcr (2.4.0)
53
+ webmock (1.11.0)
54
+ addressable (>= 2.2.7)
55
+ crack (>= 0.3.2)
56
+ yard (0.8.6.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler
63
+ faraday
64
+ jeweler
65
+ libxml-ruby
66
+ oauth2
67
+ rdoc
68
+ shoulda
69
+ vcr
70
+ webmock
71
+ yandex-webmaster!
72
+ yard
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Igor Alexandrov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,259 @@
1
+ [![Dependency Status](https://gemnasium.com/igor-alexandrov/yandex-webmaster.png)](https://gemnasium.com/igor-alexandrov/yandex-webmaster)
2
+ [![Code Climate](https://codeclimate.com/github/igor-alexandrov/yandex-webmaster.png)](https://codeclimate.com/github/igor-alexandrov/yandex-webmaster)
3
+
4
+ # Yandex::Webmaster
5
+
6
+ Wrapper for Yandex.Webmaster API.
7
+
8
+ **About Yandex.Webmaster**
9
+
10
+ * [Russian](http://webmaster.yandex.ru/)
11
+ * [English](http://webmaster.yandex.com/)
12
+
13
+ **API Documentation**
14
+
15
+ * [Russian](http://api.yandex.ru/webmaster/)
16
+ * [English](http://api.yandex.com/webmaster/)
17
+
18
+ ## Installation
19
+
20
+ [sudo] gem install yandex-webmaster
21
+
22
+ ## Usage
23
+
24
+ ### Authentication
25
+
26
+ Yandex's API uses OAuth for authentication. Luckily, the Yandex::Webmaster gem hides most of the details from you.
27
+
28
+ If you have never used Webmaster API or you want to change your authentication credentials or your authorization token expired, then you should create new one:
29
+
30
+ ```ruby
31
+ require 'rubygems'
32
+ require 'yandex-webmaster'
33
+
34
+ # Get your API credentials at https://oauth.yandex.ru/
35
+ webmaster = Yandex::Webmaster.new(:app_id => 'your_app_id', :app_password => 'your_app_password')
36
+ => #<Yandex::Webmaster::Client>
37
+
38
+ # Follow the authorization url, you will be redirected to the callback url, specified in your application settings.
39
+ webmaster.authorize_url
40
+ => "https://oauth.yandex.ru/authorize?response_type=code&client_id=your_app_id"
41
+
42
+ # Use authorization code from params to get authorization token
43
+ webmaster.authenticate(params[:code])
44
+ => #<Yandex::Webmaster::Client>
45
+
46
+ # If no error is raised then you are free to use any API method
47
+ # Too see what token is now used call for client configuration
48
+ token = webmaster.configuration.oauth_token
49
+ => "82af4af2a42e4019bd59a325da0f31d8"
50
+ ```
51
+
52
+ If you want to restore previously used token, it can be easily done too:
53
+
54
+ ```ruby
55
+ require 'rubygems'
56
+ require 'yandex-webmaster'
57
+
58
+ # get your API credentials at https://oauth.yandex.ru/
59
+ webmaster = Yandex::Webmaster.new(:oauth_token => 'token')
60
+ => #<Yandex::Webmaster::Client>
61
+ ```
62
+
63
+ To check whether you client is authenticated or not, use `authenticated?` method.
64
+
65
+ ```ruby
66
+ # We have already initialized client before.
67
+ webmaster.authenticated?
68
+ => true
69
+ ```
70
+
71
+ ### Operations with the list of sites
72
+
73
+ **Get list of sites**
74
+
75
+ Most of Yandex::Webmaster loading methods are lazy, data will be actually loaded only when you really will need it.
76
+
77
+ ```ruby
78
+ webmaster.hosts
79
+ => #<Yandex::Webmaster::ApiFactory>
80
+ webmaster.hosts.all
81
+ => #<Array[Yandex::Webmaster::Host]>
82
+ # this does not really makes a query to API, list if hosts is cached.
83
+ webmaster.hosts.first
84
+ => #<Yandex::Webmaster::Host>
85
+ ```
86
+
87
+ To reload list of hosts, call `#host` method with explicitly passed `reload` parameter.
88
+
89
+ ```ruby
90
+ # makes call to API and caches list of hosts
91
+ webmaster.hosts(true).all
92
+ => #<Array[Yandex::Webmaster::Host]>
93
+ # clears cache and makes call to API again.
94
+ webmaster.hosts(true).first
95
+ => #<Yandex::Webmaster::Host>
96
+ ```
97
+
98
+ **Create site**
99
+ ```ruby
100
+ webmaster.hosts.create('hostname')
101
+ => #<Yandex::Webmaster::Host>
102
+ ```
103
+
104
+ ### Operations with a site
105
+
106
+ **Getting site resources**
107
+
108
+ You can easily find out what API methods are available for selected host.
109
+
110
+ ```ruby
111
+ h = webmaster.hosts.last
112
+ => #<Yandex::Webmaster::Host>
113
+
114
+ h.resources
115
+ => {:host_information => "https://webmaster.yandex.ru/api/v2/hosts/<host_id>/stats", :verify_host => "https://webmaster.yandex.ru/api/v2/hosts/<host_id>/verify" ... :excluded_urls_history => "https://webmaster.yandex.ru/api/v2/hosts/<host_id>/history/excluded-urls"}
116
+ ```
117
+
118
+ **Deleting a site**
119
+
120
+ ```ruby
121
+ h = webmaster.hosts.last
122
+ => #<Yandex::Webmaster::Host>
123
+
124
+ h.delete
125
+ => #<Yandex::Webmaster::Host>
126
+
127
+ h.deleted?
128
+ => true
129
+ ```
130
+
131
+ ### Operations with site statistics
132
+
133
+ Request refreshes following fields in Host:
134
+ * `#name`
135
+ * `#verification`
136
+ * `#crawling`
137
+ * `#virused`
138
+ * `#last_access`
139
+ * `#tic`
140
+ * `#url_count`
141
+ * `#index_count`
142
+
143
+ Also request populates the following fields:
144
+ * `#url_errors`
145
+ * `#internal_links_count`
146
+ * `#links_count`
147
+
148
+ ```ruby
149
+ h = webmaster.hosts.last
150
+ => #<Yandex::Webmaster::Host>
151
+
152
+ # Populates host instance with statistics information
153
+ h.load_stats
154
+ => #<Yandex::Webmaster::Host>
155
+
156
+ h.url_errors
157
+ => 379843
158
+ h.internal_links_count
159
+ => 52367
160
+ h.links_count
161
+ => 943
162
+ ```
163
+
164
+ ### Operations with Sitemap files
165
+
166
+ **Getting a list of Sitemap files**
167
+
168
+ ```ruby
169
+ # makes call to API and caches list of sitemaps for the host
170
+ webmaster.hosts.first.sitemaps
171
+ => #<Array[Yandex::Webmaster::Hosts::Sitemap]>
172
+ ```
173
+
174
+ To reload list of sitemaps for the host, call `#host` method with explicitly passed `reload` parameter.
175
+
176
+ ```ruby
177
+ webmaster.hosts.first.sitemaps(true)
178
+ => #<Array[Yandex::Webmaster::Hosts::Sitemap]>
179
+ ```
180
+
181
+ **Getting information about a site's Sitemap file**
182
+
183
+ To load detailed information about Sitemap file use `#load_details` method.
184
+
185
+ ```ruby
186
+ sitemap = webmaster.hosts.first.sitemaps.first
187
+ => #<Yandex::Webmaster::Hosts::Sitemap>
188
+ sitemap.load_details
189
+ => #<Yandex::Webmaster::Hosts::Sitemap>
190
+ ```
191
+
192
+ When details are loaded you can see Sitemap info.
193
+
194
+ ```ruby
195
+ sitemap.latest_info
196
+ => #<Yandex::Webmaster::Hosts::SitemapInfo>
197
+ sitemap.in_search_info
198
+ => #<Yandex::Webmaster::Hosts::SitemapInfo>
199
+ ```
200
+
201
+ **Removing a Sitemap**
202
+
203
+ ```ruby
204
+ sitemap = webmaster.hosts.first.sitemaps.first
205
+ => #<Yandex::Webmaster::Hosts::Sitemap>
206
+ sitemap.delete
207
+ => #<Yandex::Webmaster::Host>
208
+ sitemap.deleted?
209
+ => true
210
+ ```
211
+
212
+
213
+
214
+ ### Operations with site verification
215
+
216
+ Basic verification information is loaded with Host load.
217
+
218
+ For verified sites:
219
+
220
+ ```ruby
221
+ h = webmaster.hosts.last
222
+ => #<Yandex::Webmaster::Host>
223
+ h.verification
224
+ #<Yandex::Webmaster::Hosts::Verification state: "verified">
225
+ ```
226
+
227
+ And for not verified sites:
228
+
229
+ ```ruby
230
+ h = webmaster.hosts.create('http://www.tver.ru')
231
+ h.verification
232
+ => #<Yandex::Webmaster::Hosts::Verification state: "never_verified">
233
+ ```
234
+
235
+
236
+ ## Note on Patches / Pull Requests
237
+
238
+ * Fork the project.
239
+ * Make your feature addition or bug fix.
240
+ * Add tests for it. This is important so I don't break it in a
241
+ future version unintentionally.
242
+ * Commit, do not mess with rakefile, version, or history.
243
+ (if you want to have your own version, that is fine but
244
+ bump version in a commit by itself I can ignore when I pull)
245
+ * Send me a pull request. Bonus points for topic branches.
246
+
247
+ ## Credits
248
+
249
+ ![JetRockets](http://www.jetrockets.ru/public/logo.png)
250
+
251
+ Webmaster is maintained by [JetRockets](http://www.jetrockets.ru/en).
252
+
253
+ Contributors:
254
+
255
+ * [Igor Alexandrov](http://igor-alexandrov.github.com/)
256
+
257
+ ## License
258
+
259
+ It is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/yandex-webmaster/version.rb'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "yandex-webmaster"
19
+ gem.homepage = "http://github.com/igor-alexandrov/yandex-webmaster"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Ruby wrapper for Yandex.Webmaster API}
22
+ gem.email = "igor.alexandrov@gmail.com"
23
+ gem.authors = ["Igor Alexandrov"]
24
+ gem.version = Yandex::Webmaster::Version::STRING
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :install
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = Yandex::Webmaster::Version::STRING
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "yandex-webmaster #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
@@ -0,0 +1,80 @@
1
+ require 'yandex-webmaster/version'
2
+ require 'yandex-webmaster/configuration'
3
+ require 'yandex-webmaster/errors'
4
+
5
+ require 'yandex-webmaster/core_ext/array'
6
+ require 'yandex-webmaster/core_ext/class'
7
+ require 'yandex-webmaster/core_ext/date'
8
+ require 'yandex-webmaster/core_ext/date_time'
9
+ require 'yandex-webmaster/core_ext/hash'
10
+ require 'yandex-webmaster/core_ext/nil_class'
11
+ require 'yandex-webmaster/core_ext/object'
12
+ require 'yandex-webmaster/core_ext/string'
13
+
14
+
15
+ module Yandex
16
+ module Webmaster
17
+ class << self
18
+ # Alias for Yandex::Webmaster::Client.new
19
+ #
20
+ # @return [Yandex::Webmaster::Client]
21
+ def new(options = {}, &block)
22
+ Yandex::Webmaster::Client.new(:configuration => options, &block)
23
+ end
24
+
25
+ # Delegate to Yandex::Webmaster::Client
26
+ #
27
+ def method_missing(method, *args, &block)
28
+ return super unless new.respond_to?(method)
29
+ new.send(method, *args, &block)
30
+ end
31
+
32
+ def respond_to?(method, include_private = false)
33
+ new.respond_to?(method, include_private) || super(method, include_private)
34
+ end
35
+
36
+ # config/initializers/webmaster.rb (for instance)
37
+ #
38
+ # Yandex::Webmaster.configure do |config|
39
+ # config.application_id = 'application_id'
40
+ # config.application_password = 'application_password'
41
+ # end
42
+ #
43
+ # elsewhere
44
+ #
45
+ # client = Yandex::Webmaster::Client.new
46
+
47
+ def configure
48
+ yield self
49
+ true
50
+ end
51
+ end
52
+
53
+ autoload :Base, 'yandex-webmaster/base'
54
+ autoload :ApiFactory, 'yandex-webmaster/api_factory'
55
+ autoload :Client, 'yandex-webmaster/client'
56
+
57
+ autoload :Host, 'yandex-webmaster/host'
58
+
59
+ module Hosts
60
+ autoload :Crawling, 'yandex-webmaster/hosts/crawling'
61
+ autoload :Sitemap, 'yandex-webmaster/hosts/sitemap'
62
+ autoload :SitemapInfo, 'yandex-webmaster/hosts/sitemap_info'
63
+ autoload :TopInfo, 'yandex-webmaster/hosts/top_info'
64
+ autoload :Verification, 'yandex-webmaster/hosts/verification'
65
+ end
66
+
67
+ module Request
68
+ autoload :OAuth2, 'yandex-webmaster/request/oauth2'
69
+ end
70
+
71
+ module Response
72
+ autoload :Hashify, 'yandex-webmaster/response/hashify'
73
+ end
74
+
75
+ module Api
76
+ autoload :AttributesBuilder, 'yandex-webmaster/api/attributes_builder'
77
+ autoload :Attributes, 'yandex-webmaster/api/attributes'
78
+ end
79
+ end
80
+ end