faraday_specific_logging 0.1.1

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: 4c978d91b7c2ec7547fbfb5e9641e090617aa8ab
4
+ data.tar.gz: b6208a2fac150add30220d4b5f449e52195a604d
5
+ SHA512:
6
+ metadata.gz: 696f628ab4bd91b528d026d9680b349777823649492925155e114b34b57cfdbbf0dc793cc61d04d4e8a2704b10f9216468bd90f6eb26e75e69bb1cf2634c8a9e
7
+ data.tar.gz: ff3c47af1bb43ab974145df173d312bfbe2f41b01c28147267a1ceb455479bf76be74cb3fd527dfff29ed38a20e9037c9bce0a16b49e68151a06d4a11b6169a8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,116 @@
1
+ AllCops:
2
+ Exclude:
3
+ - .rbenv/**
4
+ - vendor/**
5
+ - db/**
6
+ - config/**
7
+ - tmp/**
8
+
9
+ Style/AsciiComments:
10
+ Enabled: false
11
+
12
+ Metrics/ClassLength:
13
+ Max: 250
14
+
15
+ Metrics/CyclomaticComplexity:
16
+ Max: 20
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Metrics/LineLength:
22
+ Enabled: false
23
+
24
+ Lint/UnusedBlockArgument:
25
+ Enabled: true
26
+
27
+ Lint/UnusedMethodArgument:
28
+ Enabled: true
29
+
30
+ Lint/UselessAssignment:
31
+ Enabled: true
32
+
33
+ Lint/UselessComparison:
34
+ Enabled: true
35
+
36
+ Lint/Void:
37
+ Enabled: true
38
+
39
+ Style/MultilineBlockChain:
40
+ Enabled: false
41
+
42
+ Style/SpaceInsideHashLiteralBraces:
43
+ EnforcedStyle: no_space
44
+
45
+ Style/SpaceBeforeBlockBraces:
46
+ EnforcedStyle: space
47
+
48
+ Style/SpaceInsideBlockBraces:
49
+ EnforcedStyle: space
50
+ SpaceBeforeBlockParameters: false
51
+
52
+ Style/BracesAroundHashParameters:
53
+ EnforcedStyle: no_braces
54
+
55
+ Style/CollectionMethods:
56
+ Enabled: false
57
+
58
+ Style/Documentation:
59
+ Enabled: false
60
+
61
+ Style/AlignParameters:
62
+ EnforcedStyle: with_fixed_indentation
63
+
64
+ Style/IfUnlessModifier:
65
+ MaxLineLength: 60
66
+
67
+ Style/GuardClause:
68
+ MinBodyLength: 3
69
+
70
+ RedundantSelf:
71
+ Enabled: false
72
+
73
+ Style/Lambda:
74
+ Enabled: false
75
+
76
+ Lint/EndAlignment:
77
+ Enabled: false
78
+
79
+ Style/IndentationWidth:
80
+ Enabled: false
81
+
82
+ AndOr:
83
+ Enabled: false
84
+
85
+ Style/IndentHash:
86
+ Enabled: false
87
+
88
+ Style/CaseEquality:
89
+ Enabled: false
90
+
91
+ Style/SignalException:
92
+ EnforcedStyle: only_raise
93
+
94
+ NumericLiterals:
95
+ MinDigits: 12
96
+
97
+ CommentAnnotation:
98
+ Enabled: false
99
+
100
+ Style/BlockDelimiters:
101
+ Enabled: false
102
+
103
+ Style/EmptyLiteral:
104
+ Enabled: false
105
+
106
+ Style/TrailingUnderscoreVariable:
107
+ Enabled: false
108
+
109
+ Style/Semicolon:
110
+ Enabled: false
111
+
112
+ Style/WhenThen:
113
+ Enabled: false
114
+
115
+ Style/MultilineOperationIndentation:
116
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in specific_logging.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 HaiTo
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,34 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'specific_logging'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install specific_logging
16
+
17
+ ## Usage
18
+
19
+ ```rb
20
+ @conn = Faraday.new(url: 'example.com') do |builder|
21
+ builder.specific_logging, {logger: Rails.logger, target_key: 'hoge'}
22
+ builder.request :json
23
+ builder.adapter :net_http
24
+ end
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/haito/specific_logging. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'faraday_specific_logging'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'pry'
14
+ PRY.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'faraday_specific_logging'
7
+ spec.version = '0.1.1'
8
+ spec.authors = ['HaiTo']
9
+ spec.email = ['']
10
+
11
+ spec.summary = 'request body logging middleware in faraday'
12
+ spec.description = 'summary too'
13
+ spec.homepage = 'http://github.com/haito/faraday_specific_logging'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'pry-byebug'
33
+ spec.add_runtime_dependency 'faraday'
34
+ spec.add_runtime_dependency 'faraday_middleware'
35
+ end
@@ -0,0 +1,49 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Faraday
5
+ class SpecificLogging < Faraday::Middleware
6
+ def initialize(app, options = {})
7
+ super(app)
8
+ @logger = options[:logger]
9
+ @call_logging = options[:call_logging] || 'info'
10
+ @target_key = options[:target_key]
11
+ @message = options[:message] || ''
12
+ end
13
+
14
+ def call(env)
15
+ return @app.call(env) if lost_options? || not_post_or_put?(env) || env.body.nil?
16
+
17
+ request_body = parse_body(env)
18
+
19
+ @logger.send(@call_logging, message: @message, @target_key.to_sym => request_body[@target_key.to_s])
20
+
21
+ @app.call(env)
22
+ end
23
+
24
+ private
25
+
26
+ def lost_options?
27
+ @logger.nil? || @target_key.nil?
28
+ end
29
+
30
+ def not_post_or_put?(env)
31
+ %i(post put).exclude?(env[:method])
32
+ end
33
+
34
+ def parse_body(env)
35
+ # NOTE Try parse to JSON.
36
+ JSON.load(env.body)
37
+ rescue JSON::ParserError, TypeError
38
+ url_encoded_params_to_hash(env.body)
39
+ end
40
+
41
+ def url_encoded_params_to_hash(string)
42
+ string.split('&').each_with_object({}) {|str, hs|
43
+ key, value = str.split('=')
44
+
45
+ hs[key.to_s] = value
46
+ }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ require 'faraday/specific_loging'
2
+
3
+ if Faraday.respond_to?(:register_middleware)
4
+ Faraday.register_middleware specific_loging: Faraday::SpecificLogging
5
+ elsif Faraday::Middleware.respond_to?(:register_middleware)
6
+ Faraday::Middleware.register_middleware specific_loging: Faraday::SpecificLogging
7
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday_specific_logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - HaiTo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-22 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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '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'
97
+ description: summary too
98
+ email:
99
+ - ''
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - faraday_specific_logging.gemspec
116
+ - lib/faraday/specific_loging.rb
117
+ - lib/faraday_specific_logging.rb
118
+ homepage: http://github.com/haito/faraday_specific_logging
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ allowed_push_host: https://rubygems.org
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: request body logging middleware in faraday
143
+ test_files: []