diff options
author | Steven Danna <steve@opscode.com> | 2015-01-22 15:53:15 +0000 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-09 21:19:44 -0500 |
commit | 8ffa43844287691e2b88287cab6033b35b723b40 (patch) | |
tree | ae30c5235ced13749a51efcee54b99f3d01e7d56 /lib/chef/api_client.rb | |
parent | 1a9681d4e65be2e194a5393d14102d696053bbff (diff) | |
download | chef-8ffa43844287691e2b88287cab6033b35b723b40.tar.gz |
Add ApiClient#from_hash and ApiClient#from_json
ApiClient#json_create confusingly takes a hash rather than a JSON
string. We need to preserve json_create for backwards compatibility.
from_hash is the same as json_create. from_json takes an actual
string of JSON.
Diffstat (limited to 'lib/chef/api_client.rb')
-rw-r--r-- | lib/chef/api_client.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index 334fb23f38..c27dfe82ba 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -124,14 +124,21 @@ class Chef Chef::JSONCompat.to_json(to_hash, *a) end - def self.json_create(o) - client = Chef::ApiClient.new - client.name(o["name"] || o["clientname"]) - client.private_key(o["private_key"]) if o.key?("private_key") - client.public_key(o["public_key"]) - client.admin(o["admin"]) - client.validator(o["validator"]) - client + class << self + def from_hash(o) + client = Chef::ApiClient.new + client.name(o["name"] || o["clientname"]) + client.private_key(o["private_key"]) if o.key?("private_key") + client.public_key(o["public_key"]) + client.admin(o["admin"]) + client.validator(o["validator"]) + client + end + alias :json_create :from_hash + + def from_json(j) + Chef::ApiClient.from_hash(Chef::JSONCompat.parse(j)) + end end def self.http_api |