easypost 2.0.13 → 2.0.15

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 131297bd3896582b77eebf257940afee1118215c
4
+ data.tar.gz: 7ef855b3b817a0ba6b7314c4f7d92594640a066a
5
+ SHA512:
6
+ metadata.gz: 48f352fc1099de1a4995e96b1dc077133f4bba456407baf89d73263990278676d204da5979f8b3cf3e87154798b1d799f42c03d3714484727640d9a5f544718e
7
+ data.tar.gz: 3a9ea6325239c5649348d8c08c9c73648ab469b6509eade346c2914584f8fa1dbd5ba4e071d19f4a6cd90137bfd9bb6b1c452b076a20499c2f8177ff3b5ce78c
data/.gitignore CHANGED
@@ -25,4 +25,5 @@ doc/
25
25
  Icon
26
26
  ._*
27
27
  .Spotlight-V100
28
- .Trashes
28
+ .Trashes
29
+ vendor/
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ === 2.0.15 2015-04-15
2
+
3
+ * Added tracker to shipment buy response
4
+ * Updated tracker tests
5
+
6
+
7
+ === 2.0.14 2015-04-15
8
+
9
+ * Added User and CarrierAccount models with CRUD functionality
10
+
11
+
1
12
  === 2.0.13 2014-10-30
2
13
 
3
14
  * Added Pickup, PickupRate resources.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # EasyPost Ruby Client Library
2
2
 
3
+ [<img src="https://circleci.com/gh/EasyPost/easypost-ruby.png?circle-token=80adb5236ed1fdce20810b055af79c63c3d5796b">](https://circleci.com/gh/EasyPost/easypost-ruby)
4
+
5
+
3
6
  EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com
4
7
 
5
8
  Installation
data/Rakefile CHANGED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.13
1
+ 2.0.15
data/easypost.gemspec CHANGED
@@ -13,12 +13,14 @@ Gem::Specification.new do |spec|
13
13
  spec.email = 'contact@easypost.com'
14
14
  spec.homepage = 'https://www.easypost.com/docs'
15
15
 
16
- spec.files = `git ls-files`.split("\n")
17
- spec.test_files = `git ls-files -- test/*`.split("\n")
18
- spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- spec.require_path = 'lib'
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency('rest-client', '~> 1.4')
22
- spec.add_dependency('multi_json', '>= 1.0.4', '< 2')
23
- spec.add_development_dependency('rspec', "~> 2.13.0")
21
+ spec.add_dependency 'rest-client', '~> 1.4'
22
+ spec.add_dependency 'multi_json', '>= 1.0.4', '< 2'
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 2.13.0'
24
26
  end
data/lib/easypost.rb CHANGED
@@ -26,6 +26,8 @@ require 'easypost/container'
26
26
  require 'easypost/order'
27
27
  require 'easypost/pickup'
28
28
  require 'easypost/pickup_rate'
29
+ require 'easypost/carrier_account'
30
+ require 'easypost/user'
29
31
 
30
32
  require 'easypost/error'
31
33
 
@@ -68,7 +70,8 @@ module EasyPost
68
70
  @@http_config ||= {
69
71
  timeout: 60,
70
72
  open_timeout: 30,
71
- verify_ssl: false
73
+ verify_ssl: false,
74
+ ssl_version: "TLSv1",
72
75
  }
73
76
  end
74
77
 
@@ -14,12 +14,16 @@ module EasyPost
14
14
  verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
15
15
  return verified_address
16
16
  else
17
- raise Error.new("Unable to verify address.")
17
+ raise_verification_failure
18
18
  end
19
19
  end
20
20
 
21
21
  def verify(params={}, carrier=nil)
22
- response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
22
+ begin
23
+ response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
24
+ rescue
25
+ raise_verification_failure
26
+ end
23
27
 
24
28
  if response.has_key?(:address)
25
29
  if response.has_key?(:message)
@@ -28,11 +32,14 @@ module EasyPost
28
32
  verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
29
33
  return verified_address
30
34
  else
31
- raise Error.new("Unable to verify address.")
35
+ raise_verification_failure
32
36
  end
33
37
 
34
38
  return self
35
39
  end
36
40
 
41
+ def raise_verification_failure
42
+ raise Error.new("Unable to verify address.")
43
+ end
37
44
  end
38
45
  end
@@ -0,0 +1,21 @@
1
+ module EasyPost
2
+ class CarrierAccount < Resource
3
+ def save
4
+ if @unsaved_values.length > 0
5
+ values = {}
6
+ @unsaved_values.each { |k| values[k] = @values[k] }
7
+
8
+ wrapped_params = {carrier_account: values}
9
+
10
+ response, api_key = EasyPost.request(:put, url, @api_key, wrapped_params)
11
+ refresh_from(response, api_key)
12
+ end
13
+ return self
14
+ end
15
+
16
+ def self.types
17
+ response, api_key = EasyPost.request(:get, "/carrier_types", @api_key)
18
+ return Util.convert_to_easypost_object(response, api_key)
19
+ end
20
+ end
21
+ end
@@ -32,11 +32,11 @@ module EasyPost
32
32
  @api_key = api_key
33
33
 
34
34
  added = Set.new(values.keys - @values.keys)
35
-
35
+
36
36
  instance_eval do
37
37
  add_accessors(added)
38
38
  end
39
-
39
+
40
40
  values.each do |k, v|
41
41
  @values[k] = Util.convert_to_easypost_object(v, api_key)
42
42
  @transient_values.delete(k)
@@ -0,0 +1,42 @@
1
+ module EasyPost
2
+ class User < Resource
3
+ def save
4
+ if @unsaved_values.length > 0
5
+ values = {}
6
+ @unsaved_values.each { |k| values[k] = @values[k] }
7
+
8
+ wrapped_params = {user: values}
9
+
10
+ response, api_key = EasyPost.request(:put, url, @api_key, wrapped_params)
11
+ refresh_from(response, api_key)
12
+ end
13
+ return self
14
+ end
15
+
16
+ def self.retrieve_me
17
+ self.all
18
+ end
19
+
20
+ def self.all_api_keys
21
+ response, api_key = EasyPost.request(:get, "/api_keys", @api_key)
22
+ return Util.convert_to_easypost_object(response, api_key)
23
+ end
24
+
25
+ def api_keys
26
+ api_keys = EasyPost::User.all_api_keys
27
+
28
+ if api_keys.id == self.id
29
+ my_api_keys = api_keys.keys
30
+ else
31
+ for child in api_keys.children
32
+ if child.id == self.id
33
+ my_api_keys = child.keys
34
+ break
35
+ end
36
+ end
37
+ end
38
+
39
+ my_api_keys
40
+ end
41
+ end
42
+ end
data/lib/easypost/util.rb CHANGED
@@ -32,7 +32,9 @@ module EasyPost
32
32
  'Order' => Order,
33
33
  'Pickup' => Pickup,
34
34
  'PickupRate' => PickupRate,
35
- 'PostageLabel' => PostageLabel }
35
+ 'PostageLabel' => PostageLabel,
36
+ 'CarrierAccount' => CarrierAccount,
37
+ 'User' => User }
36
38
 
37
39
  prefixes = { 'adr' => Address,
38
40
  'sf' => ScanForm,
@@ -50,7 +52,9 @@ module EasyPost
50
52
  'order' => Order,
51
53
  'pickup' => Pickup,
52
54
  'pickuprate' => PickupRate,
53
- 'pl' => PostageLabel }
55
+ 'pl' => PostageLabel,
56
+ 'ca' => CarrierAccount,
57
+ 'user' => User }
54
58
 
55
59
  case response
56
60
  when Array
data/spec/address_spec.rb CHANGED
@@ -55,15 +55,15 @@ describe EasyPost::Address do
55
55
 
56
56
  it 'is not able to verify address' do
57
57
  address = EasyPost::Address.create(
58
- :company => 'Simpler Postage Inc',
59
- :street1 => '388 Junk Teerts',
60
- :street2 => 'Apt 20',
61
- :city => 'San Francisco',
62
- :state => 'CA',
63
- :zip => '941abc07'
58
+ company: 'Simpler Postage Inc',
59
+ street1: '388 Junk Teerts',
60
+ street2: 'Apt 20',
61
+ city: 'San Francisco',
62
+ state: 'CA',
63
+ zip: '941abc07'
64
64
  )
65
65
 
66
- expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify address./)
66
+ expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify addres/)
67
67
  end
68
68
  end
69
69
  end
data/spec/batch_spec.rb CHANGED
@@ -1,61 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Batch do
4
-
5
4
  describe '#create' do
6
5
  it 'creates a batch object' do
7
6
  batch = EasyPost::Batch.create({
8
- :shipment => [{
9
- :from_address => ADDRESS[:california],
10
- :to_address => ADDRESS[:missouri],
11
- :parcel => PARCEL[:dimensions]
7
+ shipment: [{
8
+ from_address: ADDRESS[:california],
9
+ to_address: EasyPost::Address.create(ADDRESS[:missouri]),
10
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
12
11
  }, {
13
- :from_address => ADDRESS[:california],
14
- :to_address => ADDRESS[:canada],
15
- :parcel => PARCEL[:dimensions],
12
+ from_address: ADDRESS[:california],
13
+ to_address: EasyPost::Address.create(ADDRESS[:canada]),
14
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
16
15
  }],
17
- :reference => "batch123456789"
16
+ reference: "batch123456789"
18
17
  })
19
18
  expect(batch).to be_an_instance_of(EasyPost::Batch)
20
19
  expect(batch.num_shipments).to eq(2)
21
20
  expect(batch.reference).to eq("batch123456789")
22
21
  expect(batch.state).to eq("creating")
23
-
24
- # sleeps_left = 10
25
- # while (batch.state == "creating" && sleeps_left > 0) do
26
- # sleep(3)
27
- # batch.refresh
28
- # sleeps_left -= 1
29
- # end
30
-
31
- # expect(batch.state).to equal("created")
32
- # expect(batch.status[:created]).to equal(2)
33
-
34
22
  end
35
23
  end
36
24
 
37
25
  describe '#create_and_buy' do
38
26
  it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
39
27
  batch = EasyPost::Batch.create({
40
- :shipment => [{
41
- :from_address => ADDRESS[:california],
42
- :to_address => ADDRESS[:missouri],
43
- :parcel => PARCEL[:dimensions],
44
- :carrier => "usps",
45
- :service => "priority"
28
+ shipment: [{
29
+ from_address: ADDRESS[:california],
30
+ to_address: EasyPost::Address.create(ADDRESS[:missouri]),
31
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
32
+ carrier: "usps",
33
+ service: "priority"
46
34
  }, {
47
- :from_address => ADDRESS[:california],
48
- :to_address => ADDRESS[:canada],
49
- :parcel => PARCEL[:dimensions],
50
- :carrier => "usps",
51
- :service => "prioritymailinternational"
35
+ from_address: ADDRESS[:california],
36
+ to_address: EasyPost::Address.create(ADDRESS[:canada]),
37
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
38
+ carrier: "usps",
39
+ service: "prioritymailinternational"
52
40
  }],
53
- :reference => "batch123456789"
41
+ reference: "batch123456789"
54
42
  })
55
43
  expect(batch).to be_an_instance_of(EasyPost::Batch)
56
44
  expect(batch.state).to eq("creating")
57
45
  expect(batch.num_shipments).to eq(2)
58
46
  end
59
47
  end
60
-
61
48
  end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyPost::CarrierAccount do
4
+ it 'performs all basic CRUD actions on a CarrierAccount' do
5
+ original_num_cas = EasyPost::CarrierAccount.all.count
6
+
7
+ description = "A test Ups Account"
8
+ reference = "RubyClientUpsTestAccount"
9
+
10
+ created_ca = EasyPost::CarrierAccount.create(
11
+ type: "UpsAccount",
12
+ description: description,
13
+ reference: reference,
14
+ credentials: {
15
+ account_number: "A1A1A1",
16
+ user_id: "UPSDOTCOM_USERNAME",
17
+ password: "UPSDOTCOM_PASSWORD",
18
+ access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
19
+ }
20
+ )
21
+
22
+ id = created_ca["id"]
23
+
24
+ interm_num_cas = EasyPost::CarrierAccount.all.count
25
+ expect(interm_num_cas).to eq(original_num_cas + 1)
26
+
27
+ retrieved_ca = EasyPost::CarrierAccount.retrieve(id)
28
+
29
+ expect(retrieved_ca["id"]).to eq(created_ca["id"])
30
+ expect(retrieved_ca["description"]).to eq(description)
31
+ expect(retrieved_ca["reference"]).to eq(reference)
32
+
33
+ updated_description = "An updated description for a test Ups Account"
34
+ retrieved_ca.description = updated_description
35
+ retrieved_ca.save
36
+
37
+ updated_ca = EasyPost::CarrierAccount.retrieve(id)
38
+ expect(updated_ca["id"]).to eq(created_ca["id"])
39
+ expect(updated_ca["description"]).to eq(updated_description)
40
+
41
+ updated_ca.delete
42
+
43
+ final_num_cas = EasyPost::CarrierAccount.all.count
44
+ expect(final_num_cas).to eq(original_num_cas)
45
+ end
46
+
47
+ describe '#types' do
48
+ let(:carrier_account_types) { [
49
+ "AsendiaAccount",
50
+ "AustraliaPostAccount",
51
+ "CanadaPostAccount",
52
+ "CanparAccount",
53
+ "ColisPriveAccount",
54
+ "DhlExpressAccount",
55
+ "DhlGlobalMailAccount",
56
+ "FastwayAccount",
57
+ "FedexAccount",
58
+ "FedexSmartpostAccount",
59
+ "GsoAccount",
60
+ "LasershipAccount",
61
+ "LsoAccount",
62
+ "NorcoAccount",
63
+ "NzpostAccount",
64
+ "OntracAccount",
65
+ "PurolatorAccount",
66
+ "RoyalMailAccount",
67
+ "SpeedeeAccount",
68
+ "TntExpressAccount",
69
+ "UpsAccount",
70
+ "UpsMailInnovationsAccount",
71
+ "UpsSurepostAccount"
72
+ ] }
73
+
74
+ it 'returns the expected list of types' do
75
+ types = EasyPost::CarrierAccount.types
76
+ account_types = types.map(&:type)
77
+
78
+ for account_type in carrier_account_types
79
+ expect(account_types).to include(account_type)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Container do
4
-
5
4
  describe '#create' do
6
5
  it 'creates a container object' do
7
6
  container = EasyPost::Container.create(
@@ -73,15 +72,5 @@ describe EasyPost::Container do
73
72
  expect(container_2.height).to eq(container_1.height)
74
73
  expect(container_1.type).to eq("BOX")
75
74
  end
76
-
77
- it 'retrieves global containers' do
78
- container_1 = EasyPost::Container.retrieve("container_USPSFR03")
79
- container_2 = EasyPost::Container.retrieve("container_USPSFR02")
80
-
81
- expect(container_1).to be_an_instance_of(EasyPost::Container)
82
- expect(container_2).to be_an_instance_of(EasyPost::Container)
83
- expect(container_1.reference).to eq(container_2.reference)
84
- end
85
75
  end
86
-
87
76
  end