module PBShipping

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: account.rb Description: account management functions

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: address.rb Description: address verification functions

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: api_object.rb Description: base shipping api object class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: api_resource.rb Description: base api resource class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: authentication.rb Description: handling authentication tasks for subsequent shipping api calls.

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: carrier.rb Description: carrier query such as supported countries

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: country.rb Description: base class for country objects.

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: country.rb Description: base class for custom objects.

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: developer.rb Description: developer account query, merchant managements, and transaction

history query

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: error.rb Description: class encapsulating shipping api exceptions/errors.

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: manifest.rb Description: manifest management functions

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: merchant.rb Description: merchant account class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: parcel.rb Description: parcel class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: rate.rb Description: shipping rate class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: scandetails.rb Description: SCAN form details object

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: shipment.rb Description: shipment rate quote, creation, and other functions

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: shipping_api_resource.rb Description: shipping api resource base class

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: tracking.rb Description: shipment tracking functions

Copyright 2016 Pitney Bowes Inc.

Licensed under the MIT License (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License in the LICENSE file or at

https://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

File: transactiondetails.rb Description: transaction detail objects

Constants

VERSION

Attributes

api_group_shipping[RW]
configuration[RW]
txid_attrname[RW]

Public Class Methods

api_request(auth_obj, method, api_version, api_path, headers = {}, params = {}, payload = {}) click to toggle source
# File lib/pbshipping.rb, line 119
def self.api_request(auth_obj, method, api_version, api_path, headers = {}, params = {}, payload = {})
  if auth_obj == nil || auth_obj.access_token == nil
    raise AuthenticationError.new("Invalid or missing authentication credentials")
  end
  begin
    url = api_url(api_version, api_path)
    headers.merge!(
      :accept => :json,
      :content_type => :json,
      :Authorization => "Bearer " + auth_obj.access_token
    )
    case method
    when :get    
      payload = {}        
      pairs = []
      params.each { |k, v|
        pairs.push "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
      }
      url += "?#{pairs.join('&')}" unless pairs.empty?
    end
    opts = { 
      :headers => headers,
      :method => method,
      :payload => payload.to_json,
      :url => url,
      :open_timeout => 15,
      :timeout => 30,
      :user_agent => "pbshipping/v1 RubyBindings"
    }
    res = make_http_request(opts)
    json_parse(res)      
  rescue => e
    case e
    when RestClient::Exception
      raise ApiError.new(e.to_s, e.http_code, e.http_body) 
    else
      raise ApiError.new(e.to_s)
    end 
  end
end
api_url(api_version, api_path) click to toggle source
# File lib/pbshipping.rb, line 73
def self.api_url(api_version, api_path)
  if @configuration[:is_production] == true
    api_server = @configuration[:production]
  else
    api_server = @configuration[:sandbox] 
  end
  api_server + @api_group_shipping + api_version + api_path
end
authenticate_request(api_key, api_secret) click to toggle source
# File lib/pbshipping.rb, line 82
def self.authenticate_request(api_key, api_secret)
  if @configuration[:is_production] == true
    api_server = @configuration[:production]
  else
    api_server = @configuration[:sandbox] 
  end
  url = api_server + "/oauth/token"
 
  headers = {
    :content_type => 'application/x-www-form-urlencoded',
    :Authorization => 'Basic ' + Base64.strict_encode64(api_key + ":" + api_secret)
  }
  payload = {
    :grant_type => 'client_credentials'
  }
  opts = {
    :method => 'post',
    :payload => payload,
    :headers => headers,
    :url => url,
    :open_timeout => 15,
    :timeout => 30
  }
  
  begin
    res = make_http_request(opts)
    json_parse(res)
  rescue => e
    case e
    when RestClient::Exception
      raise AuthenticationError.new(e.to_s, e.http_code, e.http_body) 
    else
      raise AuthenticationError.new(e.to_s)
    end           
  end  
end
get_api_version(api_sig) click to toggle source
# File lib/pbshipping.rb, line 64
def self.get_api_version(api_sig)
  if @configuration[:override_api_version].key?(api_sig) == true
    api_version = @configuration[:override_api_version][api_sig]
  else 
    api_version = @configuration[:default_api_version]
  end
  return api_version  
end
json_parse(response) click to toggle source
# File lib/pbshipping.rb, line 160
def self.json_parse(response)
  JSON::parse(response.body, { :symbolize_names => true })
end