faraday-mashify 0.1.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
+ SHA256:
3
+ metadata.gz: a10cc6c215894861271005a7a255b82984859267d41de46af0de0f7626590798
4
+ data.tar.gz: 8883fa62d08ecc8808f6af6dd5a40f1ab134c28c350be2a80059dc1bcc8b11d4
5
+ SHA512:
6
+ metadata.gz: 8c0f6d304562b78cd71e830b65f59024f19058790e879f333ea9863fc01563415a805f9f1d40bb353f72f1113e13fd81d0f6036a02892083ff6238a50000f3d2
7
+ data.tar.gz: c1c2dc91234cac3ae59864f057cc4efc20049a3cf34f2ef5155b6a0ded170a7078aa91df637c7b51bb0d6023d7622fa69691dbd3cc1b1e1d51a85187bb8e0eb4
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+ [full changelog](http://github.com/sue445/plant_erd/compare/v0.1.0...main)
5
+
6
+ ## 0.1.0
7
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Faraday Mashify
2
+
3
+ [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/sue445/faraday-mashify/ci)](https://github.com/sue445/faraday-mashify/actions?query=branch%3Amain)
4
+ [![Gem](https://img.shields.io/gem/v/faraday-mashify.svg?style=flat-square)](https://rubygems.org/gems/faraday-mashify)
5
+ [![License](https://img.shields.io/github/license/sue445/faraday-mashify.svg?style=flat-square)](LICENSE.md)
6
+
7
+ Faraday middleware for wrapping responses into [`Hashie::Mash`](https://github.com/hashie/hashie#mash).
8
+
9
+ This very specific middleware has been extracted from the [`faraday_middleware`](https://github.com/lostisland/faraday_middleware) project.
10
+
11
+ This is fully compatible with [`FaradayMiddleware::Mashify`](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/response/mashify.rb)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'faraday-mashify'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```shell
24
+ bundle install
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```shell
30
+ gem install faraday-mashify
31
+ ```
32
+
33
+ ## Usage
34
+ ```bash
35
+ curl http://www.example.com/api/me
36
+ {"name":"sue445"}
37
+ ```
38
+
39
+ ```ruby
40
+ require 'faraday/mashify'
41
+
42
+ connection =
43
+ Faraday.new(url: 'http://www.example.com') do |conn|
44
+ conn.response :mashify
45
+ conn.response :json
46
+ end
47
+
48
+ response = connection.get('/api/me').body
49
+
50
+ response[:name]
51
+ #=> "sue445"
52
+
53
+ response['name']
54
+ #=> "sue445"
55
+
56
+ response.name
57
+ #=> "sue445"
58
+ ```
59
+
60
+ ### Customize response class
61
+ If you want to customize the response class, pass `mash_class` to `conn.response :mashify`. (default is `Hashie::Mash`)
62
+
63
+ e.g.
64
+
65
+ ```ruby
66
+ class MyHash < Hashie::Mash
67
+ end
68
+
69
+ connection =
70
+ Faraday.new(url: 'http://www.example.com') do |conn|
71
+ conn.response :mashify, mash_class: MyHash
72
+ conn.response :json
73
+ end
74
+
75
+ response = connection.get('/api/me').body
76
+
77
+ response.class
78
+ #=> MyHash
79
+ ```
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies.
84
+
85
+ Then, run `bin/test` to run the tests.
86
+
87
+ To install this gem onto your local machine, run `rake build`.
88
+
89
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
90
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/sue445/faraday-mashify).
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Mashify
5
+ # Public: Converts parsed response bodies to a Hashie::Mash if they were of Hash or Array type.
6
+ class Middleware < Faraday::Middleware
7
+ # @!attribute [rw] mash_class
8
+ # @return [Class]
9
+ attr_accessor :mash_class
10
+
11
+ class << self
12
+ # @!attribute [rw] mash_class
13
+ # @return [Class]
14
+ attr_accessor :mash_class
15
+ end
16
+
17
+ # @param app [Proc]
18
+ # @param options [Hash]
19
+ # @option options [Class] :mash_class Responses are wrapped in this class (default is `::Hashie::Mash`)
20
+ def initialize(app = nil, options = {})
21
+ super(app, options)
22
+ self.mash_class = options[:mash_class] || self.class.mash_class || ::Hashie::Mash
23
+ end
24
+
25
+ # This method will be called when the response is being processed.
26
+ # You can alter it as you like, accessing things like response_body, response_headers, and more.
27
+ # Refer to Faraday::Env for a list of accessible fields:
28
+ # https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
29
+ #
30
+ # @param env [Faraday::Env] the environment of the response being processed.
31
+ def on_complete(env)
32
+ env[:body] = parse(env[:body])
33
+ end
34
+
35
+ private
36
+
37
+ def parse(body)
38
+ case body
39
+ when Hash
40
+ mash_class.new(body)
41
+ when Array
42
+ body.map { |item| parse(item) }
43
+ else
44
+ body
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Mashify
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mashify/middleware'
4
+ require_relative 'mashify/version'
5
+ require 'faraday'
6
+ require 'hashie/mash'
7
+
8
+ module Faraday
9
+ # This will be your middleware main module, though the actual middleware implementation will go
10
+ # into Faraday::Mashify::Middleware for the correct namespacing.
11
+ module Mashify
12
+ # Faraday allows you to register your middleware for easier configuration.
13
+ # This step is totally optional, but it basically allows users to use a
14
+ # custom symbol (in this case, `:mashify`), to use your middleware in their connections.
15
+ # After calling this line, the following are both valid ways to set the middleware in a connection:
16
+ # * conn.use Faraday::Mashify::Middleware
17
+ # * conn.use :mashify
18
+ # Without this line, only the former method is valid.
19
+ # Faraday::Middleware.register_middleware(mashify: Faraday::Mashify::Middleware)
20
+
21
+ # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
22
+ # This will allow to load your middleware using the `request` or `response` methods respectively.
23
+ #
24
+ # Load middleware with conn.request :mashify
25
+ # Faraday::Request.register_middleware(mashify: Faraday::Mashify::Middleware)
26
+ #
27
+ # Load middleware with conn.response :mashify
28
+ Faraday::Response.register_middleware(mashify: Faraday::Mashify::Middleware)
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-mashify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '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: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.21.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.21.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.24.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.24.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-packaging
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.5.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.5.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-performance
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.0'
181
+ description: 'Faraday middleware for wrapping responses into Hashie::Mash.
182
+
183
+ '
184
+ email:
185
+ - sue445@sue445.net
186
+ executables: []
187
+ extensions: []
188
+ extra_rdoc_files: []
189
+ files:
190
+ - CHANGELOG.md
191
+ - LICENSE.md
192
+ - README.md
193
+ - lib/faraday/mashify.rb
194
+ - lib/faraday/mashify/middleware.rb
195
+ - lib/faraday/mashify/version.rb
196
+ homepage: https://github.com/sue445/faraday-mashify
197
+ licenses:
198
+ - MIT
199
+ metadata:
200
+ bug_tracker_uri: https://github.com/sue445/faraday-mashify/issues
201
+ changelog_uri: https://github.com/sue445/faraday-mashify/blob/v0.1.0/CHANGELOG.md
202
+ documentation_uri: http://www.rubydoc.info/gems/faraday-mashify/0.1.0
203
+ homepage_uri: https://github.com/sue445/faraday-mashify
204
+ source_code_uri: https://github.com/sue445/faraday-mashify
205
+ wiki_uri: https://github.com/sue445/faraday-mashify/wiki
206
+ rubygems_mfa_required: 'true'
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '2.6'
216
+ - - "<"
217
+ - !ruby/object:Gem::Version
218
+ version: '4'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubygems_version: 3.3.3
226
+ signing_key:
227
+ specification_version: 4
228
+ summary: Faraday middleware for wrapping responses into Hashie::Mash
229
+ test_files: []