]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
dns: upgrade dnscontrol to 4.12.5
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/shell_out"
2
3 require "addressable"
4 require "httpclient"
5 require "json"
6
7 class Chef
8   module Wordpress
9     extend Chef::Mixin::ShellOut
10
11     @api_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         plugin_information(name)["version"]
20       end
21
22       private
23
24       def core_version_check
25         api_get("https://api.wordpress.org/core/version-check/1.7")
26       end
27
28       def plugin_information(name)
29         api_get("https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=#{name}")
30       end
31
32       def api_get(url)
33         @api_responses[url] ||= ::JSON.parse(::HTTPClient.new.get_content(url))
34       end
35     end
36   end
37 end