grape-msgpack 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 657b31b1af2440ab58802c5b8149276ee4267f7c
4
- data.tar.gz: 818f783c40414a4d77cbb1ce42b05f77312136c4
3
+ metadata.gz: 690a9f025912b9196909ce4706bc99a7d4f0c01b
4
+ data.tar.gz: 525bb299f15b84c695140f066e0e06d6f9458199
5
5
  SHA512:
6
- metadata.gz: e941760b158015021bef24ab2c39d24b1cdb52e342612e74a3982ca9a65cab7bb8436c13e158175529b5c1f88af96b42315467513031c757cf68beb7dda3fa1d
7
- data.tar.gz: 57c15559fd2b0aab630ad8c6879a148eb9816a2bb3402414b964da6ca8ae65cff48e283ba98f13a3f9d2867f7081474a7768f7df1fe7b66dcd2b2e0cb7779a99
6
+ metadata.gz: 688152be70811708ddec548d66b9f406825f8368b6d270cb6ef41d53086edf6a830e642ba0ef5fd5dda779807b9e335c756d9b4d8db6f79a446369d5369ab4d7
7
+ data.tar.gz: 4d7cc29f80e6adb07805a369a1ef2795bf6712fb0072c117017371f0e489e74a34559ba9ac6bdb8b031123b0a406308afa84badd8a9d0cc328a5b41e09d6e6c4
data/lib/grape/msgpack.rb CHANGED
@@ -25,6 +25,14 @@ module Grape
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ module Parser
30
+ class << self
31
+ def call(object, env)
32
+ MessagePack.unpack(object)
33
+ end
34
+ end
35
+ end
28
36
  end
29
37
  end
30
38
 
@@ -36,13 +44,20 @@ class << Grape::ErrorFormatter::Base
36
44
  FORMATTERS[:msgpack] = Grape::Msgpack::ErrorFormatter
37
45
  end
38
46
 
47
+ class << Grape::Parser::Base
48
+ PARSERS[:msgpack] = Grape::Msgpack::Parser
49
+ end
50
+
39
51
  Grape::ContentTypes::CONTENT_TYPES[:msgpack] = 'application/x-msgpack'
40
52
 
41
53
  if defined?(Grape::Entity)
42
54
  class Grape::Entity
43
- def to_msgpack(options = {})
44
- options = options.to_h if options && options.respond_to?(:to_h)
45
- MessagePack.pack(serializable_hash(options))
55
+ def to_msgpack(pack = nil)
56
+ if pack
57
+ pack.write(serializable_hash)
58
+ else
59
+ MessagePack.pack(serializable_hash)
60
+ end
46
61
  end
47
62
  end
48
63
  end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Msgpack
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -28,9 +28,20 @@ class MockAPI < Grape::API
28
28
  present MockModel.new('test_user', 21), with: MockEntity
29
29
  end
30
30
 
31
+ get :models do
32
+ present [MockModel.new('test_user', 21)], with: MockEntity
33
+ end
34
+
31
35
  get :exception do
32
36
  raise StandardError, 'an error occurred'
33
37
  end
38
+
39
+ params do
40
+ requires :name, type: String
41
+ end
42
+ post :input do
43
+ present name: params.name
44
+ end
34
45
  end
35
46
 
36
47
  describe MockAPI do
@@ -62,6 +73,17 @@ describe MockAPI do
62
73
  it { expect(MessagePack.unpack(response.body)).to eq('name' => 'test_user') }
63
74
  end
64
75
 
76
+ describe 'GET /models' do
77
+ subject(:response) do
78
+ get '/models'
79
+ last_response
80
+ end
81
+
82
+ it { expect(response.status).to eq(200) }
83
+ it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
84
+ it { expect(MessagePack.unpack(response.body).first).to eq('name' => 'test_user') }
85
+ end
86
+
65
87
  describe 'GET /exception' do
66
88
  subject(:response) do
67
89
  get '/exception'
@@ -72,4 +94,16 @@ describe MockAPI do
72
94
  it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
73
95
  it { expect(MessagePack.unpack(response.body)).to eq('error' => 'an error occurred') }
74
96
  end
97
+
98
+ describe 'POST /input' do
99
+ subject(:response) do
100
+ header 'Content-Type', 'application/x-msgpack'
101
+ post '/input', { name: 'joe' }.to_msgpack
102
+ last_response
103
+ end
104
+
105
+ it { expect(response.status).to eq 201 }
106
+ it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
107
+ it { expect(MessagePack.unpack(response.body)).to eq('name' => 'joe') }
108
+ end
75
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-msgpack
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
  - Sho Kusano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler