Class: EasyPost::Referral
- Inherits:
-
Resource
- Object
- EasyPostObject
- Resource
- EasyPost::Referral
- Defined in:
- lib/easypost/referral.rb
Overview
Referral objects are User objects created from a Partner user.
Instance Attribute Summary
Attributes inherited from EasyPostObject
#api_key, #name, #parent, #unsaved_values
Class Method Summary collapse
-
.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add credit card to a referral customer.
-
.all(params = {}, api_key = nil) ⇒ Object
Retrieve a list of referral customers.
-
.build_next_page_params(_collection, current_page_items, page_size = nil) ⇒ Object
Build the next page parameters.
-
.create(params = {}, api_key = nil) ⇒ Object
Create a referral customer.
-
.get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of referral customers.
-
.update_email(email, user_id, api_key = nil) ⇒ Object
Update a referral customer.
Methods inherited from Resource
class_name, #delete, each, get_next_page_exec, #refresh, retrieve, #save, 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
.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add credit card to a referral customer. This function requires the Referral Customer’s API key.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/easypost/referral.rb', line 99 def self.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') easypost_stripe_api_key = retrieve_easypost_stripe_api_key begin stripe_credit_card_token = create_stripe_token( number, expiration_month, expiration_year, cvc, easypost_stripe_api_key, ) rescue StandardError raise EasyPost::Error.new('Could not send card details to Stripe, please try again later.') end response = create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority) EasyPost::Util.convert_to_easypost_object(response, referral_api_key) end |
.all(params = {}, api_key = nil) ⇒ Object
Retrieve a list of referral customers. This function requires the Partner User’s API key.
78 79 80 81 |
# File 'lib/easypost/referral.rb', line 78 def self.all(params = {}, api_key = nil) response = EasyPost.make_request(:get, '/v2/referral_customers', api_key, params) EasyPost::Util.convert_to_easypost_object(response, api_key) end |
.build_next_page_params(_collection, current_page_items, page_size = nil) ⇒ Object
Build the next page parameters.
89 90 91 92 93 94 95 96 |
# File 'lib/easypost/referral.rb', line 89 def self.build_next_page_params(_collection, current_page_items, page_size = nil) params = {} params[:before_id] = current_page_items.last.id unless page_size.nil? params[:page_size] = page_size end params end |
.create(params = {}, api_key = nil) ⇒ Object
Create a referral customer. This function requires the Partner User’s API key.
59 60 61 62 |
# File 'lib/easypost/referral.rb', line 59 def self.create(params = {}, api_key = nil) response = EasyPost.make_request(:post, '/v2/referral_customers', api_key, { user: params }) EasyPost::Util.convert_to_easypost_object(response, api_key) end |
.get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of referral customers.
84 85 86 |
# File 'lib/easypost/referral.rb', line 84 def self.get_next_page(collection, page_size = nil) get_next_page_exec(method(:all), collection, collection.referral_customers, page_size) end |
.update_email(email, user_id, api_key = nil) ⇒ Object
Update a referral customer. This function requires the Partner User’s API key.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/easypost/referral.rb', line 65 def self.update_email(email, user_id, api_key = nil) wrapped_params = { user: { email: email, }, } EasyPost.make_request(:put, "/v2/referral_customers/#{user_id}", api_key, wrapped_params) # return true if API succeeds, else an error is throw if it fails. true end |