kuaidi100_rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc85d77ce9cfc5dc2aab203ae1d40f99690d1767
4
- data.tar.gz: 5280227fa64531c1fe37d47d838421a4a53de8b6
3
+ metadata.gz: 3bc2fe0e0bdbde3cf91ff10baf0b16907a40a23f
4
+ data.tar.gz: dde3a8bfd27906027e66e5b1bb442e60cd261c64
5
5
  SHA512:
6
- metadata.gz: ba1998fcdb5b16dcd1a3f2a31094afa12e122fce6445acf8d484252d2019ad0f76e415a9b69f53d182da414d8a86bec89b0a6d29d7a3a4d98f2c5370537afe63
7
- data.tar.gz: 78e68b87667dba9b19b39915c396481c7fc9df18c72b6375a4d505b7aac2eae953390ea1a5374a36935738f63bb267f7dcfe39afde57210954ff6d7511a6fb45
6
+ metadata.gz: 6b1cf7674ce685019e3aa2b0dc792b784bcf1c4c465e1b4ddc2a0da21eb8e149287df640cf92d3e06100566c854209ff77977d0229d64c1338d979cfb338d4c2
7
+ data.tar.gz: 998c7947eddaee8330f79ae54653d43002bdf72ddc3dc154e931efb8f865b629a11b9d0637b3e2f8bc312ee6a9cb8711fcbacca32a9cd28d0b2d9fd23c1ff58c
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
22
22
  raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
23
  end
24
24
 
25
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|pkg)/}) }
26
26
  spec.bindir = "exe"
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.9"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "faraday", "~> 0.9"
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module Kuaidi100Rails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,12 +2,16 @@ require "kuaidi100_rails/version"
2
2
  require 'open-uri'
3
3
  require 'net/http'
4
4
  require 'json'
5
+ require 'faraday'
5
6
 
6
7
  module Kuaidi100Rails
7
8
  API_URL = 'http://api.kuaidi100.com/api'
9
+ SUBSCRIBE_URL = 'http://www.kuaidi100.com/poll'
8
10
 
9
11
  class << self
10
12
  attr_accessor :API_KEY
13
+ attr_accessor :POLL_KEY
14
+ attr_accessor :POLL_CALLBACK_URL
11
15
  end
12
16
 
13
17
  module_function
@@ -15,8 +19,9 @@ module Kuaidi100Rails
15
19
  def crawl(com, nu)
16
20
  begin
17
21
  url = URI.parse(API_URL)
18
- params = {:com => com, :nu => nu, :id => Kuaidi100Rails.API_KEY, :show => 0, :muti => 1, :order => 'desc'}
22
+ params = {:id => Kuaidi100Rails.API_KEY, :com => com, :nu => nu, :show => 0, :muti => 1, :order => 'desc'}
19
23
  url.query = URI.encode_www_form(params)
24
+ p url
20
25
  res = Net::HTTP.get(url)
21
26
  hash = SHash.new(JSON.parse(res))
22
27
  p hash
@@ -25,6 +30,43 @@ module Kuaidi100Rails
25
30
  end
26
31
  end
27
32
 
33
+ #subscribe express
34
+ #===Parameters==
35
+ #+com+ company code
36
+ #+nu+ express number
37
+ #+from+ start from address
38
+ #+to+ destination address
39
+ #+salt+ random signature string
40
+ def subscribe(com, nu, from, to, salt=nil)
41
+ begin
42
+ body = {
43
+ company: com,
44
+ number: nu,
45
+ from: from,
46
+ to: to,
47
+ key: Kuaidi100Rails.POLL_KEY,
48
+ parameters: {
49
+ callbackurl: Kuaidi100Rails.POLL_CALLBACK_URL,
50
+ salt: salt,
51
+ resultv2: '1'
52
+ }
53
+ }
54
+ p body
55
+
56
+ response = Faraday.new(:url => SUBSCRIBE_URL).post do |req|
57
+ req.headers['Content-Type'] = 'application/json'
58
+ req.params[:schema] = 'json'
59
+ req.params[:param] = body.to_json
60
+ end
61
+
62
+ hash = SHash.new(JSON.parse(response.body))
63
+ p hash
64
+
65
+ rescue Exception => e
66
+ puts "error #{e}"
67
+ end
68
+ end
69
+
28
70
  class SHash < Hash
29
71
 
30
72
  def initialize(json_object=nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuaidi100_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
41
55
  description: kuaidi100 api gems for rails
42
56
  email:
43
57
  - 15201280641@qq.com