Class: EasyPost::User

Inherits:
Resource show all
Defined in:
lib/easypost/user.rb

Instance Attribute Summary

Attributes inherited from EasyPostObject

#api_key, #name, #parent, #unsaved_values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

all, class_name, #delete, #refresh, retrieve, url, #url

Methods inherited from EasyPostObject

#[], #[]=, #as_json, construct_from, #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_keysObject



27
28
29
30
# File 'lib/easypost/user.rb', line 27

def self.all_api_keys
  response, api_key = EasyPost.request(:get, "/api_keys", @api_key)
  return Util.convert_to_easypost_object(response, api_key)
end

.create(params = {}, api_key = nil) ⇒ Object



3
4
5
6
7
8
# File 'lib/easypost/user.rb', line 3

def self.create(params={}, api_key=nil)
  wrapped_params = {}
  wrapped_params[self.class_name().to_sym] = params
  response, api_key = EasyPost.request(:post, self.url, api_key, wrapped_params, {}, false)
  return Util.convert_to_easypost_object(response, api_key)
end

.retrieve_meObject



23
24
25
# File 'lib/easypost/user.rb', line 23

def self.retrieve_me
  self.all
end

Instance Method Details

#api_keysObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/easypost/user.rb', line 32

def api_keys
  api_keys = EasyPost::User.all_api_keys

  if api_keys.id == self.id
    my_api_keys = api_keys.keys
  else
    for child in api_keys.children
      if child.id == self.id
        my_api_keys = child.keys
        break
      end
    end
  end

  my_api_keys
end

#saveObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/easypost/user.rb', line 10

def save
  if @unsaved_values.length > 0
    values = {}
    @unsaved_values.each { |k| values[k] = @values[k] }

    wrapped_params = {user: values}

    response, api_key = EasyPost.request(:put, url, @api_key, wrapped_params)
    refresh_from(response, api_key)
  end
  return self
end