easypost 4.7.1 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33802b8af58e7efc3e5592c6559dd48dfa5a58cc9338f719c78bc97639f73c51
4
- data.tar.gz: 1ec9df3da15eb1169817db4d3610f78826388836995615ec928a80d60e17fcf1
3
+ metadata.gz: d6f62b9504efc5502cea14eb8c0ec792fe8c2987d857aedc34522663f2587706
4
+ data.tar.gz: e8c927c3ee7d01bc7a4d1d42c9cc6c1360ea082c66017bdf31c6399d503753fe
5
5
  SHA512:
6
- metadata.gz: 8f66b559d5f34005ad16151f3b32b168254efaff625ab06eba13a97ebe1aade1ff40f3d281fed9f32f80016bf662337be2053dc9a74d0f748bff47c67c3f6dd8
7
- data.tar.gz: a22e6a0c850f686807aae90db0d81a24f963c045e043dbd497a5078b9b4f5806124782906d78b3e30b760a13cd78daf9c99b4252c58760205d5b7364472f3310
6
+ metadata.gz: 7a731d243163def53e558f86191f992156ad50d2da7ed35f8993ae3b4f01298cacf99f5c507df44f420f856bd6c7c87b1f0965e98bd5f2719f7ebc048a383cd1
7
+ data.tar.gz: c79fb8e2236b550a0ca7925674f685054262bf0a88dda6dbd5582ad74828e85bb5268d188656513feb6e8cdf164792eb0f646ca436cb2d67d95b83c6f5be9906
@@ -32,6 +32,7 @@ jobs:
32
32
  uses: ruby/setup-ruby@v1
33
33
  with:
34
34
  ruby-version: "3.1"
35
+ bundler-cache: true
35
36
  - name: Install Dependencies
36
37
  run: make install
37
38
  - name: Lint Project
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  inherit_from: easycop.yml
2
2
 
3
+ AllCops:
4
+ SuggestExtensions: false
3
5
  # We are ignoring RSpec/FilePath because Simplecov doesn't play nice with nested spec files
4
6
  RSpec/FilePath:
5
7
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.8.0 (2022-09-21)
4
+
5
+ - Adds support to buy a shipment by passing in `end_shipper_id`
6
+ - `with_carbon_offset` can now alternatively be passed in the `params` parameter of the `shipment.buy` function
7
+ - Migrates Partner White Label (Referrals) to general library namespace and deprecates beta functions
8
+
3
9
  ## v4.7.1 (2022-09-06)
4
10
 
5
11
  - Makes not implemented `all` calls match the `EasyPost::Resource` interface so that one can call `.to_json` on them and receive the proper error
data/Makefile CHANGED
@@ -14,7 +14,7 @@ clean:
14
14
 
15
15
  ## fix - Fix Rubocop errors
16
16
  fix:
17
- rubocop -A
17
+ bundle exec rubocop -A
18
18
 
19
19
  ## install - Install globally from source
20
20
  install:
@@ -24,7 +24,7 @@ install:
24
24
 
25
25
  ## lint - Lint the project
26
26
  lint:
27
- rubocop
27
+ bundle exec rubocop
28
28
 
29
29
  ## publish - Publishes the built gem to Rubygems
30
30
  publish:
@@ -37,7 +37,7 @@ release:
37
37
 
38
38
  ## scan - Runs security analysis on the project with Brakeman
39
39
  scan:
40
- brakeman lib --force
40
+ bundle exec brakeman lib --force
41
41
 
42
42
  ## test - Test the project
43
43
  test:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.7.1
1
+ 4.8.0
@@ -2,6 +2,7 @@
2
2
 
3
3
  # EndShipper objects are fully-qualified Address objects that require all parameters and get verified upon creation.
4
4
  class EasyPost::Beta::EndShipper < EasyPost::Resource
5
+ # Create an EndShipper object.
5
6
  # <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
6
7
  def self.create(params = {}, api_key = nil)
7
8
  warn '[DEPRECATION] Please use `EndShipper.create` in the main namespace instead.'
@@ -10,6 +11,7 @@ class EasyPost::Beta::EndShipper < EasyPost::Resource
10
11
  end
11
12
 
12
13
  # Retrieves an EndShipper object.
14
+ # <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
13
15
  def self.retrieve(id, params = {}, api_key = nil)
14
16
  warn '[DEPRECATION] Please use `EndShipper.retrieve` in the main namespace instead.'
15
17
  response = EasyPost.make_request(:get, "/beta/end_shippers/#{id}", api_key, params)
@@ -17,6 +19,7 @@ class EasyPost::Beta::EndShipper < EasyPost::Resource
17
19
  end
18
20
 
19
21
  # Retrieves a list of EndShipper objects.
22
+ # <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
20
23
  def self.all(params = {}, api_key = nil)
21
24
  warn '[DEPRECATION] Please use `EndShipper.all` in the main namespace instead.'
22
25
  response = EasyPost.make_request(:get, '/beta/end_shippers', api_key, params)
@@ -24,6 +27,7 @@ class EasyPost::Beta::EndShipper < EasyPost::Resource
24
27
  end
25
28
 
26
29
  # Updates (saves) an EndShipper object. This requires all parameters to be set.
30
+ # <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
27
31
  def save
28
32
  warn '[DEPRECATION] Please use `endShipper.save` in the main namespace instead.'
29
33
  if @unsaved_values.length.positive?
@@ -3,13 +3,17 @@
3
3
  # Referral objects are User objects created from a Partner user.
4
4
  class EasyPost::Beta::Referral < EasyPost::Resource
5
5
  # Create a referral user. This function requires the Partner User's API key.
6
+ # <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
6
7
  def self.create(params = {}, api_key = nil)
8
+ warn '[DEPRECATION] Please use `EndShipper.create` in the main namespace instead.'
7
9
  response = EasyPost.make_request(:post, '/beta/referral_customers', api_key, { user: params })
8
10
  EasyPost::Util.convert_to_easypost_object(response, api_key)
9
11
  end
10
12
 
11
13
  # Update a referral user. This function requires the Partner User's API key.
14
+ # <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
12
15
  def self.update_email(email, user_id, api_key = nil)
16
+ warn '[DEPRECATION] Please use `EndShipper.update_email` in the main namespace instead.'
13
17
  wrapped_params = {
14
18
  user: {
15
19
  email: email,
@@ -22,13 +26,17 @@ class EasyPost::Beta::Referral < EasyPost::Resource
22
26
  end
23
27
 
24
28
  # Retrieve a list of referral users. This function requires the Partner User's API key.
29
+ # <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
25
30
  def self.all(params = {}, api_key = nil)
31
+ warn '[DEPRECATION] Please use `EndShipper.all` in the main namespace instead.'
26
32
  response = EasyPost.make_request(:get, '/beta/referral_customers', api_key, params)
27
33
  EasyPost::Util.convert_to_easypost_object(response, api_key)
28
34
  end
29
35
 
30
36
  # Add credit card to a referral user. This function requires the Referral User's API key.
37
+ # <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
31
38
  def self.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary')
39
+ warn '[DEPRECATION] Please use `EndShipper.add_credit_card` in the main namespace instead.'
32
40
  easypost_stripe_api_key = retrieve_easypost_stripe_api_key
33
41
 
34
42
  begin
@@ -48,13 +56,14 @@ class EasyPost::Beta::Referral < EasyPost::Resource
48
56
  end
49
57
 
50
58
  # Retrieve EasyPost's Stripe public API key.
51
- def self.retrieve_easypost_stripe_api_key
59
+ private_class_method def self.retrieve_easypost_stripe_api_key
52
60
  response = EasyPost.make_request(:get, '/beta/partners/stripe_public_key', @api_key)
53
61
  response['public_key']
54
62
  end
55
63
 
56
64
  # Get credit card token from Stripe.
57
- def self.create_stripe_token(number, expiration_month, expiration_year, cvc, easypost_stripe_token)
65
+ private_class_method def self.create_stripe_token(number, expiration_month, expiration_year,
66
+ cvc, easypost_stripe_token)
58
67
  headers = {
59
68
  # This Stripe endpoint only accepts URL form encoded bodies.
60
69
  Authorization: "Bearer #{easypost_stripe_token}",
@@ -84,7 +93,7 @@ class EasyPost::Beta::Referral < EasyPost::Resource
84
93
  end
85
94
 
86
95
  # Submit Stripe credit card token to EasyPost.
87
- def self.create_easypost_credit_card(referral_api_key, stripe_object_id, priority = 'primary')
96
+ private_class_method def self.create_easypost_credit_card(referral_api_key, stripe_object_id, priority = 'primary')
88
97
  wrapped_params = {
89
98
  credit_card: {
90
99
  stripe_object_id: stripe_object_id,
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Referral objects are User objects created from a Partner user.
4
+ class EasyPost::Referral < EasyPost::Resource
5
+ # Create a referral user. This function requires the Partner User's API key.
6
+ def self.create(params = {}, api_key = nil)
7
+ response = EasyPost.make_request(:post, '/v2/referral_customers', api_key, { user: params })
8
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
9
+ end
10
+
11
+ # Update a referral user. This function requires the Partner User's API key.
12
+ def self.update_email(email, user_id, api_key = nil)
13
+ wrapped_params = {
14
+ user: {
15
+ email: email,
16
+ },
17
+ }
18
+ EasyPost.make_request(:put, "/v2/referral_customers/#{user_id}", api_key, wrapped_params)
19
+
20
+ # return true if API succeeds, else an error is throw if it fails.
21
+ true
22
+ end
23
+
24
+ # Retrieve a list of referral users. This function requires the Partner User's API key.
25
+ def self.all(params = {}, api_key = nil)
26
+ response = EasyPost.make_request(:get, '/v2/referral_customers', api_key, params)
27
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
28
+ end
29
+
30
+ # Add credit card to a referral user. This function requires the Referral User's API key.
31
+ def self.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary')
32
+ easypost_stripe_api_key = retrieve_easypost_stripe_api_key
33
+
34
+ begin
35
+ stripe_credit_card_token = create_stripe_token(
36
+ number,
37
+ expiration_month,
38
+ expiration_year,
39
+ cvc,
40
+ easypost_stripe_api_key,
41
+ )
42
+ rescue StandardError
43
+ raise EasyPost::Error.new('Could not send card details to Stripe, please try again later.')
44
+ end
45
+
46
+ response = create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority)
47
+ EasyPost::Util.convert_to_easypost_object(response, referral_api_key)
48
+ end
49
+
50
+ # Retrieve EasyPost's Stripe public API key.
51
+ private_class_method def self.retrieve_easypost_stripe_api_key
52
+ response = EasyPost.make_request(:get, '/beta/partners/stripe_public_key', @api_key)
53
+ response['public_key']
54
+ end
55
+
56
+ # Get credit card token from Stripe.
57
+ private_class_method def self.create_stripe_token(number, expiration_month, expiration_year,
58
+ cvc, easypost_stripe_token)
59
+ headers = {
60
+ # This Stripe endpoint only accepts URL form encoded bodies.
61
+ Authorization: "Bearer #{easypost_stripe_token}",
62
+ 'Content-type': 'application/x-www-form-urlencoded',
63
+ }
64
+
65
+ credit_card_hash = {
66
+ card: {
67
+ number: number,
68
+ exp_month: expiration_month,
69
+ exp_year: expiration_year,
70
+ cvc: cvc,
71
+ },
72
+ }
73
+
74
+ form_encoded_params = EasyPost::Util.form_encode_params(credit_card_hash)
75
+
76
+ uri = URI.parse('https://api.stripe.com/v1/tokens')
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.use_ssl = true
79
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
80
+ query = URI.encode_www_form(form_encoded_params)
81
+
82
+ response = http.request(request, query)
83
+ response_json = JSON.parse(response.body)
84
+ response_json['id']
85
+ end
86
+
87
+ # Submit Stripe credit card token to EasyPost.
88
+ private_class_method def self.create_easypost_credit_card(referral_api_key, stripe_object_id, priority = 'primary')
89
+ wrapped_params = {
90
+ credit_card: {
91
+ stripe_object_id: stripe_object_id,
92
+ priority: priority,
93
+ },
94
+ }
95
+ response = EasyPost.make_request(:post, '/beta/credit_cards', referral_api_key, wrapped_params)
96
+ EasyPost::Util.convert_to_easypost_object(response, referral_api_key)
97
+ end
98
+ end
@@ -35,14 +35,23 @@ class EasyPost::Shipment < EasyPost::Resource
35
35
  end
36
36
 
37
37
  # Buy a Shipment.
38
- def buy(params = {}, with_carbon_offset = false)
38
+ def buy(params = {}, with_carbon_offset = false, end_shipper_id = nil)
39
39
  if params.instance_of?(EasyPost::Rate)
40
40
  temp = params.clone
41
41
  params = {}
42
42
  params[:rate] = temp
43
43
  end
44
44
 
45
- params[:carbon_offset] = with_carbon_offset
45
+ if params[:with_carbon_offset]
46
+ params[:carbon_offset] = params[:with_carbon_offset]
47
+ params.delete(:with_carbon_offset)
48
+ else
49
+ params[:carbon_offset] = with_carbon_offset
50
+ end
51
+
52
+ if end_shipper_id
53
+ params[:end_shipper_id] = end_shipper_id
54
+ end
46
55
 
47
56
  response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
48
57
  refresh_from(response, @api_key)
data/lib/easypost.rb CHANGED
@@ -30,6 +30,7 @@ require 'easypost/pickup_rate'
30
30
  require 'easypost/pickup'
31
31
  require 'easypost/postage_label'
32
32
  require 'easypost/rate'
33
+ require 'easypost/referral'
33
34
  require 'easypost/refund'
34
35
  require 'easypost/report'
35
36
  require 'easypost/scan_form'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.1
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - EasyPost Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brakeman
@@ -208,6 +208,7 @@ files:
208
208
  - lib/easypost/pickup_rate.rb
209
209
  - lib/easypost/postage_label.rb
210
210
  - lib/easypost/rate.rb
211
+ - lib/easypost/referral.rb
211
212
  - lib/easypost/refund.rb
212
213
  - lib/easypost/report.rb
213
214
  - lib/easypost/resource.rb