Class: Eurus::WeiboRedEnvelope
- Inherits:
-
Object
- Object
- Eurus::WeiboRedEnvelope
- Defined in:
- lib/eurus-weibo-commercial.rb
Constant Summary collapse
- ACTION =
["add","query","update"]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key = "") ⇒ WeiboRedEnvelope
constructor
A new instance of WeiboRedEnvelope.
-
#red_envelope_template(opt = "add", params) ⇒ Object
params = { title: “test-tpl”, firm_id: “you firm id from weibo”, show_id: “you id you wanna display”, share_info: “hello world”, share_url: “eurus.cn” }.
-
#send_red_envelope(params) ⇒ Object
params = { out_order_id: “”, tpl_id: “”, amount: “”, uid: “” }.
Constructor Details
#initialize(key = "") ⇒ WeiboRedEnvelope
Returns a new instance of WeiboRedEnvelope.
38 39 40 |
# File 'lib/eurus-weibo-commercial.rb', line 38 def initialize(key="") @key = key end |
Class Method Details
.md5_with_partner_key(params, key) ⇒ Object
82 83 84 85 86 |
# File 'lib/eurus-weibo-commercial.rb', line 82 def self.md5_with_partner_key(params,key) str = params.sort.map { |item| item.join('=') }.join('&') str << "#{key}" Digest::MD5.hexdigest(str) end |
Instance Method Details
#red_envelope_template(opt = "add", params) ⇒ Object
params =
title: "test-tpl",
firm_id: "you firm id from weibo",
show_id: "you id you wanna display",
share_info: "hello world",
share_url: "http://eurus.cn"
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/eurus-weibo-commercial.rb', line 48 def red_envelope_template(opt="add",params) # opt includes add query update if WeiboRedEnvelope::ACTION.include? opt uri = URI "http://hb.e.weibo.com/v2/bonus/c/set/#{opt}" sign = self.class.md5_with_partner_key(params, @key) req = Net::HTTP::Post.new(uri) req.set_form_data(params.merge(sign: sign,sign_type: 'md5')) res = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end return JSON.parse res.body else return "Invalid Operation Type" end end |
#send_red_envelope(params) ⇒ Object
params =
out_order_id: "",
tpl_id: "",
amount: "",
uid: ""
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/eurus-weibo-commercial.rb', line 70 def send_red_envelope(params) uri = URI "http://hb.e.weibo.com/v2/bonus/c/create" sign = self.class.md5_with_partner_key(params, @key) req = Net::HTTP::Post.new(uri) req.set_form_data(params.merge(sign: sign,sign_type: 'md5')) res = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end return JSON.parse res.body end |