]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
8ebb1460c621dc953fae8e1d41462239dfa4e567
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require 'chef/mixin/command'
2
3 class Chef
4   module Wordpress
5     extend Chef::Mixin::Command
6
7     @api_responses = {}
8     @svn_responses = {}
9
10     def self.current_version
11       core_version_check["offers"].first["current"]
12     end
13
14     def self.current_plugin_version(name)
15       if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
16         $1
17       else
18         "trunk"
19       end
20     end
21
22   private
23
24     def self.core_version_check
25       api_get("http://api.wordpress.org/core/version-check/1.6")
26     end
27
28     def self.api_get(url)
29       @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
30     end
31
32     def self.svn_cat(url)
33       unless @svn_responses[url]
34         status, stdout, stderr = output_of_command("svn cat #{url}", {})
35         handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true)
36
37         @svn_responses[url] = stdout.force_encoding("UTF-8")
38       end
39
40       @svn_responses[url]
41     end
42   end
43 end