Commit e63d88f2 by lanrion

Merge pull request #23 from lanrion/replace-multi_json-with-yajl-ruby-21

replace multi_json with yajl #21
parents 4ee383b1 c6731265
source 'https://rubygems.org'
gem "rspec", "~> 3.0.0.beta1"
gem "redis-namespace", "~> 1.4.1"
gem "rake", "~> 0.9.6"
gem 'simplecov', '~> 0.7.1', :require => false
gem "codeclimate-test-reporter", require: nil
gem 'coveralls', require: false
group :test do
gem "rspec", "~> 3.0.0.beta1"
gem "redis-namespace", "~> 1.4.1"
gem "rake", "~> 0.9.6"
gem 'simplecov', '~> 0.7.1', :require => false
gem "codeclimate-test-reporter", require: nil
gem 'coveralls', require: false
end
group :development do
# For debugger
gem "pry-rails", "~> 0.3.2"
......
require "rest-client"
require "multi_json"
require 'yajl/json_gem'
require "weixin_authorize/config"
require "weixin_authorize/handler"
require "weixin_authorize/api"
require "weixin_authorize/client"
MultiJson.use :yajl
module WeixinAuthorize
# Storage
......@@ -27,7 +25,7 @@ module WeixinAuthorize
def http_post_without_token(url, payload={}, headers={}, endpoint="plain")
post_api_url = endpoint_url(endpoint, url)
payload = MultiJson.dump(payload) if endpoint == "plain" # to json if invoke "plain"
payload = JSON.dump(payload) if endpoint == "plain" # to json if invoke "plain"
load_json(RestClient.post(post_api_url, payload, :params => headers))
end
......
......@@ -20,7 +20,7 @@ module WeixinAuthorize
# 自定义菜单创建接口
# https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
def create_menu(menu)
menu = MultiJson.load(menu) if menu.is_a?(String)
menu = JSON.load(menu) if menu.is_a?(String)
create_menu_url = "#{menu_base_url}/create"
http_post(create_menu_url, menu)
end
......
......@@ -5,7 +5,7 @@ describe WeixinAuthorize::Api::Menu do
it "can create a menu" do
menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
response = $client.create_menu(MultiJson.load(menu)) # or Json string
response = $client.create_menu(JSON.load(menu)) # or Json string
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
......
......@@ -15,7 +15,7 @@
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require "rspec"
require "weixin_authorize"
require "multi_json"
require 'yajl/json_gem'
require "redis"
require "redis-namespace"
......
......@@ -19,9 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_dependency "rest-client", ">= 1.6.7"
spec.add_dependency "multi_json", "~> 1.9.0"
spec.add_dependency "redis", "~> 3.0.7"
# A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)
# https://github.com/brianmario/yajl-ruby
spec.add_dependency "yajl-ruby", "~> 1.2.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment