unp_smart 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1e6fab91beaa21a5e9be24293bac4c0acfb9602
4
- data.tar.gz: bd661d9892db68861023319c1cc4c076723f6a23
3
+ metadata.gz: 1363bec36e89b6ac13f1344f8124c66b3a301197
4
+ data.tar.gz: ea06b3ab4d19feb6f1b1be5bc8f5a3b6add0f8de
5
5
  SHA512:
6
- metadata.gz: e37e4ec501319ca55e096570066e5725fbdd3653a413d4173dc7f8115d540aa4beb70abf0c563f48dafc810556551972bffa559ab5b2e44c87c4be9f0954bb59
7
- data.tar.gz: 03c261effb0338e21e13a9bd401774ca4eb9b5c715c660728bb17ae2197af7ac1e2abddbdb28d4ab1f2f8335bfe8a584e57d2c837b404ae23c01c9e60fc04483
6
+ metadata.gz: 22a20c9bcd929eb47c40e15bf58f4909c5b17f35474bf5bd2ccba036b6b6f0653d6abf861edcd1ec66f9466750eb868ee9e7bb53cf122d7e5673f952ce0dc20a
7
+ data.tar.gz: 934a89bcc5fd2b0d118dbb6a5dce4390bc749dbe2dbb78e652292e714b32e620301c9485f13494145fa256f7bb16dc0f88f331883c41559f6d3a5271fa20bb27
data/.gitignore CHANGED
@@ -29,3 +29,4 @@ config/secrets.yml
29
29
  /vendor/assets/bower_components
30
30
  *.bowerrc
31
31
  bower.json
32
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unp_smart (0.0.1)
4
+ unp_smart (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ```
24
24
  development:
25
- account: '000000'
25
+ account: ''
26
26
  secret_key: ''
27
27
  server: 'https://data.unionpaysmart.com'
28
28
  debug: true
@@ -41,6 +41,7 @@ development:
41
41
 
42
42
  ## 使用
43
43
 
44
+ ### 在项目中使用
44
45
  ```
45
46
  UnpSmart.get path,params,&block
46
47
 
@@ -64,9 +65,30 @@ UnpSmart.get '/merchant/queryName',{mName: '巴黎春天'}
64
65
  * 第二个为请求的内容,如果失败为失败信息
65
66
 
66
67
 
68
+ ### 在终端中使用
69
+
70
+ 为了方便用户使用或调试,还提供了命令行的工具,按如下方式执行
71
+ ```
72
+ unpsmart [get/post] api_path key1 value1 key2 value2 [...]
73
+ ```
74
+
75
+ 前面的get或post可以省略,默认为get如
76
+
77
+ ```
78
+ unpsmart get merchant/queryName mName 巴黎春天
79
+ ```
80
+
81
+ 参数按key value传递即可,如果使用终端并且当前目录没有config/unp_smart.yml文件,程序会尝试加载用户目录下的.unp_smart.yml,如果没有您可以新建一个
82
+
83
+ ```
84
+ curl https://raw.githubusercontent.com/unpsmart/ruby-sdk/master/config/unp_smart.yml > ~/.unp_smart.yml
85
+ ```
86
+
87
+ 然后编辑这个文件即可
88
+
67
89
  ## Contributing
68
90
 
69
- 1. Fork it ( https://github.com/unpsmart/unp_smart/fork )
91
+ 1. Fork it ( https://github.com/unpsmart/ruby-sdk/fork )
70
92
  2. Create your feature branch (`git checkout -b my-new-feature`)
71
93
  3. Commit your changes (`git commit -am 'Add some feature'`)
72
94
  4. Push to the branch (`git push origin my-new-feature`)
data/bin/unpsmart ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def invoke_api http_method,api_path,params={}
4
+ require 'unp_smart'
5
+ puts "invoke api:#{http_method},#{api_path},#{params}"
6
+ if http_method == 'get'
7
+ result = UnpSmart.get api_path,params
8
+ else
9
+ result = UnpSmart.post api_path,params
10
+ end
11
+
12
+ puts "\n"
13
+ puts "-"*50
14
+ puts result
15
+ puts "-"*50
16
+ end
17
+
18
+ if ARGV.length >0
19
+ http_method = ARGV.shift
20
+ if %w{get post}.include?(http_method)
21
+ api_path = ARGV.shift
22
+ else
23
+ api_path = http_method
24
+ http_method = 'get'
25
+ end
26
+
27
+ unless ARGV.length%2 == 0
28
+ puts "Args is missed!!You should give me even values"
29
+ exit!
30
+ end
31
+
32
+ params = {}
33
+ ARGV.each_slice(2) do |item|
34
+ params[item[0]] = item[1]
35
+ end
36
+ begin
37
+ invoke_api http_method,api_path,params
38
+ rescue => e
39
+ puts "invoke api error,got:#{e}"
40
+ end
41
+ else
42
+ puts "Usage:\n\tunpsmart [get/post] api_path key1 value1 key2 value2 [...]"
43
+ end
44
+
data/config/unp_smart.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  development:
2
- account: '000000'
2
+ account: ''
3
3
  secret_key: ''
4
- server: 'http://192.168.88.105:9999'
4
+ server: 'https://data.unionpaysmart.com'
5
5
  debug: true
6
6
  verbose: false
7
7
  raw_response: true
@@ -18,6 +18,7 @@ module UnpSmart
18
18
 
19
19
  def _invoke_api http_method,api,params={}
20
20
  log "request api:#{api},params:#{params}"
21
+ raise 'api is not allowed blank!' if api.blank?
21
22
 
22
23
  @api = api
23
24
  @params = params
@@ -26,7 +27,8 @@ module UnpSmart
26
27
  @config = {} if @config.nil?
27
28
  @verbose = get_variable :verbose
28
29
 
29
- raise 'api is not allowed blank!' if api.blank?
30
+ @api = "/#{@api}" unless @api.start_with?("/")
31
+
30
32
  account = get_variable :account
31
33
  log "account:", account if @verbose
32
34
  raise 'account is not allowed blank!' if account.blank?
@@ -44,7 +46,7 @@ module UnpSmart
44
46
 
45
47
  extracted_params[:sign] = sign_params extracted_params,secret_key
46
48
 
47
- request_url = "#{get_variable :server}#{api}?#{extracted_params.map{|key,value| "#{key}=#{CGI.escape value.nil? ? "" : value.to_s}"}.join("&")}"
49
+ request_url = "#{get_variable :server}#{@api}?#{extracted_params.map{|key,value| "#{key}=#{CGI.escape value.nil? ? "" : value.to_s}"}.join("&")}"
48
50
 
49
51
  log "request:",request_url if @debug
50
52
 
@@ -60,7 +62,7 @@ module UnpSmart
60
62
  yield return_response
61
63
  else
62
64
  if get_variable(:raw_response)
63
- log "return raw response" if @debug
65
+ log "return raw response" if @verbose
64
66
  return_response
65
67
  else
66
68
  log "parse result"
@@ -90,11 +92,21 @@ module UnpSmart
90
92
 
91
93
  def load_config
92
94
  log "loading config"
93
- @config ||= YAML.load_file("#{app_root}/config/unp_smart.yml")[current_env]
95
+ path = "#{app_root}/config/unp_smart.yml"
96
+ unless File.exist?(path)
97
+ path = "#{File.expand_path('~')}/.unp_smart.yml"
98
+ log "try use home config #{path}" if @verbose
99
+
100
+ unless File.exist?(path)
101
+ log "can't load config,will use env or params config"
102
+ return
103
+ end
104
+ end
105
+ log "config file path",path
106
+ @config ||= YAML.load_file(path)[current_env]
94
107
  log "config:#{@config}" if @verbose
95
- rescue => e
96
- @config = {}
97
- log "load config error:#{e.inspect}"
108
+ # rescue => e
109
+ # log "load config error:#{e.inspect}"
98
110
  end
99
111
 
100
112
  private
@@ -113,8 +125,7 @@ module UnpSmart
113
125
  end
114
126
 
115
127
  def get_variable_from_config key
116
- @config
117
- @config[key.to_s]
128
+ @config[key.to_s] if @config.present?
118
129
  end
119
130
 
120
131
  def log *msg
@@ -1,3 +1,3 @@
1
1
  module UnpSmart
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/unp_smart.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.executables = ['unpsmart']#spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unp_smart
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
  - Martin Xu
@@ -83,7 +83,8 @@ dependencies:
83
83
  description: UnionpaySmart SDK for Ruby
84
84
  email:
85
85
  - martin.xus@gmail.com
86
- executables: []
86
+ executables:
87
+ - unpsmart
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
@@ -93,6 +94,7 @@ files:
93
94
  - LICENSE
94
95
  - README.md
95
96
  - Rakefile
97
+ - bin/unpsmart
96
98
  - config/unp_smart.yml
97
99
  - lib/unp_smart.rb
98
100
  - lib/unp_smart/unp_smart_method.rb