postmaster 1.1.0 → 1.2.1

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.
data/lib/example.rb CHANGED
@@ -80,3 +80,29 @@ result = shipment.track()
80
80
  # you can cancel shipment, but only before being picked up by the carrier
81
81
  result = shipment.void()
82
82
  #puts result.inspect
83
+
84
+ # create box example
85
+ result = Postmaster::Package.create(
86
+ :width => 10,
87
+ :height => 12,
88
+ :length => 8,
89
+ :name => 'My Box'
90
+ )
91
+ #puts result.inspect
92
+
93
+ # list boxes example
94
+ result = Postmaster::Package.all(
95
+ :limit => 2
96
+ )
97
+ #puts result.inspect
98
+
99
+ # fit items in box example
100
+ result = Postmaster::Package.fit(
101
+ "items" =>
102
+ [{"width" => 2.2, "length" => 3, "height" => 1, "count" => 2}],
103
+ "packages" => [
104
+ {"width" => 6, "length" => 6, "height" => 6, "sku" => "123ABC"},
105
+ {"width" => 12, "length" => 12, "height" => 12, "sku" => "456XYZ"}
106
+ ]
107
+ )
108
+ #puts result.inspect
data/lib/postmaster.rb CHANGED
@@ -88,7 +88,11 @@ module Postmaster
88
88
  end
89
89
  payload = nil
90
90
  else
91
- payload = Util.flatten_params(params).collect{|(key, value)| "#{key}=#{Util.url_encode(value)}"}.join('&')
91
+ if params.kind_of? String
92
+ payload = params
93
+ else
94
+ payload = Util.flatten_params(params).collect{|(key, value)| "#{key}=#{Util.url_encode(value)}"}.join('&')
95
+ end
92
96
  end
93
97
 
94
98
  begin
@@ -1,6 +1,17 @@
1
1
  module Postmaster
2
2
 
3
3
  class Package < APIResource
4
- end
4
+ include Postmaster::APIOperations::List
5
+
6
+ def self.create(params={})
7
+ response = Postmaster.request(:post, self.url, params)
8
+ response[:id]
9
+ end
5
10
 
11
+ def self.fit(params={})
12
+ json_params = Postmaster::JSON.dump(params, :pretty => true)
13
+ headers = {:content_type => 'application/json'}
14
+ Postmaster.request(:post, '/v1/packages/fit', json_params, headers)
15
+ end
16
+ end
6
17
  end
@@ -1,3 +1,3 @@
1
1
  module Postmaster
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -101,10 +101,14 @@ class TestPostmasterRuby < Test::Unit::TestCase
101
101
  obj = Postmaster::PostmasterObject.construct_from({
102
102
  :foo => "bar",
103
103
  })
104
-
105
- assert_equal('{"foo":"bar"}', obj.to_s)
104
+ if MultiJson.adapter.to_s == 'MultiJson::Adapters::Yajl'
105
+ expected = "{\n \"foo\": \"bar\"\n}"
106
+ else
107
+ expected = '{"foo":"bar"}'
108
+ end
109
+ assert_equal(expected, obj.to_s)
106
110
  assert_equal('{"foo":"bar"}', obj.to_json)
107
- assert(obj.inspect.include? 'JSON: {"foo":"bar"}')
111
+ assert(obj.inspect.include? 'JSON: '+expected)
108
112
  end
109
113
 
110
114
  end
@@ -79,7 +79,7 @@ class TestShipmentRuby < Test::Unit::TestCase
79
79
  end
80
80
 
81
81
  should "track" do
82
- shipment = Postmaster::Shipment.create(params=sample_shipment)
82
+ shipment = Postmaster::Shipment.retrieve('2010')
83
83
  result = shipment.track()
84
84
 
85
85
  assert_kind_of(Array, result)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmaster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 2
8
9
  - 1
9
- - 0
10
- version: 1.1.0
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Postmaster
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-14 00:00:00 Z
18
+ date: 2013-06-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client