├── lib ├── courex.rb └── courex │ ├── version.rb │ └── dispatch.rb ├── Rakefile ├── Gemfile ├── .gitignore ├── README.md ├── courextool.gemspec ├── bin └── courex └── LICENSE /lib/courex.rb: -------------------------------------------------------------------------------- 1 | require 'courex/dispatch' -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | -------------------------------------------------------------------------------- /lib/courex/version.rb: -------------------------------------------------------------------------------- 1 | module Courex 2 | VERSION = "0.0.1" 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in courextool.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Courextool 2 | 3 | TODO: Write a gem description 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | gem 'courextool' 10 | 11 | And then execute: 12 | 13 | $ bundle 14 | 15 | Or install it yourself as: 16 | 17 | $ gem install courextool 18 | 19 | ## Usage 20 | 21 | TODO: Write usage instructions here 22 | 23 | ## Contributing 24 | 25 | 1. Fork it 26 | 2. Create your feature branch (`git checkout -b my-new-feature`) 27 | 3. Commit your changes (`git commit -am 'Added some feature'`) 28 | 4. Push to the branch (`git push origin my-new-feature`) 29 | 5. Create new Pull Request 30 | -------------------------------------------------------------------------------- /courextool.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/courex/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Misty De Meo"] 6 | gem.email = ["mistydemeo@gmail.com"] 7 | gem.description = %q{Simple CLI tool to access the Courex API} 8 | gem.summary = %q{Simple CLI tool to access the Courex API} 9 | gem.homepage = "" 10 | 11 | gem.files = `git ls-files`.split($\) 12 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 13 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 14 | gem.name = "courextool" 15 | gem.require_paths = ["lib"] 16 | gem.version = Courex::VERSION 17 | 18 | gem.add_runtime_dependency "nokogiri" 19 | gem.add_runtime_dependency "slop" 20 | end 21 | -------------------------------------------------------------------------------- /bin/courex: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # -*- encoding: utf-8 -*- 3 | 4 | require 'slop' 5 | require 'courex' 6 | 7 | opts = Slop.parse! do 8 | banner "courex -u username -p password " 9 | on :s, :stdout, 'Write to stdout' 10 | on :u, :username, "Username", argument: true 11 | on :p, :password, "Password", argument: true 12 | on :debug, 'Print XML to send to stdout' 13 | on :h, :help, "Display this message" do 14 | puts help 15 | exit 0 16 | end 17 | end 18 | 19 | if !ARGV[0] 20 | STDERR.puts "Error: a tracking number must be specified." 21 | exit Errno::EINVAL::Errno 22 | end 23 | 24 | [:username, :password].each do |key| 25 | if !opts[key] 26 | STDERR.puts "Error: #{key} must be specified" 27 | exit Errno::EINVAL::Errno 28 | end 29 | end 30 | 31 | Courex.username = opts[:username] 32 | Courex.password = opts[:password] 33 | 34 | dispatch = Courex::Dispatch.new ARGV[0] 35 | 36 | STDOUT.puts dispatch.to_xml if opts.debug? 37 | 38 | STDOUT.puts dispatch.dispatch.body -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Misty De Meo 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /lib/courex/dispatch.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'nokogiri' 3 | 4 | module Courex 5 | class Dispatch 6 | attr_accessor :xml 7 | attr_reader :tracking_number 8 | 9 | def initialize tracking_number 10 | @tracking_number = tracking_number 11 | 12 | @xml = Nokogiri::XML::Builder.new do |xml| 13 | xml.RequestCall { 14 | xml.AppType 'Tracking' 15 | 16 | xml.UserName Courex.username 17 | xml.Password Courex.password 18 | 19 | xml.Parameters { 20 | xml.TrackNo tracking_number 21 | } 22 | } 23 | end 24 | end 25 | 26 | def to_xml; @xml.to_xml; end 27 | 28 | def dispatch 29 | uri = URI('http://www.courex.com.sg/xml/index.php') 30 | post = Net::HTTP::Post.new uri.path 31 | 32 | post.content_type = 'application/x-www-form-urlencoded' 33 | post['user-Agent'] = 'CourexGateway_socket/1.0' 34 | post['Accept'] = '*/*' 35 | post.body = @xml.to_xml 36 | 37 | response = Net::HTTP.start(uri.host, uri.port) {|http| http.request(post)} 38 | end 39 | end 40 | 41 | def self.username= name 42 | @username = name 43 | end 44 | 45 | def self.username; @username; end 46 | 47 | def self.password= pass 48 | @password = pass 49 | end 50 | 51 | def self.password; @password; end 52 | end --------------------------------------------------------------------------------