express-search 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in express-search.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ express-search (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.8)
10
+ crack (0.4.2)
11
+ safe_yaml (~> 1.0.0)
12
+ diff-lcs (1.2.5)
13
+ rake (10.4.2)
14
+ rspec (3.2.0)
15
+ rspec-core (~> 3.2.0)
16
+ rspec-expectations (~> 3.2.0)
17
+ rspec-mocks (~> 3.2.0)
18
+ rspec-core (3.2.3)
19
+ rspec-support (~> 3.2.0)
20
+ rspec-expectations (3.2.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.2.0)
23
+ rspec-mocks (3.2.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.2.0)
26
+ rspec-support (3.2.2)
27
+ safe_yaml (1.0.4)
28
+ webmock (1.21.0)
29
+ addressable (>= 2.3.6)
30
+ crack (>= 0.3.2)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.8)
37
+ express-search!
38
+ rake (~> 10.0)
39
+ rspec (~> 3.2.0)
40
+ webmock (~> 1.21.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 chilwar
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,39 @@
1
+ # Express::Search
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/express/search`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'express-search'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install express-search
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/express-search/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "express/search"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'express/search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "express-search"
8
+ spec.version = Express::Search::VERSION
9
+ spec.authors = ["chilwar"]
10
+ spec.email = ["136744469@qq.com"]
11
+ spec.date = "2015-05-05"
12
+
13
+ spec.summary = %q{used for china express search}
14
+ spec.description = %q{used for china express search}
15
+ spec.homepage = "http://github.com/chilwar/express-search"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = [
19
+ ".rspec",
20
+ ".travis.yml",
21
+ "CODE_OF_CONDUCT.md",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "express-search.gemspec",
28
+ "bin/console",
29
+ "bin/setup",
30
+ "lib/express/search.rb",
31
+ "lib/express/search/company.rb",
32
+ "lib/express/search/result.rb",
33
+ "lib/express/search/version.rb",
34
+ "spec/express/search_spec.rb",
35
+ "spec/express/search/company_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.8"
43
+ spec.add_development_dependency "rake", "~> 10.0"
44
+
45
+ if spec.respond_to? :specification_version then
46
+ spec.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ spec.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
50
+ spec.add_development_dependency(%q<webmock>, ["~> 1.21.0"])
51
+ else
52
+ spec.add_dependency(%q<rspec>, ["~> 3.2.0"])
53
+ spec.add_dependency(%q<webmock>, ["~> 1.21.0"])
54
+ end
55
+ else
56
+ spec.add_dependency(%q<rspec>, ["~> 3.2.0"])
57
+ spec.add_dependency(%q<webmock>, ["~> 1.21.0"])
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Express
3
+ module Search
4
+ module Company
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ MATCHES = {
11
+ /顺丰/ => 'shunfeng',
12
+ /ems/i => 'ems',
13
+ /申通/ => 'shentong',
14
+ /圆通/ => 'yuantong',
15
+ /中通/ => 'zhongtong',
16
+ /宅急送/ => 'zhaijisong',
17
+ /韵达/ => 'yunda',
18
+ /天天/ => 'tiantian',
19
+ /联邦|Fedex/i => 'fedexcn',
20
+ /汇通/ => 'huitong'
21
+ }
22
+
23
+ module ClassMethods
24
+ def company_code(name)
25
+ result = ''
26
+ MATCHES.each do |pattern, code|
27
+ if name =~ pattern
28
+ result = code
29
+ break
30
+ end
31
+ end
32
+ result
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Express
3
+ module Search
4
+ class Result
5
+ attr_reader :status, :data, :message
6
+
7
+ def initialize(json)
8
+ @status, @data, @message = json['status'], json['data'], json['message']
9
+ end
10
+
11
+ def success?
12
+ status == "3"
13
+ end
14
+
15
+ def to_s
16
+ {success: success?, message: message, data: data}.to_s
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Express
2
+ module Search
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "express/search/version"
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'express/search/result'
7
+ require 'express/search/company'
8
+
9
+ module Express
10
+ module Search
11
+ include Express::Search::Company
12
+
13
+ class << self
14
+ attr_accessor :id, :secret
15
+ end
16
+
17
+ def self.get_result(nu, com, type = "json", encode = "utf8", ord = "asc")
18
+ uri = URI('http://api.ickd.cn')
19
+ uri.query = URI.encode_www_form({
20
+ id: id,
21
+ secret: secret,
22
+ nu: nu,
23
+ com: company_code(com),
24
+ type: type,
25
+ encode: encode,
26
+ ord: ord
27
+ })
28
+
29
+ Express::Search::Result.new JSON.parse(Net::HTTP.get_response(uri).body)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe "Company" do
5
+
6
+ let(:list) do
7
+ {
8
+ '顺丰快递' => 'shunfeng',
9
+ '顺丰' => 'shunfeng',
10
+ 'EMS' => 'ems',
11
+ 'ems' => 'ems',
12
+ '申通E物流' => 'shentong',
13
+ '申通快递' => 'shentong',
14
+ '申通' => 'shentong',
15
+ '圆通快递' => 'yuantong',
16
+ '圆通速递' => 'yuantong',
17
+ '圆通' => 'yuantong',
18
+ '中通速递' => 'zhongtong',
19
+ '中通' => 'zhongtong',
20
+ '宅急送快递' => 'zhaijisong',
21
+ '宅急送' => 'zhaijisong',
22
+ '韵达快运' => 'yunda',
23
+ '韵达快递' => 'yunda',
24
+ '天天快递' => 'tiantian',
25
+ '联邦快递' => 'fedexcn',
26
+ 'Fedex国内' => 'fedexcn',
27
+ '汇通快运' => 'huitong',
28
+ '汇通快递' => 'huitong'
29
+ }
30
+ end
31
+
32
+ let(:id) { 136744469 }
33
+
34
+ let(:secret) { "chilwar" }
35
+
36
+ let(:express) { Express::Search }
37
+
38
+ it "Should be search" do
39
+ express.id = id
40
+ express.secret = secret
41
+ list.each do |name, code|
42
+ express.company_code(name).should eql code
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../../spec_helper', __FILE__)
3
+
4
+ describe Express::Search do
5
+
6
+ let(:id) { 136744469 }
7
+
8
+ let(:secret) { "chilwar" }
9
+
10
+ let(:nu) { 12345 }
11
+
12
+ let(:company) { "圆通" }
13
+
14
+ let(:com) { "yuantong" }
15
+
16
+ let(:body) do
17
+ {
18
+ status: "3",
19
+ message: "",
20
+ errCode: "",
21
+ data: [
22
+ { time: "2015-03-17 20:40", content: "上海市长宁区东部公司 已收件" },
23
+ { time: "2015-03-17 20:42", content: "上海市长宁区东部公司 已打包" },
24
+ { time: "2015-03-18 21:11", content: "天津转运中心公司 已拆包" },
25
+ { time: "2015-03-18 23:00", content: "天津转运中心公司 已发出" },
26
+ { time: "2015-03-19 08:06", content: "天津市滨海新区滨海公司 已收入" },
27
+ { time: "2015-03-19 08:38", content: "天津市滨海新区滨海公司 派件中" },
28
+ { time: "2015-03-19 13:13", content: "天津市滨海新区滨海公司 已签收" }
29
+ ]
30
+ }.to_json.to_s
31
+ end
32
+
33
+ before do
34
+ stub_request(:get, "http://api.ickd.cn?id=#{ id }&secret=#{ secret }&nu=#{ nu }&com=#{ com }&encode=utf8&ord=asc&type=json").to_return(body: body)
35
+ WebMock.disable_net_connect!
36
+ end
37
+
38
+ it "Should be search" do
39
+ Express::Search.id = id
40
+ Express::Search.secret = secret
41
+ result = Express::Search.get_result("12345", "圆通")
42
+ result.success?.should be_truthy
43
+ result.data.should_not be_empty
44
+ end
45
+
46
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+ require 'express/search'
5
+
6
+ RSpec.configure do |config|
7
+ config.raise_errors_for_deprecations!
8
+
9
+ config.expect_with(:rspec) { |c| c.syntax = :should }
10
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: express-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chilwar
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-05-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.8'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.21.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.21.0
78
+ description: used for china express search
79
+ email:
80
+ - 136744469@qq.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .rspec
86
+ - .travis.yml
87
+ - CODE_OF_CONDUCT.md
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - express-search.gemspec
94
+ - bin/console
95
+ - bin/setup
96
+ - lib/express/search.rb
97
+ - lib/express/search/company.rb
98
+ - lib/express/search/result.rb
99
+ - lib/express/search/version.rb
100
+ - spec/express/search_spec.rb
101
+ - spec/express/search/company_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: http://github.com/chilwar/express-search
104
+ licenses:
105
+ - MIT
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.23.2
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: used for china express search
128
+ test_files: []