ubox 0.1.1 → 0.1.2

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: e2c5d1acec7663f83a8dc911b0975208991c9188
4
- data.tar.gz: 7553404e7cbc91a3ca0dad87470cccaac1c672af
3
+ metadata.gz: badaab7f029c707220f0f6d753abfda36ff33322
4
+ data.tar.gz: 4f09c0631f505511928b35825f2a1cc94386968c
5
5
  SHA512:
6
- metadata.gz: e1d8ddb4798cf37d2f6c64897305746296c35c561bf818ee45df9cfa5f7241f8e10d90c527ad37be522af751d3036c0be7912f5f0935136ff0dcb86c5581e734
7
- data.tar.gz: 9f9d019c1608fc5788394f25b82d86fbfa26a6bd8378456261eb2af83982440d21115f8403f05598e37ac549f56f3edad71c71471cf3a3671ec5a44d087108df
6
+ metadata.gz: 894991f42f1a1c109a90e5853abe63857a38e07ace8a3c1735eafd7d2d6c10b3418eb0b2ba91f11c15bb6cf74a9e150606f359c86d70d6a819bd8a4991567397
7
+ data.tar.gz: 3475764e829252016a2c0b4b270e93c5e6ee69424725444ead769eb9e35d0495f4d26744272cc791972022f807037f4232fb0c16e52ab08f1bfbbcacd9a0609f
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Ubox
2
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/ubox`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ 友宝开放api
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
 
@@ -1,6 +1,7 @@
1
- module Entinfo
1
+ module Ubox
2
2
  class Configuration
3
3
  attr_accessor :app_id
4
4
  attr_accessor :app_key
5
+ attr_accessor :api_url
5
6
  end
6
7
  end
data/lib/ubox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ubox
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saxer