dji 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dji.gemspec +39 -0
- data/exe/dji +16 -0
- data/lib/dji.rb +16 -0
- data/lib/dji/command.rb +64 -0
- data/lib/dji/command/base.rb +53 -0
- data/lib/dji/command/behavior.rb +55 -0
- data/lib/dji/commands.rb +3 -0
- data/lib/dji/commands/track/track_command.rb +13 -0
- data/lib/dji/commands/version/version_command.rb +11 -0
- data/lib/dji/fedex.rb +79 -0
- data/lib/dji/order_tracking.rb +90 -0
- data/lib/dji/version.rb +3 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7c13726726cac5f389ff3afdb5bb756b3805316
|
4
|
+
data.tar.gz: f902274bcd1157a40499916494148b45f47f26d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: affb1a2ea0208affab2c2c00a971e59b4f35608c067e841619e41f20769409e0f9d79585b87609c636e8bd5fa459159aaa38d68252c0a31d6e4079180f30876b
|
7
|
+
data.tar.gz: ae750d8f08cfa3b631760dc27875b6d16e4392ad89750d7405c7fcb5046bad465df25bc5f69a3f8291a58549f9c886890eb719a299d77a6425a66270a64a0818
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at kevin@welikeinc.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kevin Elliott
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# DJI
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
If you already have Ruby installed on your computer, you can install this. Otherwise, go install Ruby and come back to these instructions.
|
8
|
+
|
9
|
+
Open a command line (Terminal on macOS):
|
10
|
+
|
11
|
+
$ gem install dji
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Track an order
|
16
|
+
|
17
|
+
$ dji track -o ORDER_NUMBER -p PHONE_TAIL
|
18
|
+
|
19
|
+
Use your order number in place of ORDER_NUMBER and the last 4 digits of your phone number for PHONE_TAIL. A full example might look like this:
|
20
|
+
|
21
|
+
$ dji track -o 1234567890 -p 1234
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dji. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
37
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dji"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dji.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dji/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dji'
|
8
|
+
spec.version = DJI::VERSION
|
9
|
+
spec.authors = ["Kevin Elliott"]
|
10
|
+
spec.email = ["kevin@welikeinc.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CLI and Ruby tools for drone-maker DJI's store, account, and more.}
|
13
|
+
spec.description = %q{CLI and Ruby tools for drone-maker DJI's store, account, and more.}
|
14
|
+
spec.homepage = "http://github.com/kevinelliott/dji"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = ['dji']
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_dependency 'activesupport'
|
34
|
+
spec.add_dependency 'thor', '>= 0.18.1', '< 2.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
end
|
data/exe/dji
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'dji'
|
4
|
+
require 'dji/commands'
|
5
|
+
|
6
|
+
ARGV << '--help' if ARGV.empty?
|
7
|
+
|
8
|
+
command_aliases = {
|
9
|
+
'h' => 'help',
|
10
|
+
't' => 'track',
|
11
|
+
}
|
12
|
+
|
13
|
+
command = ARGV.shift
|
14
|
+
command = command_aliases[command] || command
|
15
|
+
|
16
|
+
DJI::Command.invoke command, ARGV
|
data/lib/dji.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
require 'active_support/dependencies/autoload'
|
4
|
+
require 'active_support/descendants_tracker'
|
5
|
+
require 'active_support/core_ext/class/subclasses'
|
6
|
+
require 'active_support/core_ext/module/delegation'
|
7
|
+
require 'active_support/core_ext/array/extract_options'
|
8
|
+
|
9
|
+
require 'dji/version'
|
10
|
+
|
11
|
+
module DJI
|
12
|
+
extend ActiveSupport::Autoload
|
13
|
+
|
14
|
+
autoload :Fedex
|
15
|
+
autoload :OrderTracking
|
16
|
+
end
|
data/lib/dji/command.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/dependencies/autoload'
|
3
|
+
require 'active_support/core_ext/enumerable'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/hash/transform_values'
|
6
|
+
|
7
|
+
require "active_support/inflector"
|
8
|
+
require "active_support/core_ext/module/introspection"
|
9
|
+
require "active_support/core_ext/module/delegation"
|
10
|
+
|
11
|
+
require 'thor'
|
12
|
+
|
13
|
+
|
14
|
+
module DJI
|
15
|
+
module Command
|
16
|
+
extend ActiveSupport::Autoload
|
17
|
+
|
18
|
+
autoload :Behavior
|
19
|
+
autoload :Base
|
20
|
+
|
21
|
+
include Behavior
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
def invoke(namespace, args = [], **config)
|
26
|
+
namespace = namespace.to_s
|
27
|
+
namespace = 'help' if namespace.blank? || Thor::HELP_MAPPINGS.include?(namespace)
|
28
|
+
namespace = 'version' if %w( -v --version ).include? namespace
|
29
|
+
|
30
|
+
if command = find_by_namespace(namespace)
|
31
|
+
command.perform(namespace, args, config)
|
32
|
+
else
|
33
|
+
puts "There is no such command: #{namespace}"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_by_namespace(name) # :nodoc:
|
39
|
+
lookups = [ name, "dji:#{name}" ]
|
40
|
+
|
41
|
+
lookup(lookups)
|
42
|
+
|
43
|
+
namespaces = subclasses.index_by(&:namespace)
|
44
|
+
namespaces[(lookups & namespaces.keys).first]
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def command_type
|
50
|
+
@command_type ||= "command"
|
51
|
+
end
|
52
|
+
|
53
|
+
def lookup_paths
|
54
|
+
@lookup_paths ||= %w( dji/commands commands )
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_lookup_paths
|
58
|
+
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_command.rb" ]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
|
4
|
+
module DJI
|
5
|
+
module Command
|
6
|
+
|
7
|
+
class Base < ::Thor
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Convenience method to get the namespace from the class name. It's the
|
12
|
+
# same as Thor default except that the Command at the end of the class
|
13
|
+
# is removed.
|
14
|
+
def namespace
|
15
|
+
ActiveSupport::Inflector.underscore(
|
16
|
+
ActiveSupport::Inflector.demodulize(
|
17
|
+
name
|
18
|
+
)
|
19
|
+
).chomp("_command").sub(/:command:/, ":")
|
20
|
+
end
|
21
|
+
|
22
|
+
def inherited(base) #:nodoc:
|
23
|
+
super
|
24
|
+
|
25
|
+
if base.name && base.name !~ /Base$/
|
26
|
+
DJI::Command.subclasses << base
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def perform(command, args, config) # :nodoc:
|
31
|
+
command = nil if Thor::HELP_MAPPINGS.include?(args.first)
|
32
|
+
|
33
|
+
dispatch(command, args.dup, nil, config)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return command name without namespaces.
|
37
|
+
#
|
38
|
+
# DJI::Command::TestCommand.command_name # => 'test'
|
39
|
+
def command_name
|
40
|
+
@command_name ||= begin
|
41
|
+
if command = name.to_s.split("::").last
|
42
|
+
command.chomp!("Command")
|
43
|
+
command.underscore
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module DJI
|
4
|
+
module Command
|
5
|
+
module Behavior
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
|
10
|
+
def subclasses
|
11
|
+
@subclasses ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# Receives namespaces in an array and tries to find matching generators
|
17
|
+
# in the load path.
|
18
|
+
def lookup(namespaces) #:nodoc:
|
19
|
+
paths = namespaces_to_paths(namespaces)
|
20
|
+
|
21
|
+
paths.each do |raw_path|
|
22
|
+
lookup_paths.each do |base|
|
23
|
+
path = "#{base}/#{raw_path}_#{command_type}"
|
24
|
+
|
25
|
+
begin
|
26
|
+
require path
|
27
|
+
return
|
28
|
+
rescue LoadError => e
|
29
|
+
raise unless e.message =~ /#{Regexp.escape(path)}$/
|
30
|
+
rescue Exception => e
|
31
|
+
warn "[WARNING] Could not load #{command_type} #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Convert namespaces to paths by replacing ":" for "/" and adding
|
38
|
+
# an extra lookup. For example, "dji:track" should be searched
|
39
|
+
# in both: "dji/track/track_command" and "dji/track_command".
|
40
|
+
def namespaces_to_paths(namespaces) #:nodoc:
|
41
|
+
paths = []
|
42
|
+
namespaces.each do |namespace|
|
43
|
+
pieces = namespace.split(":")
|
44
|
+
paths << pieces.dup.push(pieces.last).join("/")
|
45
|
+
paths << pieces.join("/")
|
46
|
+
end
|
47
|
+
paths.uniq!
|
48
|
+
paths
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/dji/commands.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module DJI
|
2
|
+
module Command
|
3
|
+
class TrackCommand < Base
|
4
|
+
desc 'track ORDER_NUMBER PHONE_TAIL', 'track an order'
|
5
|
+
option :order_number, required: true, aliases: :o
|
6
|
+
option :phone_tail, required: true, aliases: :p
|
7
|
+
|
8
|
+
def track
|
9
|
+
DJI::OrderTracking.tracking_details(options[:order_number], options[:phone_tail])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/dji/fedex.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module DJI
|
7
|
+
class Fedex
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Get the tracking details for an order
|
12
|
+
def tracking_details(country, postal_code)
|
13
|
+
uri = URI.parse(tracking_url)
|
14
|
+
params = {
|
15
|
+
'action' => 'altref',
|
16
|
+
'trackingnumber' => 'DJI GOODS',
|
17
|
+
'cntry_code' => country,
|
18
|
+
'shipdate' => Time.now.strftime('%Y-%m-%d'),
|
19
|
+
'dest_postal' => postal_code
|
20
|
+
}
|
21
|
+
uri.query = URI.encode_www_form(params)
|
22
|
+
|
23
|
+
headers = {
|
24
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
25
|
+
'Origin' => 'https://www.fedex.com/',
|
26
|
+
'Referer' => tracking_url
|
27
|
+
}
|
28
|
+
|
29
|
+
http = Net::HTTP.new uri.host, uri.port
|
30
|
+
request = Net::HTTP.get(uri, headers)
|
31
|
+
res = http.request(request)
|
32
|
+
|
33
|
+
case res
|
34
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
35
|
+
puts res.body
|
36
|
+
# OK
|
37
|
+
# page = Nokogiri::HTML(res.body)
|
38
|
+
# content = page.at_xpath('//div[@id="main"]/div[@class="container"]/div[@class="row"]/div[@class="col-xs-9"]/div[@class="col-xs-10 well"][2]')
|
39
|
+
# # puts content
|
40
|
+
# data = {}
|
41
|
+
# data[:order_number] = content.at_xpath('div[1]').text.split(' ')[-1]
|
42
|
+
# data[:total] = content.at_xpath('div[2]').text.split(' ')[1..-1].join(' ')
|
43
|
+
# data[:payment_status] = content.at_xpath('div[3]').text.split(': ')[1]
|
44
|
+
# data[:shipping_status] = content.at_xpath('div[4]').text.split(': ')[1]
|
45
|
+
# data[:shipping_company] = content.at_xpath('div[5]/span').text
|
46
|
+
# data[:tracking_number] = content.at_xpath('div[6]/a').text
|
47
|
+
|
48
|
+
# print_tracking_details(data)
|
49
|
+
else
|
50
|
+
puts res.inspect
|
51
|
+
res.error!
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# The URL for order tracking
|
57
|
+
def tracking_url
|
58
|
+
'https://www.fedex.com/apps/fedextrack/'
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_tracking_details(data)
|
62
|
+
now = Time.now.to_s
|
63
|
+
|
64
|
+
puts
|
65
|
+
puts "ORDER TRACKING AS OF #{now}"
|
66
|
+
puts "------------------------------------------------------"
|
67
|
+
puts "Order Number : #{data[:order_number]}"
|
68
|
+
puts "Total : #{data[:total]}"
|
69
|
+
puts "Payment Status : #{data[:payment_status]}"
|
70
|
+
puts "Shipping Status : #{data[:shipping_status]}"
|
71
|
+
puts "Shipping Company : #{data[:shipping_company]}"
|
72
|
+
puts "Tracking Number : #{data[:tracking_number]}"
|
73
|
+
puts
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module DJI
|
7
|
+
class OrderTracking
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Retrieve an authenticity_token
|
12
|
+
def authenticity_token(url)
|
13
|
+
uri = URI(url)
|
14
|
+
http = Net::HTTP.new uri.host, uri.port
|
15
|
+
request = Net::HTTP::Get.new uri.path
|
16
|
+
response = http.request request
|
17
|
+
|
18
|
+
page = Nokogiri::HTML(response.body)
|
19
|
+
token = page.at_xpath('//meta[@name="csrf-token"]/@content').text
|
20
|
+
cookie = response['set-cookie']
|
21
|
+
|
22
|
+
{ param: 'authenticity_token', token: token, cookie: cookie }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get the tracking details for an order
|
26
|
+
def tracking_details(order_number, phone)
|
27
|
+
auth_token = authenticity_token(tracking_url)
|
28
|
+
|
29
|
+
url = URI.parse(tracking_url)
|
30
|
+
params = { 'number' => order_number, 'phone_tail' => phone, 'utf8' => '✓' }
|
31
|
+
params[auth_token[:param]] = auth_token[:token]
|
32
|
+
|
33
|
+
headers = {
|
34
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
35
|
+
'Cookie' => auth_token[:cookie],
|
36
|
+
'Origin' => 'http://store.dji.com',
|
37
|
+
'Referer' => tracking_url
|
38
|
+
}
|
39
|
+
|
40
|
+
http = Net::HTTP.new url.host, url.port
|
41
|
+
request = Net::HTTP::Post.new url.path, headers
|
42
|
+
request.set_form_data params
|
43
|
+
res = http.request(request)
|
44
|
+
|
45
|
+
case res
|
46
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
47
|
+
# OK
|
48
|
+
page = Nokogiri::HTML(res.body)
|
49
|
+
content = page.at_xpath('//div[@id="main"]/div[@class="container"]/div[@class="row"]/div[@class="col-xs-9"]/div[@class="col-xs-10 well"][2]')
|
50
|
+
# puts content
|
51
|
+
data = {}
|
52
|
+
data[:order_number] = content.at_xpath('div[1]').text.split(' ')[-1]
|
53
|
+
data[:total] = content.at_xpath('div[2]').text.split(' ')[1..-1].join(' ')
|
54
|
+
data[:payment_status] = content.at_xpath('div[3]').text.split(': ')[1]
|
55
|
+
data[:shipping_status] = content.at_xpath('div[4]').text.split(': ')[1]
|
56
|
+
data[:shipping_company] = content.at_xpath('div[5]/span').text
|
57
|
+
data[:tracking_number] = content.at_xpath('div[6]/a').text
|
58
|
+
|
59
|
+
print_tracking_details(data)
|
60
|
+
else
|
61
|
+
puts res.inspect
|
62
|
+
res.error!
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# The URL for order tracking
|
68
|
+
def tracking_url
|
69
|
+
'http://store.dji.com/orders/tracking'
|
70
|
+
end
|
71
|
+
|
72
|
+
def print_tracking_details(data)
|
73
|
+
now = Time.now.to_s
|
74
|
+
|
75
|
+
puts
|
76
|
+
puts "ORDER TRACKING AS OF #{now}"
|
77
|
+
puts "------------------------------------------------------"
|
78
|
+
puts "Order Number : #{data[:order_number]}"
|
79
|
+
puts "Total : #{data[:total]}"
|
80
|
+
puts "Payment Status : #{data[:payment_status]}"
|
81
|
+
puts "Shipping Status : #{data[:shipping_status]}"
|
82
|
+
puts "Shipping Company : #{data[:shipping_company]}"
|
83
|
+
puts "Tracking Number : #{data[:tracking_number]}"
|
84
|
+
puts
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
data/lib/dji/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Elliott
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.18.1
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.18.1
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.13'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.13'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
description: CLI and Ruby tools for drone-maker DJI's store, account, and more.
|
90
|
+
email:
|
91
|
+
- kevin@welikeinc.com
|
92
|
+
executables:
|
93
|
+
- dji
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".travis.yml"
|
100
|
+
- CODE_OF_CONDUCT.md
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- bin/console
|
106
|
+
- bin/setup
|
107
|
+
- dji.gemspec
|
108
|
+
- exe/dji
|
109
|
+
- lib/dji.rb
|
110
|
+
- lib/dji/command.rb
|
111
|
+
- lib/dji/command/base.rb
|
112
|
+
- lib/dji/command/behavior.rb
|
113
|
+
- lib/dji/commands.rb
|
114
|
+
- lib/dji/commands/track/track_command.rb
|
115
|
+
- lib/dji/commands/version/version_command.rb
|
116
|
+
- lib/dji/fedex.rb
|
117
|
+
- lib/dji/order_tracking.rb
|
118
|
+
- lib/dji/version.rb
|
119
|
+
homepage: http://github.com/kevinelliott/dji
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: CLI and Ruby tools for drone-maker DJI's store, account, and more.
|
144
|
+
test_files: []
|