easypost 2.3.0 → 2.4.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 +4 -4
 - data/CHANGELOG +4 -0
 - data/Gemfile +1 -1
 - data/VERSION +1 -1
 - data/circle.yml +3 -0
 - data/lib/easypost.rb +1 -0
 - data/lib/easypost/report.rb +47 -0
 - data/lib/easypost/util.rb +3 -2
 - data/spec/report_spec.rb +76 -0
 - data/spec/user_spec.rb +2 -2
 - metadata +6 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 022e41326d9ad6741c522ddc51cdee8169a0132a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 389053b0e140ead7d54488ced5c215f79d4a9930
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b4dd67994b147e1de7d0ba0b513e0e44203e10ecaa236c7a15d475b956746c5a2720d7fec643aaece62731bbc7e05b2a14748df432a6761f1c17de6a2f9dda5c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d2a15deccdee35141fb29bf0da7eb1c6d71fdb76520c40eed8ed3eb0fa0b7ed0c28ef5e354c31f3704d54d637b860851f5c35736c2ff87cd6e14e5b86e82924d
         
     | 
    
        data/CHANGELOG
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            source 'https://rubygems.org'
         
     | 
| 
       2 
     | 
    
         
            -
            gemspec
         
     | 
| 
      
 2 
     | 
    
         
            +
            gemspec
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            2. 
     | 
| 
      
 1 
     | 
    
         
            +
            2.4.0
         
     | 
    
        data/circle.yml
    ADDED
    
    
    
        data/lib/easypost.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module EasyPost
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Report < Resource
         
     | 
| 
      
 3 
     | 
    
         
            +
                REPORT_TYPES = { shprep: 'shipment', plrep: 'payment_log', trkrep: 'tracker' }
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def self.create(params={}, api_key=nil)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  url = self.url
         
     | 
| 
      
 7 
     | 
    
         
            +
                  wrapped_params = {}
         
     | 
| 
      
 8 
     | 
    
         
            +
                  wrapped_params[class_name.to_sym] = params
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  if REPORT_TYPES.values.include?(params[:type].to_s)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    url += "/#{params[:type]}"
         
     | 
| 
      
 12 
     | 
    
         
            +
                  else
         
     | 
| 
      
 13 
     | 
    
         
            +
                    raise Error.new("Undetermined Report Type")
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  response, api_key = EasyPost.request(:post, url, api_key, params)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  return Util.convert_to_easypost_object(response, api_key)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def self.retrieve(params, api_key=nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  url = self.url
         
     | 
| 
      
 22 
     | 
    
         
            +
                  obj_id = params[:id].split("_")[0]
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  if REPORT_TYPES.has_key?(obj_id.to_sym)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    url += "/#{REPORT_TYPES[obj_id.to_sym]}/#{params[:id]}"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  else
         
     | 
| 
      
 27 
     | 
    
         
            +
                    raise Error.new("Undetermined Report Type")
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  response, api_key = EasyPost.request(:get, url, api_key, params)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def self.all(filters={}, api_key=nil)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  url = self.url
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  if REPORT_TYPES.values.include?(filters[:type].to_s)
         
     | 
| 
      
 38 
     | 
    
         
            +
                    url += "/#{filters[:type]}"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  else
         
     | 
| 
      
 40 
     | 
    
         
            +
                    raise Error.new("Undetermined Report Type")
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  response, api_key = EasyPost.request(:get, url, api_key, filters)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/easypost/util.rb
    CHANGED
    
    | 
         @@ -38,7 +38,8 @@ module EasyPost 
     | 
|
| 
       38 
38 
     | 
    
         
             
                    'Printer' => Printer,
         
     | 
| 
       39 
39 
     | 
    
         
             
                    'PrintJob' => PrintJob,
         
     | 
| 
       40 
40 
     | 
    
         
             
                    'CarrierAccount' => CarrierAccount,
         
     | 
| 
       41 
     | 
    
         
            -
                    'User' => User
         
     | 
| 
      
 41 
     | 
    
         
            +
                    'User' => User,
         
     | 
| 
      
 42 
     | 
    
         
            +
                    'Report' => Report
         
     | 
| 
       42 
43 
     | 
    
         
             
                  }
         
     | 
| 
       43 
44 
     | 
    
         | 
| 
       44 
45 
     | 
    
         
             
                  prefixes = {
         
     | 
| 
         @@ -63,7 +64,7 @@ module EasyPost 
     | 
|
| 
       63 
64 
     | 
    
         
             
                    'printer' => Printer,
         
     | 
| 
       64 
65 
     | 
    
         
             
                    'printjob' => PrintJob,
         
     | 
| 
       65 
66 
     | 
    
         
             
                    'ca' => CarrierAccount,
         
     | 
| 
       66 
     | 
    
         
            -
                    'user' => User
         
     | 
| 
      
 67 
     | 
    
         
            +
                    'user' => User,
         
     | 
| 
       67 
68 
     | 
    
         
             
                  }
         
     | 
| 
       68 
69 
     | 
    
         | 
| 
       69 
70 
     | 
    
         
             
                  case response
         
     | 
    
        data/spec/report_spec.rb
    ADDED
    
    | 
         @@ -0,0 +1,76 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe EasyPost::Report do
         
     | 
| 
      
 4 
     | 
    
         
            +
              [:shipment, :tracker, :payment_log].each do |report_type|
         
     | 
| 
      
 5 
     | 
    
         
            +
                context "report" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  let(:type) { report_type }
         
     | 
| 
      
 7 
     | 
    
         
            +
                  let(:type_name) {
         
     | 
| 
      
 8 
     | 
    
         
            +
                    case type
         
     | 
| 
      
 9 
     | 
    
         
            +
                    when :shipment
         
     | 
| 
      
 10 
     | 
    
         
            +
                      "ShipmentReport"
         
     | 
| 
      
 11 
     | 
    
         
            +
                    when :tracker
         
     | 
| 
      
 12 
     | 
    
         
            +
                      "TrackerReport"
         
     | 
| 
      
 13 
     | 
    
         
            +
                    when :payment_log
         
     | 
| 
      
 14 
     | 
    
         
            +
                      "PaymentLogReport"
         
     | 
| 
      
 15 
     | 
    
         
            +
                    else
         
     | 
| 
      
 16 
     | 
    
         
            +
                      raise "Invalid type!"
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
                  }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  describe '#create' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    it 'creates a report object' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                      report = EasyPost::Report.create(
         
     | 
| 
      
 23 
     | 
    
         
            +
                                                       start_date: Date.today - 30,
         
     | 
| 
      
 24 
     | 
    
         
            +
                                                       end_date: Date.today,
         
     | 
| 
      
 25 
     | 
    
         
            +
                                                       type: type
         
     | 
| 
      
 26 
     | 
    
         
            +
                                                       )
         
     | 
| 
      
 27 
     | 
    
         
            +
                      expect(report.object).to eq type_name
         
     | 
| 
      
 28 
     | 
    
         
            +
                      # will switch that test on when tracker status is deployed
         
     | 
| 
      
 29 
     | 
    
         
            +
                      # expect(report.status).to eq 'available'
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  describe '#retrieve' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                    it 'retrieves a user created report by public_id' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                      report_1 = EasyPost::Report.create(
         
     | 
| 
      
 36 
     | 
    
         
            +
                                                         start_date: Date.today - 30,
         
     | 
| 
      
 37 
     | 
    
         
            +
                                                         end_date: Date.today,
         
     | 
| 
      
 38 
     | 
    
         
            +
                                                         type: type
         
     | 
| 
      
 39 
     | 
    
         
            +
                                                         )
         
     | 
| 
      
 40 
     | 
    
         
            +
                      report_2 = EasyPost::Report.retrieve(id: report_1.id)
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                      expect(report_1.object).to eq type_name
         
     | 
| 
      
 43 
     | 
    
         
            +
                      expect(report_2.object).to eq type_name
         
     | 
| 
      
 44 
     | 
    
         
            +
                      expect(report_2.id).to eq(report_1.id)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  describe '#all' do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    it 'retrieves all user created reports' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                      report_1 = EasyPost::Report.create(
         
     | 
| 
      
 51 
     | 
    
         
            +
                                                         start_date: Date.today - 25,
         
     | 
| 
      
 52 
     | 
    
         
            +
                                                         end_date: Date.today,
         
     | 
| 
      
 53 
     | 
    
         
            +
                                                         type: type
         
     | 
| 
      
 54 
     | 
    
         
            +
                                                         )
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                      report_2 = EasyPost::Report.create(
         
     | 
| 
      
 57 
     | 
    
         
            +
                                                         start_date: Date.today - 29,
         
     | 
| 
      
 58 
     | 
    
         
            +
                                                         end_date: Date.today,
         
     | 
| 
      
 59 
     | 
    
         
            +
                                                         type: type
         
     | 
| 
      
 60 
     | 
    
         
            +
                                                         )
         
     | 
| 
      
 61 
     | 
    
         
            +
                      reports = EasyPost::Report.all(type: type)
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                      expect(reports.count).to eq 2
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              it 'fails to create a report object' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                expect { EasyPost::Report.create(
         
     | 
| 
      
 71 
     | 
    
         
            +
                  start_date: Date.today - 30,
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end_date: Date.today,
         
     | 
| 
      
 73 
     | 
    
         
            +
                  type: 'foobar'
         
     | 
| 
      
 74 
     | 
    
         
            +
                  ) }.to raise_exception(EasyPost::Error)
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/user_spec.rb
    CHANGED
    
    | 
         @@ -64,8 +64,8 @@ describe EasyPost::User do 
     | 
|
| 
       64 
64 
     | 
    
         
             
              #     api_keys = EasyPost::User.all_api_keys
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
              #     my_keys = api_keys.keys
         
     | 
| 
       67 
     | 
    
         
            -
              #     expect(my_keys.first.mode).to eq(" 
     | 
| 
       68 
     | 
    
         
            -
              #     expect(my_keys.last.mode).to eq(" 
     | 
| 
      
 67 
     | 
    
         
            +
              #     expect(my_keys.first.mode).to eq("test")
         
     | 
| 
      
 68 
     | 
    
         
            +
              #     expect(my_keys.last.mode).to eq("production")
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
              #     me = EasyPost::User.retrieve_me
         
     | 
| 
       71 
71 
     | 
    
         
             
              #     children_count = me.children.count
         
     | 
    
        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: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Sawyer Bateman
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-12-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rest-client
         
     | 
| 
         @@ -95,6 +95,7 @@ files: 
     | 
|
| 
       95 
95 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       96 
96 
     | 
    
         
             
            - VERSION
         
     | 
| 
       97 
97 
     | 
    
         
             
            - bin/easypost-irb
         
     | 
| 
      
 98 
     | 
    
         
            +
            - circle.yml
         
     | 
| 
       98 
99 
     | 
    
         
             
            - easypost.gemspec
         
     | 
| 
       99 
100 
     | 
    
         
             
            - lib/easypost.rb
         
     | 
| 
       100 
101 
     | 
    
         
             
            - lib/easypost/address.rb
         
     | 
| 
         @@ -117,6 +118,7 @@ files: 
     | 
|
| 
       117 
118 
     | 
    
         
             
            - lib/easypost/printer.rb
         
     | 
| 
       118 
119 
     | 
    
         
             
            - lib/easypost/rate.rb
         
     | 
| 
       119 
120 
     | 
    
         
             
            - lib/easypost/refund.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - lib/easypost/report.rb
         
     | 
| 
       120 
122 
     | 
    
         
             
            - lib/easypost/resource.rb
         
     | 
| 
       121 
123 
     | 
    
         
             
            - lib/easypost/scan_form.rb
         
     | 
| 
       122 
124 
     | 
    
         
             
            - lib/easypost/shipment.rb
         
     | 
| 
         @@ -132,6 +134,7 @@ files: 
     | 
|
| 
       132 
134 
     | 
    
         
             
            - spec/item_spec.rb
         
     | 
| 
       133 
135 
     | 
    
         
             
            - spec/order_spec.rb
         
     | 
| 
       134 
136 
     | 
    
         
             
            - spec/pickup_spec.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - spec/report_spec.rb
         
     | 
| 
       135 
138 
     | 
    
         
             
            - spec/shipment_spec.rb
         
     | 
| 
       136 
139 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       137 
140 
     | 
    
         
             
            - spec/support/constant.rb
         
     | 
| 
         @@ -169,6 +172,7 @@ test_files: 
     | 
|
| 
       169 
172 
     | 
    
         
             
            - spec/item_spec.rb
         
     | 
| 
       170 
173 
     | 
    
         
             
            - spec/order_spec.rb
         
     | 
| 
       171 
174 
     | 
    
         
             
            - spec/pickup_spec.rb
         
     | 
| 
      
 175 
     | 
    
         
            +
            - spec/report_spec.rb
         
     | 
| 
       172 
176 
     | 
    
         
             
            - spec/shipment_spec.rb
         
     | 
| 
       173 
177 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       174 
178 
     | 
    
         
             
            - spec/support/constant.rb
         
     |