diff --git a/lib/easypost.rb b/lib/easypost.rb index de0fcb66..c3b0897e 100644 --- a/lib/easypost.rb +++ b/lib/easypost.rb @@ -12,6 +12,7 @@ require "easypost/address" require "easypost/api_key" require "easypost/batch" +require "easypost/brand" require "easypost/carrier_account" require "easypost/carrier_type" require "easypost/customs_info" diff --git a/lib/easypost/brand.rb b/lib/easypost/brand.rb new file mode 100644 index 00000000..4c9c3c6c --- /dev/null +++ b/lib/easypost/brand.rb @@ -0,0 +1,9 @@ +class EasyPost::Brand < EasyPost::Resource + def url + if user_id.nil? || user_id.empty? + raise EasyPost::Error, "Missing user_id: #{self.class} instance is missing user_id" + end + + "#{::EasyPost::User.url}/#{CGI.escape(user_id)}/brand" + end +end diff --git a/lib/easypost/user.rb b/lib/easypost/user.rb index 5dbe6ee2..d60705a0 100644 --- a/lib/easypost/user.rb +++ b/lib/easypost/user.rb @@ -1,7 +1,7 @@ class EasyPost::User < EasyPost::Resource - def self.create(params={}, api_key=nil) - response = EasyPost.make_request(:post, self.url, api_key, {self.class_name.to_sym => params}) - return EasyPost::Util.convert_to_easypost_object(response, api_key) + def self.create(params = {}, api_key = nil) + response = EasyPost.make_request(:post, url, api_key, {class_name.to_sym => params}) + EasyPost::Util.convert_to_easypost_object(response, api_key) end def save @@ -14,11 +14,11 @@ def save response = EasyPost.make_request(:put, url, @api_key, wrapped_params) refresh_from(response, api_key) end - return self + self end def self.retrieve_me - self.all + all end def self.all_api_keys @@ -28,11 +28,11 @@ def self.all_api_keys def api_keys api_keys = EasyPost::User.all_api_keys - if api_keys.id == self.id + if api_keys.id == id my_api_keys = api_keys.keys else - for child in api_keys.children - if child.id == self.id + api_keys.children.each do |child| + if child.id == id my_api_keys = child.keys break end @@ -41,4 +41,16 @@ def api_keys my_api_keys end + + def update_brand(**attrs) + brand = EasyPost::Brand.new + data = {object: "Brand", user_id: id, **attrs} + # Add accessors manually because there's no API to retrieve a brand + brand.add_accessors(data.keys) + # Assigning values with accessors defined above + data.each do |key, val| + brand.send("#{key}=", val) + end + brand.save + end end