kuaidi100 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 619fd2596755fbb3f7bd461342d00163c59dbf40
4
+ data.tar.gz: 42cb887b59451e3e85e0af1d8772f07f64eaa58f
5
+ SHA512:
6
+ metadata.gz: 8e9e882a9cd10cb9dd6be611fe916fb081c2d048979b3304991c01391c92b0b98d88bfb3bd78b23dbe7114f9b57590f833d39fa9ff0eb3af73443edd2a1bdcce
7
+ data.tar.gz: 439428934ad979a641d2887a3b535432982f0c989b632ff6b46371e13db217b955a2f1f3567558abbd5c38a54bb9aa8b2402dcd23f712b569b0f40399c1a1534
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Kuaidi100
2
+
3
+ Kuaidi100 api
4
+
5
+ [documention][1]
6
+
7
+ [1]: http://www.kuaidi100.com/openapi/api_post.shtml#d03 'Kuaidi100'
8
+
9
+ ## USAGE
10
+
11
+ ---
12
+
13
+ ### Config
14
+
15
+ ```
16
+ Kuaidi100.key = 'Your key'
17
+
18
+ ```
19
+
20
+ ### Generate URL
21
+
22
+ ```
23
+ options = {
24
+ com: 'Delivery Company Code', # https://code.google.com/p/kuaidi-api/wiki/Open_API_API_URL
25
+ nu: 'Your Delivery Number',
26
+ show: '', # 0 is json, 1 is xml, 2 is html, 3 is text
27
+ muti: '', # 1 is mutil line, 0 is single line. default is 1.
28
+ order: 'asc or desc'
29
+ }
30
+
31
+ ```
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Kuaidi100'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,9 @@
1
+ require 'kuaidi100/version.rb'
2
+ require 'kuaidi100/utils.rb'
3
+ require 'kuaidi100/service.rb'
4
+ require 'kuaidi100/generator.rb'
5
+ module Kuaidi100
6
+ class << self
7
+ attr_accessor :key
8
+ end
9
+ end
@@ -0,0 +1,78 @@
1
+ require 'rails/generators'
2
+ module Kuaidi100
3
+ class Generator < Rails::Generators::NamedBase
4
+ def create_controller_file
5
+ route "post '#{file_name}/show'"
6
+ route "get '#{file_name}/index'"
7
+ create_file "app/controllers/#{file_name}_controller.rb", <<-FILE
8
+ class #{class_name}Controller < ApplicationController
9
+
10
+ def index
11
+ end
12
+
13
+ def show
14
+
15
+ url = URI.parse('http://api.kuaidi100.com/api')
16
+
17
+ Net::HTTP.start(url.host, url.port) do |http|
18
+
19
+ req = Net::HTTP::Post.new(url.path)
20
+
21
+ req.set_form_data({
22
+ id: "",
23
+ com: params[:com],
24
+ nu: params[:nu],
25
+ valicode:"",
26
+ show:"2",
27
+ muti:"1",
28
+ order:"desc"
29
+ })
30
+
31
+ puts http.request(req).body
32
+
33
+ @content = http.request(req).body.force_encoding("UTF-8")
34
+
35
+ end
36
+ end
37
+ end
38
+ FILE
39
+ end
40
+
41
+ def create_view_file
42
+ create_file "app/views/#{file_name}/index.html.haml", <<-FILE
43
+ =form_tag #{file_name}_show_path,role:"form" do |f|
44
+ .form-group
45
+ %label 快递单号:
46
+ =text_field_tag :nu
47
+ .form-group
48
+ .col-md-3
49
+ =select_tag 'com', options_for_select(get_com_hash.collect{ |ch| [ ch[1], ch[0] ] }), class:"form-control"
50
+ .form-group
51
+ =submit_tag "自助查询", class: "btn btn-success"
52
+ FILE
53
+
54
+ create_file "app/views/#{file_name}/show.html.haml", <<-FILE
55
+ %hr
56
+ :javascript
57
+ document.write("#{'#{@content}'}");
58
+ FILE
59
+ end
60
+
61
+ def create_helper_file
62
+ create_file "app/helpers/#{file_name}_helper.rb", <<-FILE
63
+ module #{class_name}Helper
64
+ def get_com_hash
65
+ @com_hash ={
66
+ "tiantian"=>"天天",
67
+ "shentong"=>"申通",
68
+ "yuantong"=>"圆通",
69
+ "shunfeng"=>"顺丰",
70
+ "debangwuliu"=>"德邦",
71
+ "yunda"=>"韵达"
72
+ }
73
+ end
74
+ end
75
+ FILE
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,22 @@
1
+ require 'cgi'
2
+
3
+ module Kuaidi100
4
+ module Service
5
+ KUAIDI100_URL = 'http://api.kuaidi100.com/api'
6
+
7
+ def self.create_url(options = {})
8
+ options = { 'id' => Kuaidi100.key }.merge(Utils.stringify_keys(options))
9
+ "#{ KUAIDI100_URL }?#{query_string(options)}"
10
+ end
11
+
12
+ def self.query_string(options)
13
+ options.map do |key, value|
14
+ "#{ CGI.escape(key.to_s) }=#{ CGI.escape(value.to_s) }"
15
+ end.join('&')
16
+ end
17
+
18
+ # TODO: check params
19
+ def check_query
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Kuaidi100
2
+ module Utils
3
+ def self.stringify_keys(hash)
4
+ new_hash = {}
5
+ hash.each do |key, value|
6
+ new_hash[(key.to_s rescue key) || key] = value
7
+ end
8
+ new_hash
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Kuaidi100
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kuaidi100 do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ module Kuaidi100
3
+ class UtilsTest < Test::Unit::TestCase
4
+ def test_stringify_keys
5
+ hash = { 'a' => 1, :b => 2 }
6
+ assert_equal({ 'a' => 1, 'b' => 2 }.sort, Kuaidi100::Utils.stringify_keys(hash).sort)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'test_helper'
2
+ class Kuaidi100Test < Test::Unit::TestCase
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'kuaidi100'
3
+
4
+ Kuaidi100.key = 'Your key' # Yourself key
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuaidi100
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mr.Passer-by
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of Kuaidi100.
42
+ email:
43
+ - dr397379567@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/kuaidi100.rb
52
+ - lib/kuaidi100/generator.rb
53
+ - lib/kuaidi100/service.rb
54
+ - lib/kuaidi100/utils.rb
55
+ - lib/kuaidi100/version.rb
56
+ - lib/tasks/kuaidi100_tasks.rake
57
+ - test/kuaidi100/utils_test.rb
58
+ - test/kuaidi100_test.rb
59
+ - test/test_helper.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Summary of Kuaidi100.
84
+ test_files:
85
+ - test/kuaidi100_test.rb
86
+ - test/kuaidi100/utils_test.rb
87
+ - test/test_helper.rb