shippo 2.0.6 → 2.0.7

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
  SHA1:
3
- metadata.gz: 85b2b23425a202d40c7136f79f3a5124cf80969d
4
- data.tar.gz: a8c700f918325afae4fdf2f4cc594f9ab22fe7a4
3
+ metadata.gz: 7cf3a2a856cd835b2b6bd4b9dd581be7aa861c1d
4
+ data.tar.gz: 9e18225119fd342921378279dd15ef5827bfe4a0
5
5
  SHA512:
6
- metadata.gz: f0ad9eef6f26034009b9c320258afc1cfbb70b5e290ac874f0962a25800f24604962c151bed0fb67a0042a78bee1af8479a0af38445d4761c69896232451f3cc
7
- data.tar.gz: 31a69491bcfd82afa39d2464594294a99d06fa0405b41bf0f117c76c093ce6e07d7e93529ad0a3ec9d50e61c738e5ba3d2fc7278530c6f7fe95dbd2a1621d819
6
+ metadata.gz: 8a4516e0260ac10b5e4437ccd3603f5f69384422a1ff9f57dd014e0b28dc20419ff455e2a334024c9d7482b5940197ef3ac6b9bf1ceb783633d8904dadbab043
7
+ data.tar.gz: d103a9d4cf47d126303892dac1281c84e3813525597eca4c8640bfa69f11f21e5ace1f81d5e6081adc963155ae8896e23dab1d7d29f2c8c0069d314eed7a6e4e
@@ -1,3 +1,10 @@
1
+ ### 2.0.7 release, Jan 2nd, 2017
2
+ - Fixed bug preventing address validation
3
+ - Removed trailing slash from base URL, added spec test to ensure this configuration
4
+ - Added address validation example
5
+ - Updated basic shipment example to include how to access the Shippo object id
6
+ ### 2.0.6 release, Nov 22nd, 2016
7
+ - Fixed bug to send request with correct API version header
1
8
  #### 2.0.5 release, Oct 24th, 2016
2
9
  - Updated README.md
3
10
  - now possible to send API version
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # © 2016 Shippo, Inc.
4
+ #
5
+ # License: MIT
6
+ #
7
+ # This example demonstrates how to purchase a label for a domestic US shipment.
8
+ # Please set +SHIPPO_TOKEN+ in the environment before running it.
9
+ #
10
+ # You can also set +SHIPPO_DEBUG+ to see detailed printouts of objects returned.
11
+ #
12
+ #
13
+
14
+ lib = File.expand_path('../../lib', __FILE__)
15
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
16
+
17
+ require 'bundler/setup'
18
+ require 'shippo'
19
+ require 'shippo/api/category'
20
+ require 'shippo/exceptions/api_error'
21
+ require 'awesome_print'
22
+ require 'json'
23
+
24
+ Shippo::API.token = ENV['SHIPPO_TOKEN']
25
+
26
+ # Simple wrapper class to help us print objects to the STDOUT
27
+ class ExampleHelper
28
+ def self.log_operation(msg)
29
+ printf '%s', msg
30
+ result = yield
31
+ puts 'OK'
32
+ result
33
+ rescue Exception => e
34
+ raise(e)
35
+ end
36
+
37
+ def self.dump_object(instance, msg = nil)
38
+ return unless Shippo::API.debug?
39
+ sep
40
+ puts "#{msg.upcase}:" if msg
41
+ puts "\#<#{instance.class.inspect}:0x#{instance.object_id.to_s(16)}> ⇒ "
42
+ ap instance
43
+ sep
44
+ # See https://github.com/goshippo/shippo-ruby-client#resource-id-and-other-object-fields
45
+ puts "Shippo object id: #{instance.object.id}"
46
+ sep
47
+ end
48
+
49
+ def self.sep
50
+ puts '—' * (ENV['COLUMNS'] || 80)
51
+ end
52
+ end
53
+
54
+ # Create address object
55
+ address = {
56
+ :object_purpose => 'PURCHASE',
57
+ :name => 'Mr Hippo',
58
+ :company => 'Shippo',
59
+ :street1 => '215 Clayton St.',
60
+ :street2 => '',
61
+ :city => 'San Francisco',
62
+ :state => 'CA',
63
+ :zip => '94117',
64
+ :country => 'US',
65
+ :phone => '+1 555 341 9393',
66
+ :email => 'support@goshippo.com',
67
+ :is_residential => true,
68
+ :metadata => 'some metadata'
69
+ }
70
+
71
+ begin
72
+ address = ExampleHelper.log_operation 'Creating address... ' do
73
+ Shippo::Address.create(address)
74
+ end
75
+ raise Shippo::Exceptions::UnsuccessfulResponseError.new(address.object.inspect) unless address.valid?
76
+ File.open('example-address.json', 'w') do |file|
77
+ file.puts JSON.dump(address.to_hash)
78
+ end
79
+ rescue Shippo::Exceptions::APIServerError => e
80
+ puts "Server returned an error:\n#{e}"
81
+ exit 3
82
+ rescue Shippo::Exceptions::ConnectionError
83
+ puts 'Error connecting to remote host. Is your Internet working?'
84
+ exit 2
85
+ rescue Shippo::Exceptions::AuthenticationError
86
+ if Shippo::API.token
87
+ puts "Token '#{Shippo::API.token}' does not appear to be valid."
88
+ puts 'Access denied.'
89
+ else
90
+ puts 'Please set authentication token in the environment:'
91
+ puts 'export SHIPPO_TOKEN="<your token here>"'
92
+ puts 'and re-run the example.'
93
+ end
94
+ exit 1
95
+ end
96
+
97
+ # Validate the address that we created
98
+ resp = Shippo::Address.validate(address.object.id)
99
+ ExampleHelper.dump_object(resp, 'Validation complete')
100
+
@@ -41,6 +41,9 @@ class ExampleHelper
41
41
  puts "\#<#{instance.class.inspect}:0x#{instance.object_id.to_s(16)}> ⇒ "
42
42
  ap instance
43
43
  sep
44
+ # See https://github.com/goshippo/shippo-ruby-client#resource-id-and-other-object-fields
45
+ puts "Shippo object id: #{instance.object.id}"
46
+ sep
44
47
  end
45
48
 
46
49
  def self.sep
@@ -11,7 +11,7 @@ require 'shippo/api/resource'
11
11
 
12
12
  module Shippo
13
13
  module API
14
- @base = 'https://api.goshippo.com/'
14
+ @base = 'https://api.goshippo.com'
15
15
  @version = nil
16
16
  @token = ''
17
17
  @debug = Integer(ENV['SHIPPO_DEBUG'] || 0) > 0 ? true : false
@@ -2,8 +2,8 @@ module Shippo
2
2
  module API
3
3
  module Operations
4
4
  module Validate
5
- def validate(params={})
6
- response = Shippo::API.get("#{url}/validate/", params)
5
+ def validate(object_id, params={})
6
+ response = Shippo::API.get("#{url}/#{CGI.escape(object_id)}/validate/", params)
7
7
  Shippo::Address.from(response)
8
8
  end
9
9
  end
@@ -99,6 +99,10 @@ module Shippo
99
99
  def success?
100
100
  self.object && self.object.status && self.object.status.eql?(Shippo::API::Category::Status::SUCCESS)
101
101
  end
102
+
103
+ def valid?
104
+ self.object && self.object.state && self.object.state.eql?(Shippo::API::Category::State::VALID)
105
+ end
102
106
  end
103
107
  end
104
108
  end
@@ -1,5 +1,5 @@
1
1
  module Shippo
2
2
  module API
3
- VERSION = '2.0.6'
3
+ VERSION = '2.0.7'
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Shippo
2
2
  class Address < ::Shippo::API::Resource
3
- operations :list, :create
3
+ operations :list, :create, :validate
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shippo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shippo & Contributors
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-22 00:00:00.000000000 Z
12
+ date: 2017-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -188,8 +188,9 @@ files:
188
188
  - Guardfile
189
189
  - README.md
190
190
  - Rakefile
191
+ - bin/address_validation_example
192
+ - bin/basic_shipment_example
191
193
  - bin/console
192
- - bin/example
193
194
  - lib/shippo.rb
194
195
  - lib/shippo/api.rb
195
196
  - lib/shippo/api/api_object.rb
@@ -249,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
250
  version: '0'
250
251
  requirements: []
251
252
  rubyforge_project:
252
- rubygems_version: 2.5.1
253
+ rubygems_version: 2.6.9
253
254
  signing_key:
254
255
  specification_version: 4
255
256
  summary: API client for Shippo® APIs. Shippo helps you connect with multiple carriers