usps_ruby 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ task :install_usps_ruby do
2
+ FileUtils.cp "usps_config.yml", "#{Rails.root}/config/usps_config.yml"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'yaml'
2
+ begin
3
+ CONFIGURATION = YAML.load_file("#{Rails.root}/config/dhl_config.yml")[RAILS_ENV]
4
+ rescue
5
+ puts "Confuration file not found. Run rake install_usps_ruby."
6
+ end
@@ -0,0 +1,38 @@
1
+ module UspsCall
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'openssl'
6
+
7
+ # This method gets called by main class DHLMemnosyne.
8
+ # It makes actual http request to get the shipment details.
9
+ def self.response(tracking_number,usps_id,usps_password)
10
+ uri = URI.parse 'production.shippingapis.com'
11
+ http = Net::HTTP.new uri.host, uri.port
12
+ http.use_ssl, http.verify_mode = use_ssl?(uri)
13
+ request = usps_request(tracking_number,usps_id,usps_password)
14
+ return Net::HTTP.get(uri.path, request)
15
+ end
16
+
17
+ def self.usps_request(tracking_number,usps_id,usps_password)
18
+ require 'rubygems'
19
+ require 'nokogiri'
20
+ method = "/ShippingAPI.dll?API=TrackV2&XML="
21
+ xml_request = Nokogiri::XML::Builder.new do |xml|
22
+ xml.TrackFieldRequest('USERID' => usps_id, 'PASSWORD' => usps_password) {
23
+ xml.TrackID('ID' => tracking_number){
24
+ }
25
+ }
26
+ end
27
+ method + parse_xml_request(xml_request)
28
+ end
29
+
30
+ def self.use_ssl?(uri)
31
+ uri.port == 443 ?
32
+ (return true, OpenSSL::SSL::VERIFY_NONE) : (return false, OpenSSL::SSL::VERIFY_NONE)
33
+ end
34
+
35
+ def self.parse_xml_request(xml)
36
+ return xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip.gsub("\"","\'").gsub(" ","%20")
37
+ end
38
+ end
data/lib/usps_ruby.rb ADDED
@@ -0,0 +1,12 @@
1
+ # This is the main class. To get the shipment details user has to call
2
+ # DHLMemnosyne.track method. DHLMemnosyne.track method receives 3 arguments. First argument is tracking number of a shipment.
3
+ # second argument is DHL id provided by DHL. Third argument is Password provided by DHL. DHL id and password can be specified in
4
+ # rails_root/config/dhl_config.yml. User can also can the track method by directly providing DHL id and password as second
5
+ # and third argument to track method.
6
+ class UspsRuby
7
+ #require '/usps_ruby/credentials/credentials.rb'
8
+ def self.track(tracking_number, dhl_id, dhl_password=nil)
9
+ require 'usps_ruby/web_interface/usps_call'
10
+ UspsCall.response(tracking_number,dhl_id,dhl_password)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usps_ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Pratik Ganvir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.5.2
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.2
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0.9'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0.9'
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ description: Track USPS shipment.
47
+ email: pratikganvir@yahoo.in
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - lib/usps_ruby.rb
53
+ - lib/usps_ruby/credentials/credentials.rb
54
+ - lib/usps_ruby/web_interface/usps_call.rb
55
+ - lib/tasks/rakefile.rb
56
+ homepage: http://rubygems.org/gems/dhl_memnosyne
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ none: false
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ none: false
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Gem for USPS api.
80
+ test_files: []