]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Convert more URLs to https
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/shell_out"
2
3 require "httpclient"
4 require "php_serialize"
5
6 class Chef
7   module Wordpress
8     extend Chef::Mixin::ShellOut
9
10     @api_responses = {}
11     @svn_responses = {}
12
13     class << self
14       def current_version
15         core_version_check["offers"].first["current"]
16       end
17
18       def current_plugin_version(name)
19         if svn_cat("https://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
20           Regexp.last_match[1]
21         else
22           "trunk"
23         end
24       end
25
26       private
27
28       def core_version_check
29         api_get("https://api.wordpress.org/core/version-check/1.6")
30       end
31
32       def api_get(url)
33         @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
34       end
35
36       def svn_cat(url)
37         unless @svn_responses[url]
38           result = shell_out!("svn", "cat", url)
39
40           @svn_responses[url] = result.stdout.force_encoding("UTF-8")
41         end
42
43         @svn_responses[url]
44       end
45     end
46   end
47 end