recurl 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8848c42ca60b085111810bf3c54c5d2a1106d00f1b09e4b78ec470a04ddd3911
4
+ data.tar.gz: 30a110782d26cec341ade8b8c3fd37d5e19852be64ba41de75b06d34a2333bd0
5
+ SHA512:
6
+ metadata.gz: 102cf5cc38680209c0051462a8f32c48ad6fe6acb5e51f9e949010edab5aac61e0f724acc6a44c04a41212010f13ad434c59633036adcfe13396df59be042d53
7
+ data.tar.gz: ef92f072148bf7e3d8b9e7401858cf5d480c8cea67bcfca675f54e6c7f44a58c1bc2261b3148ea045ea4c221783497880c1bc91a24c75c6f45af790abba99a79
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'recurl.gemspec'
4
+ - 'demo/**/*'
5
+ Style/HashEachMethods:
6
+ Enabled: true
7
+ Style/HashTransformKeys:
8
+ Enabled: true
9
+ Style/HashTransformValues:
10
+ Enabled: true
@@ -0,0 +1,14 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=508a3ddc73903dd71d407f0656d547c8a01e757a0ab558192c75d4c9db80d844
4
+ language: ruby
5
+ rvm:
6
+ - 2.6
7
+ - 2.7
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
12
+ script: "bundle exec rspec"
13
+ after_script:
14
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in recurl.gemspec
6
+ gemspec
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ recurl (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ jaro_winkler (1.5.4)
14
+ json (2.3.0)
15
+ method_source (0.9.2)
16
+ parallel (1.19.1)
17
+ parser (2.7.0.4)
18
+ ast (~> 2.4.0)
19
+ pry (0.12.2)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.9.0)
22
+ rack (2.2.2)
23
+ rack-test (1.1.0)
24
+ rack (>= 1.0, < 3)
25
+ rainbow (3.0.0)
26
+ rake (13.0.1)
27
+ rexml (3.2.4)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.1)
33
+ rspec-support (~> 3.9.1)
34
+ rspec-expectations (3.9.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.2)
41
+ rubocop (0.80.1)
42
+ jaro_winkler (~> 1.5.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.7.0.1)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ rexml
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 1.4.0, < 1.7)
49
+ ruby-progressbar (1.10.1)
50
+ simplecov (0.17.1)
51
+ docile (~> 1.1)
52
+ json (>= 1.8, < 3)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-html (0.10.2)
55
+ unicode-display_width (1.6.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 2.0)
62
+ pry (~> 0.12.2)
63
+ rack-test (~> 1.1)
64
+ rake (~> 13.0)
65
+ recurl!
66
+ rspec (~> 3.9)
67
+ rubocop (~> 0.80.1)
68
+ simplecov (~> 0.17.1)
69
+
70
+ BUNDLED WITH
71
+ 2.0.2
@@ -0,0 +1,62 @@
1
+ # Recurl
2
+
3
+ [![Code Climate](https://codeclimate.com/github/zaru/recurl/badges/gpa.svg)](https://codeclimate.com/github/zaru/recurl)
4
+ [![Test Coverage](https://codeclimate.com/github/zaru/recurl/badges/coverage.svg)](https://codeclimate.com/github/zaru/recurl/coverage)
5
+ [![Build Status](https://travis-ci.org/zaru/recurl.svg?branch=master)](https://travis-ci.org/zaru/recurl)
6
+ [![Gem Version](https://badge.fury.io/rb/recurl.svg)](https://badge.fury.io/rb/recurl)
7
+
8
+ Logger that reproduces access log with `curl` command.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'recurl'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install recurl
25
+
26
+ ## Configuration
27
+
28
+ ### Sinatra
29
+
30
+ ```
31
+ require 'rack'
32
+ require 'recurl'
33
+ require 'logger'
34
+
35
+ Recurl.configure do |config|
36
+ config.logger = Logger.new(STDOUT)
37
+ end
38
+ use Recurl::Rack::Middleware
39
+
40
+ require File.expand_path 'app', File.dirname(__FILE__)
41
+ run MyApp
42
+ ```
43
+
44
+ ### Ruby on Rails
45
+
46
+ This is an example that you might put into a Rails initializer at `config/initializers/recurl.rb`:
47
+
48
+ ```
49
+ Recurl.configure do |config|
50
+ config.logger = Logger.new(STDOUT)
51
+ end
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zaru/recurl.
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'recurl'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'recurl/version'
4
+ require 'recurl/configuration'
5
+ require 'recurl/rack'
6
+
7
+ require 'recurl/railtie' if defined?(::Rails)
8
+
9
+ # bootstrap Recurl module
10
+ module Recurl
11
+ extend Configuration
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Recurl
4
+ # Configure Recurl
5
+ #
6
+ # Usage:
7
+ # Recurl.configure do |config|
8
+ # config.logger = Logger.new(STDOUT)
9
+ # end
10
+ module Configuration
11
+ attr_accessor :logger
12
+
13
+ def configure
14
+ yield self
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Recurl
4
+ module Rack
5
+ # Rack middleware
6
+ class Middleware
7
+ attr_reader :env
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ @env = env
15
+ log
16
+ @app.call env
17
+ end
18
+
19
+ private
20
+
21
+ def log
22
+ logger.info "curl #{http_method} #{headers} #{params} #{url}"
23
+ end
24
+
25
+ def headers
26
+ {
27
+ 'User-Agent' => env['HTTP_USER_AGENT'],
28
+ 'Accept' => env['HTTP_ACCEPT'],
29
+ 'Cookie' => env['HTTP_COOKIE'],
30
+ 'Content-Type' => env['CONTENT_TYPE']
31
+ }.map { |k, v| " -H '#{k}: #{v}'" }.join(' ')
32
+ end
33
+
34
+ def params
35
+ body = ::Rack::Request.new(env).body.read
36
+ body.empty? ? '' : "-d '#{body}'"
37
+ end
38
+
39
+ def url
40
+ "'#{env['REQUEST_URI']}'"
41
+ end
42
+
43
+ def http_method
44
+ "-X #{env['REQUEST_METHOD']}"
45
+ end
46
+
47
+ def logger
48
+ ::Recurl.logger
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Recurl
4
+ # Load middleware when use Rails
5
+ class Railtie < ::Rails::Railtie
6
+ initializer 'recurl.middleware' do |app|
7
+ app.middleware.use(Recurl::Rack::Middleware)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Recurl
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'recurl/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'recurl'
9
+ spec.version = Recurl::VERSION
10
+ spec.authors = ['zaru']
11
+ spec.email = ['zarutofu@gmail.com']
12
+
13
+ spec.summary = 'save the request with curl command'
14
+ spec.description = 'save the request with curl command ( rack middleware )'
15
+ spec.homepage = 'https://github.com/zaru/recurl'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/zaru/recurl'
19
+
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ end
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', '~> 2.0'
30
+ spec.add_development_dependency 'rake', '~> 13.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.80.1'
32
+ spec.add_development_dependency 'rspec', '~> 3.9'
33
+ spec.add_development_dependency 'rack-test', '~> 1.1'
34
+ spec.add_development_dependency 'simplecov', '~> 0.17.1'
35
+ spec.add_development_dependency 'pry', '~> 0.12.2'
36
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recurl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zaru
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-12 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: '2.0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.80.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.80.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
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.17.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.17.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.12.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.2
111
+ description: save the request with curl command ( rack middleware )
112
+ email:
113
+ - zarutofu@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rubocop.yml"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/recurl.rb
128
+ - lib/recurl/configuration.rb
129
+ - lib/recurl/rack.rb
130
+ - lib/recurl/railtie.rb
131
+ - lib/recurl/version.rb
132
+ - recurl.gemspec
133
+ homepage: https://github.com/zaru/recurl
134
+ licenses: []
135
+ metadata:
136
+ homepage_uri: https://github.com/zaru/recurl
137
+ source_code_uri: https://github.com/zaru/recurl
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubygems_version: 3.0.3
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: save the request with curl command
157
+ test_files: []