grape-msgpack 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 +4 -4
- data/lib/grape/msgpack.rb +18 -3
- data/lib/grape/msgpack/version.rb +1 -1
- data/spec/grape/msgpack_spec.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 690a9f025912b9196909ce4706bc99a7d4f0c01b
|
4
|
+
data.tar.gz: 525bb299f15b84c695140f066e0e06d6f9458199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
44
|
-
|
45
|
-
|
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
|
data/spec/grape/msgpack_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|