easypost 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9995cfcc5bc7cce1ebefa6343fc31ba18f6f0f4b36dfb7502225b7abb1b40f8
4
- data.tar.gz: 64d814764933ba53e3de2b01f39ba6fd2195a3a65ec4ec6c01b720078750fc42
3
+ metadata.gz: d6f62b9504efc5502cea14eb8c0ec792fe8c2987d857aedc34522663f2587706
4
+ data.tar.gz: e8c927c3ee7d01bc7a4d1d42c9cc6c1360ea082c66017bdf31c6399d503753fe
5
5
  SHA512:
6
- metadata.gz: 44179f3818dd5d9098eed96f3263b12a67dd7ec415c49fb9efc976b07b858e63ed326c68b0a07415a62da8311cd5b4e72c406bf6650e197ad69956c674b03d76
7
- data.tar.gz: 86007bac46665593dc205c9c231409698401af9b58da3d2d22049c0510b29528303a625c2be2945814ceffd7ee93838049dba5a8a34dcbf3afe3879f583cee80
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,9 +1,19 @@
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
+
9
+ ## v4.7.1 (2022-09-06)
10
+
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
12
+
3
13
  ## v4.7.0 (2022-08-25)
4
14
 
5
15
  - Moves EndShipper out of beta to the general library namespace
6
- - Ensure the Easypost object will respond to `.id` when it has one in @values
16
+ - Ensure the Easypost object will respond to `.id` when it has one in `@values`
7
17
 
8
18
  ## v4.6.0 (2022-08-02)
9
19
 
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.0
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,
@@ -3,7 +3,7 @@
3
3
  # CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping.
4
4
  class EasyPost::CustomsInfo < EasyPost::Resource
5
5
  # Retrieve a list of CustomsInfo objects
6
- def self.all
6
+ def self.all(_filters = {}, _api_key = nil)
7
7
  raise NotImplementedError.new('CustomsInfo.all not implemented.')
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  # A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object.
4
4
  class EasyPost::CustomsItem < EasyPost::Resource
5
5
  # Retrieve a list of CustomsItem objects
6
- def self.all
6
+ def self.all(_filters = {}, _api_key = nil)
7
7
  raise NotImplementedError.new('CustomsItem.all not implemented.')
8
8
  end
9
9
  end
@@ -26,7 +26,7 @@ class EasyPost::Order < EasyPost::Resource
26
26
  end
27
27
 
28
28
  # Retrieve a list of Order objects.
29
- def self.all
29
+ def self.all(_filters = {}, _api_key = nil)
30
30
  raise NotImplementedError.new('Order.all not implemented.')
31
31
  end
32
32
 
@@ -3,7 +3,7 @@
3
3
  # Parcel objects represent the physical container being shipped.
4
4
  class EasyPost::Parcel < EasyPost::Resource
5
5
  # Retrieving all Parcel objects is not supported.
6
- def self.all
6
+ def self.all(_filters = {}, _api_key = nil)
7
7
  raise NotImplementedError.new('Parcel.all not implemented.')
8
8
  end
9
9
  end
@@ -4,7 +4,7 @@
4
4
  class EasyPost::PaymentMethod < EasyPost::Resource
5
5
  # <b>DEPRECATED:</b> Please use <tt>Billing class</tt> instead.
6
6
  # Deprecated: v4.5.0 - v6.0.0
7
- def self.all(api_key = nil)
7
+ def self.all(_filters = {}, api_key = nil)
8
8
  warn '[DEPRECATION] `all` is deprecated. Please use `Billing.retrieve_payment_methods` instead.'
9
9
  EasyPost::Billing.retrieve_payment_methods(api_key)
10
10
  end
@@ -26,7 +26,7 @@ class EasyPost::Pickup < EasyPost::Resource
26
26
  end
27
27
 
28
28
  # Retrieve a list of all Pickup objects.
29
- def self.all
29
+ def self.all(_filters = {}, _api_key = nil)
30
30
  raise NotImplementedError.new('Pickup.all not implemented.')
31
31
  end
32
32
 
data/lib/easypost/rate.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # A Rate object contains all the details about the rate of a Shipment.
4
4
  class EasyPost::Rate < EasyPost::Resource
5
5
  # Retrieving all Rate objects is not supported.
6
- def self.all
6
+ def self.all(_filters = {}, _api_key = nil)
7
7
  raise NotImplementedError.new('Rate.all not implemented.')
8
8
  end
9
9
  end
@@ -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.0
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-08-25 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