ubox 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -3
- data/lib/ubox/configuration.rb +2 -1
- data/lib/ubox/version.rb +1 -1
- data/lib/ubox.rb +34 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: badaab7f029c707220f0f6d753abfda36ff33322
|
4
|
+
data.tar.gz: 4f09c0631f505511928b35825f2a1cc94386968c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894991f42f1a1c109a90e5853abe63857a38e07ace8a3c1735eafd7d2d6c10b3418eb0b2ba91f11c15bb6cf74a9e150606f359c86d70d6a819bd8a4991567397
|
7
|
+
data.tar.gz: 3475764e829252016a2c0b4b270e93c5e6ee69424725444ead769eb9e35d0495f4d26744272cc791972022f807037f4232fb0c16e52ab08f1bfbbcacd9a0609f
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Ubox
|
2
2
|
|
3
|
-
|
3
|
+
友宝开放api
|
4
4
|
|
5
|
-
|
5
|
+
## Status
|
6
|
+
代码 已经打包发布到 RubyGems.
|
7
|
+
|
8
|
+
[![image](https://ruby-china-files.b0.upaiyun.com/photo/5982eaaa64f467d9dbda03ad4f40ea27.png)](https://rubygems.org/gems/ubox)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -20,9 +23,55 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
$ gem install ubox
|
22
25
|
|
26
|
+
## Config
|
27
|
+
```ruby
|
28
|
+
Ubox.configure do |ubox|
|
29
|
+
ubox.app_id = 'your_app_id'
|
30
|
+
ubox.app_key = 'your_app_key'
|
31
|
+
ubox.api_url = 'http://uboxapi.dev.uboxol.com/opentrade' #正式环境请用正式环境url
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
23
35
|
## Usage
|
24
36
|
|
25
|
-
|
37
|
+
###获取商品信息(扫码)
|
38
|
+
```ruby
|
39
|
+
Ubox.product_detail('http://v.dev.uboxol.com/qr/c0081801_10000870_1')
|
40
|
+
```
|
41
|
+
|
42
|
+
```json
|
43
|
+
{
|
44
|
+
"head": {
|
45
|
+
"return_code": 200,
|
46
|
+
"return_msg": "正常响应"
|
47
|
+
},
|
48
|
+
"body": {
|
49
|
+
"vm": {
|
50
|
+
"id": "0081801",
|
51
|
+
"name": "友宝在线六层富二代完鼎测试需要改动名称完鼎测试需要改动名称完",
|
52
|
+
"address": "北京111111",
|
53
|
+
"distance": "",
|
54
|
+
"is_shop": false,
|
55
|
+
"has_box": false,
|
56
|
+
"has_meal": false,
|
57
|
+
"lat": "116.480557",
|
58
|
+
"lng": "39.960201",
|
59
|
+
"vm_connected": true
|
60
|
+
},
|
61
|
+
"product": {
|
62
|
+
"id": 10000870,
|
63
|
+
"name": "双层咖啡杯",
|
64
|
+
"oldPrice": 200,
|
65
|
+
"price": 200,
|
66
|
+
"expire_time": 1464856997,
|
67
|
+
"pic": "http://vms.dev.uboxol.com/upload/box-tmp/m/10000870/10000870.jpg?t=1357177524",
|
68
|
+
"num": 16
|
69
|
+
},
|
70
|
+
"tran_id": "100031290"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
26
75
|
|
27
76
|
## Development
|
28
77
|
|
data/lib/ubox/configuration.rb
CHANGED
data/lib/ubox/version.rb
CHANGED
data/lib/ubox.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require "ubox/version"
|
2
2
|
require 'ubox/configuration'
|
3
|
+
require 'digest'
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
3
7
|
|
4
8
|
module Ubox
|
5
9
|
extend self
|
@@ -13,4 +17,34 @@ module Ubox
|
|
13
17
|
def configure
|
14
18
|
yield(config)
|
15
19
|
end
|
20
|
+
|
21
|
+
#获取签名
|
22
|
+
def sign(params)
|
23
|
+
str = params.keys.reject { |k| k.to_sym==:sign }.sort_by { |k| k }.inject('') do |s, key|
|
24
|
+
s += "#{key}=#{params[key]}"
|
25
|
+
s
|
26
|
+
end
|
27
|
+
Digest::SHA1.hexdigest("#{str}_#{self.config.app_key}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_params(params)
|
31
|
+
params.inject([]) { |a, (k, v)| a<<"#{k}=#{v}"; a }.join("&")
|
32
|
+
end
|
33
|
+
|
34
|
+
#商品详情
|
35
|
+
def product_detail(qr_string)
|
36
|
+
params = {
|
37
|
+
app_id: self.config.app_id,
|
38
|
+
qr_string: qr_string
|
39
|
+
}
|
40
|
+
params = params.merge({sign: self.sign(params)})
|
41
|
+
|
42
|
+
url = "#{self.config.api_url}/getProductDetail"
|
43
|
+
uri = URI(url)
|
44
|
+
res = Net::HTTP.post_form(uri, params)
|
45
|
+
|
46
|
+
body = res.body
|
47
|
+
JSON.parse(body)
|
48
|
+
end
|
49
|
+
|
16
50
|
end
|