Class: EasyPost::User
- Inherits:
-
Resource
- Object
- EasyPostObject
- Resource
- EasyPost::User
- Defined in:
- lib/easypost/user.rb
Overview
The User object can be used to manage your own account and to create child accounts.
Instance Attribute Summary
Attributes inherited from EasyPostObject
#api_key, #name, #parent, #unsaved_values
Class Method Summary collapse
-
.all_api_keys ⇒ Object
Retrieve a list of ApiKey objects.
-
.create(params = {}, api_key = nil) ⇒ Object
Create a child User.
-
.retrieve_me ⇒ Object
Retrieve the authenticated User.
Instance Method Summary collapse
-
#api_keys ⇒ Object
Retrieve a list of ApiKey objects of a child User.
-
#delete ⇒ Object
Delete a User.
-
#save ⇒ Object
Save (update) a User.
-
#update_brand(**attrs) ⇒ Object
Update the Brand of a User.
Methods inherited from Resource
all, class_name, each, #refresh, retrieve, url, #url
Methods inherited from EasyPostObject
#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values
Constructor Details
This class inherits a constructor from EasyPost::EasyPostObject
Class Method Details
.all_api_keys ⇒ Object
Retrieve a list of ApiKey objects.
37 38 39 |
# File 'lib/easypost/user.rb', line 37 def self.all_api_keys EasyPost::ApiKey.all end |
.create(params = {}, api_key = nil) ⇒ Object
Create a child User.
6 7 8 9 |
# File 'lib/easypost/user.rb', line 6 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 |
.retrieve_me ⇒ Object
Retrieve the authenticated User.
32 33 34 |
# File 'lib/easypost/user.rb', line 32 def self.retrieve_me all end |
Instance Method Details
#api_keys ⇒ Object
Retrieve a list of ApiKey objects of a child User.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/easypost/user.rb', line 42 def api_keys api_keys = EasyPost::User.all_api_keys if api_keys.id == id my_api_keys = api_keys.keys else api_keys.children.each do |child| if child.id == id my_api_keys = child.keys break end end end my_api_keys end |
#delete ⇒ Object
Delete a User.
26 27 28 29 |
# File 'lib/easypost/user.rb', line 26 def delete EasyPost.make_request(:delete, url, @api_key) self end |
#save ⇒ Object
Save (update) a User.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/easypost/user.rb', line 12 def save if @unsaved_values.length.positive? values = {} @unsaved_values.each { |k| values[k] = @values[k] } wrapped_params = { user: values } response = EasyPost.make_request(:put, url, @api_key, wrapped_params) refresh_from(response, api_key) end self end |
#update_brand(**attrs) ⇒ Object
Update the Brand of a User.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/easypost/user.rb', line 60 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 |