grape-msgpack 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd48218f961f5483fe6ee240467e0c94f98c6063
4
+ data.tar.gz: 29de7ae2759c8f0bfdd97a7c0a23259e6db0c920
5
+ SHA512:
6
+ metadata.gz: a25e281c2bc76cfb875609ddc37fdb6989cf371e9eb109b94bad133eb3ed3b3b52c560e01df2cf48d393d710c8a984fe44df6760838d3dd64f2f285d458940a2
7
+ data.tar.gz: bb42efd5b3ced23b92e2690afd34177c3c042515b21e482d2a9e7b947e8f56e374b27443be5bb1b46bd592fc9bb826aba3ad6064bdf7b675d75a5fdc10713aa7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-msgpack.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sho Kusano
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Grape::Msgpack
2
+
3
+ [![Build Status](https://travis-ci.org/rosylilly/grape-msgpack.png?branch=master)](https://travis-ci.org/rosylilly/grape-msgpack)
4
+
5
+ Message pack formatter for grape.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'grape-msgpack'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grape-msgpack
20
+
21
+ ## Usage
22
+
23
+ set default format msgpack:
24
+
25
+ ```ruby
26
+ class TwitterAPI < Grape::API
27
+ default_format :msgpack
28
+ end
29
+ ```
30
+
31
+ and grape-msgpack supoorts grape-entity:
32
+
33
+ ```ruby
34
+ class ModelEntity < Grape::Entity
35
+ expose :id
36
+ end
37
+
38
+ class ModelAPI < Grape::API
39
+ default_format :msgpack
40
+
41
+ get ':id' do
42
+ present Model.find(params[:id]), with: ModelEntity
43
+ # => { 'id' => 1 }
44
+ end
45
+ end
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape/msgpack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape-msgpack"
8
+ spec.version = Grape::Msgpack::VERSION
9
+ spec.authors = ["Sho Kusano"]
10
+ spec.email = ["rosylilly@aduca.org"]
11
+ spec.summary = %q{msgpack formatter for grape}
12
+ spec.description = %q{msgpack formatter for grape}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
24
+ spec.add_development_dependency 'rack-test', '~> 0.6.2'
25
+ spec.add_development_dependency 'grape-entity', '~> 0.3.0'
26
+
27
+ spec.add_dependency 'grape', '~> 0.6.0'
28
+ spec.add_dependency 'msgpack', '~> 0.5.6'
29
+ end
@@ -0,0 +1 @@
1
+ require 'grape/msgpack'
@@ -0,0 +1,34 @@
1
+ require 'msgpack'
2
+ require 'grape'
3
+ require 'grape/msgpack/version'
4
+
5
+ module Grape
6
+ # Message pack formatter for Grape
7
+ module Msgpack
8
+ class << self
9
+ def call(obj, env)
10
+ return obj.to_msgpack if obj.respond_to?(:to_msgpack)
11
+ MessagePack.pack(obj)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class << Grape::Formatter::Base
18
+ FORMATTERS[:msgpack] = Grape::Msgpack
19
+ end
20
+
21
+ class << Grape::ErrorFormatter::Base
22
+ FORMATTERS[:msgpack] = Grape::Msgpack
23
+ end
24
+
25
+ Grape::ContentTypes::CONTENT_TYPES[:msgpack] = 'application/x-msgpack'
26
+
27
+ if defined?(Grape::Entity)
28
+ class Grape::Entity
29
+ def to_msgpack(options = {})
30
+ options = options.to_h if options && options.respond_to?(:to_h)
31
+ MessagePack.pack(serializable_hash(options))
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Grape
2
+ module Msgpack
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'rack/test'
3
+ require 'grape-entity'
4
+ require 'grape/msgpack'
5
+
6
+ class MockModel
7
+ def initialize(name, age)
8
+ @name = name
9
+ @age = age
10
+ end
11
+ attr_reader :name, :age
12
+ end
13
+
14
+ class MockEntity < Grape::Entity
15
+ expose :name
16
+ end
17
+
18
+ class MockAPI < Grape::API
19
+ default_format :msgpack
20
+
21
+ get :test do
22
+ [1, 2, 3]
23
+ end
24
+
25
+ get :model do
26
+ present MockModel.new('test_user', 21), with: MockEntity
27
+ end
28
+ end
29
+
30
+ describe MockAPI do
31
+ include Rack::Test::Methods
32
+
33
+ def app
34
+ MockAPI
35
+ end
36
+
37
+ describe 'GET /test' do
38
+ subject(:response) do
39
+ get '/test'
40
+ last_response
41
+ end
42
+
43
+ it { expect(response.status).to eq(200) }
44
+ it { expect(response.headers["Content-Type"]).to eq('application/x-msgpack') }
45
+ it { expect(MessagePack.unpack(response.body)).to eq([1, 2, 3]) }
46
+ end
47
+
48
+ describe 'GET /model' do
49
+ subject(:response) do
50
+ get '/model'
51
+ last_response
52
+ end
53
+
54
+ it { expect(response.status).to eq(200) }
55
+ it { expect(response.headers["Content-Type"]).to eq('application/x-msgpack') }
56
+ it { expect(MessagePack.unpack(response.body)).to eq("name" => "test_user") }
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-msgpack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sho Kusano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: grape-entity
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: grape
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.6.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: msgpack
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.6
111
+ description: msgpack formatter for grape
112
+ email:
113
+ - rosylilly@aduca.org
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - grape-msgpack.gemspec
126
+ - lib/grape-msgpack.rb
127
+ - lib/grape/msgpack.rb
128
+ - lib/grape/msgpack/version.rb
129
+ - spec/grape/msgpack_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: ''
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.1.9
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: msgpack formatter for grape
155
+ test_files:
156
+ - spec/grape/msgpack_spec.rb
157
+ - spec/spec_helper.rb