olive_branch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1547ffafacf7baa2b3c55a911c4b943b09f0cfe
4
+ data.tar.gz: 81463b9e8ada7c5bacfe04c7edbbc3d5d5765107
5
+ SHA512:
6
+ metadata.gz: ed68fde9ecd1176b9b93046575fa868823b4eabbb4b9f937470aa357d93245d6b9dd6be23c2a745286f0feddd03d6ede0ee8351300202c4e2739c7b2b3c9a938
7
+ data.tar.gz: a1e5a53e095253afa619b5ac93bbe73f27bd7ec73d7888214589c9e92cb0a9add2b156228755b71f2073f91c2d41bc9b9b296da37489a1ef1bea1e193a5f1625
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Eli Fatsi (Viget)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # OliveBranch
2
+
3
+ [![Code Climate](https://codeclimate.com/github/vigetlabs/olive_branch.png)](https://codeclimate.com/github/vigetlabs/olive_branch)
4
+
5
+ This gem lets your API users pass in and receive camelCased or dash-cased keys, while your Rails app receives and produces snake_cased ones.
6
+
7
+ ## Install
8
+
9
+ 1. Add this to your Gemfile and then `bundle install`:
10
+
11
+ gem "olive_branch"
12
+
13
+ 2. Add this to `config/applcation.rb`:
14
+
15
+ config.middleware.use "OliveBranch::Middleware"
16
+
17
+ ## Use
18
+
19
+ Include a `Key-Inflection` header with values of `camel`, `dash`, or `snake` in your JSON API requests.
20
+
21
+
22
+ * * *
23
+
24
+ OliveBranch is released under the [MIT License](http://www.opensource.org/licenses/MIT). See MIT-LICENSE for further details.
25
+
26
+ * * *
27
+
28
+ <a href="http://code.viget.com">
29
+ <img src="http://code.viget.com/github-banner.png" alt="Code At Viget">
30
+ </a>
31
+
32
+ Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget.](https://viget.com)
@@ -0,0 +1,3 @@
1
+ module OliveBranch
2
+ autoload :Middleware, "olive_branch/middleware"
3
+ end
@@ -0,0 +1,31 @@
1
+ module OliveBranch
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ inflection = env["HTTP_KEY_INFLECTION"]
9
+
10
+ if inflection && env["CONTENT_TYPE"] =~ /application\/json/
11
+ env["action_dispatch.request.request_parameters"].deep_transform_keys!(&:underscore)
12
+ end
13
+
14
+ status, headers, response = @app.call(env)
15
+
16
+ if inflection && headers["Content-Type"] =~ /application\/json/
17
+ new_response = JSON.parse(response.body)
18
+
19
+ if inflection == "camel"
20
+ new_response.deep_transform_keys! { |k| k.camelize(:lower) }
21
+ elsif inflection == "dash"
22
+ new_response.deep_transform_keys!(&:dasherize)
23
+ end
24
+
25
+ [status, headers, [new_response.to_json]]
26
+ else
27
+ [status, headers, response]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module OliveBranch
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: olive_branch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Fatsi
8
+ - David Eisinger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '4.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '4.0'
28
+ description: Handle camel/snake/dash case conversion
29
+ email:
30
+ - eli.fatsi@viget.com
31
+ - david.eisinger@viget.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - lib/olive_branch.rb
39
+ - lib/olive_branch/middleware.rb
40
+ - lib/olive_branch/version.rb
41
+ homepage: https://github.com/vigetlabs/olive_branch
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Handle camel/snake/dash case conversion
65
+ test_files: []