]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Use chef image clone to ghcr to workaround docker hub limits
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "json"
2 require "net/http"
3
4 class Chef
5   module Wordpress
6     @api_responses = {}
7
8     class << self
9       def current_version
10         core_version_check["offers"].first["current"]
11       end
12
13       def current_plugin_version(name)
14         plugin_information(name)["version"]
15       end
16
17       private
18
19       def core_version_check
20         api_get("https://api.wordpress.org/core/version-check/1.7/")
21       end
22
23       def plugin_information(name)
24         api_get("https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=#{name}")
25       end
26
27       def api_get(url)
28         @api_responses[url] ||= ::JSON.parse(Net::HTTP.get(URI(url)))
29       end
30     end
31   end
32 end