response_mate 0.3.3 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93c14f8ebe00b8759584452bf612e52f105375e2
4
- data.tar.gz: 090bffd16367fe10de84dbcdeefe298bdf9b4a9f
3
+ metadata.gz: 886ee91f9cc8611ed603ada2aba4256a34626d5e
4
+ data.tar.gz: a593e47b886bc4160c43453f03bf2fa8ff26da44
5
5
  SHA512:
6
- metadata.gz: 05c4ddfbba025b2733c026e01e74ac173e7a7d5592c253dd1e925329929cc9942a513e76dfb403b1fc9eb77f777b8294fc5b01b7a739baebee3c84372ddfc1f3
7
- data.tar.gz: bcb334033c8a5f880ae51aa1dbfb1ca1647ac91601b73ff1362241c2fba443339d3910c8a381d9f653740b5d6f2012c020eabb77e736d8b22a33ca5bd5f5c912
6
+ metadata.gz: c6d9ba046034288193fc61e786d27f7c16ef663b15bb62f5791a32a3b22bb10aa0aadbe387401c87382099d86b56cf7a71f1218d4c7b061c589fefd9d4a4bb15
7
+ data.tar.gz: 34339559073b743d0cd29e8cdf51521ce1548bd3fb386aacac329c8ab8616defc90668be9f8b91f00dda077b5ea7f75ae5ab8b541007e750e490ffa454270341
data/.rubocop.yml CHANGED
@@ -1,3 +1,8 @@
1
+ AllCops:
2
+ Exclude:
3
+ - Guardfile
4
+ - response_mate.gemspec
5
+
1
6
  Style/LineLength:
2
7
  Max: 120
3
8
 
@@ -29,3 +34,6 @@ Style/SpaceInsideBlockBraces:
29
34
  Style/Blocks:
30
35
  Exclude:
31
36
  - spec/**/*.rb
37
+
38
+ Style/EachWithObject:
39
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## Unreleased
6
+
7
+ ## [0.4.0] - 2015-08-19
8
+
9
+ ## Added
10
+
11
+ * `record`, `inspect`, `list` commands accept `-e` option to specify the
12
+ environment file
13
+ * Warning when a manifest contains no requests
14
+ * ResponseMate::Environment#exists? to check if an environment file
15
+ exists
16
+ * List command now accepts `-o` option to specify the output directory
17
+ of recordings
18
+
19
+ ## Changed
20
+
21
+ * The verb key in the recorded response is now lower cased Symbol (was
22
+ upper case String)
23
+ * Manifests are preprocessed as Mustache templates only if they are
24
+ identified as Mustache
25
+ * ResponseMate::Manifest#requests_for_keys returns empty array for any
26
+ kind of blank input
27
+ * ResponseMate::Manifest#parse becomes private
28
+ * ResponseMate::Environment#parse does not exit when the file is missing
29
+ * The default output directory for the recordings is the current working
30
+ directory (used to be `./output/responses/`)
31
+
32
+ ## Fixed
33
+
34
+ * Exception handling for ManifestMissing, OutputDirError, KeysNotFound
35
+ in bin/response_mate
36
+
37
+ ## [0.3.3] - 2015-03-02
38
+
39
+ ### Changed
40
+
41
+ * Force internal and external encoding to UTF-8
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,42 @@
1
+ # Contributing
2
+
3
+ If you discover issues, have ideas for improvements or new features,
4
+ please report them to the [issue tracker][1] of the repository or
5
+ submit a pull request. Please, try to follow these guidelines when you
6
+ do so.
7
+
8
+ ## Issue reporting
9
+
10
+ * Check that the issue has not already been reported.
11
+ * Check that the issue has not already been fixed in the latest code
12
+ (a.k.a. `master`).
13
+ * Be clear, concise and precise in your description of the problem.
14
+ * Open an issue with a descriptive title and a summary in grammatically correct,
15
+ complete sentences.
16
+ * Mention the version of the gem you are using.
17
+ * Include any relevant code to the issue summary.
18
+
19
+ ## Pull requests
20
+
21
+ * Read [how to properly contribute to open source projects on Github][2].
22
+ * Fork the project.
23
+ * Use a topic/feature branch to easily amend a pull request later, if necessary.
24
+ * Comply with our [git style guide][3].
25
+ * Use the same coding conventions as the rest of the project.
26
+ * Commit and push until you are happy with your contribution.
27
+ * Make sure to add tests for it. This is important so I don't break it
28
+ in a future version unintentionally.
29
+ * Add an entry to the [Changelog](CHANGELOG.md) accordingly.
30
+ * Make sure the test suite is passing and the code you wrote doesn't produce
31
+ RuboCop offenses.
32
+ * [Squash related commits together][5].
33
+ * Open a [pull request][4] that relates to *only* one subject with a clear title
34
+ and description in grammatically correct, complete sentences.
35
+
36
+ This text is adapted from [rubocop - contributing](https://github.com/bbatsov/rubocop/blob/master/CONTRIBUTING.md)
37
+
38
+ [1]: https://github.com/Zorbash/response_mate/issues
39
+ [2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request
40
+ [3]: https://github.com/agis-/git-style-guide
41
+ [4]: https://help.github.com/articles/using-pull-requests
42
+ [5]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
data/Gemfile CHANGED
@@ -7,12 +7,11 @@ gem 'coveralls', require: false
7
7
  group :development, :test do
8
8
  gem 'pry-debugger', platforms: :mri_19
9
9
  gem 'pry-byebug', platforms: :mri_21
10
- gem 'guard-rspec', require: false
11
10
  gem 'guard-rubocop', require: false
12
11
  end
13
12
 
14
13
  group :test do
15
- gem 'rspec', '~> 2.14.0'
14
+ gem 'guard-rspec', require: false
16
15
  gem 'simplecov', '~> 0.9'
17
16
  gem 'fakeweb', '~> 1.2.8'
18
17
  end
data/Guardfile CHANGED
@@ -10,7 +10,7 @@ guard 'rspec', rspec_options do
10
10
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
11
  end
12
12
 
13
- #guard :rubocop, all_on_start: false do
14
- #watch(%r{.+\.rb$})
15
- #watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
16
- #end
13
+ guard :rubocop, all_on_start: false, cli: ['-D'] do
14
+ watch(%r{.+\.rb$})
15
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
16
+ end
data/README.md CHANGED
@@ -6,27 +6,36 @@
6
6
  [![Coverage Status](https://coveralls.io/repos/Zorbash/response_mate/badge.png?branch=master)](https://coveralls.io/r/Zorbash/response_mate?branch=master)
7
7
  [![Build Status](https://travis-ci.org/Zorbash/response_mate.svg)](https://travis-ci.org/Zorbash/response_mate)
8
8
 
9
- ResponseMate is a command line tool that aims to make inspecting and
10
- recording HTTP requests/responses. It is designed with APIs in mind.
9
+ ResponseMate is a command line tool that helps inspecting and
10
+ recording HTTP requests/responses from a terminal.
11
11
 
12
- It is a cli supplement/replacement of [postman](https://github.com/a85/POSTMan-Chrome-Extension)
12
+ It is designed with APIs in mind.
13
13
 
14
14
  #### Install
15
15
  `gem install response_mate`
16
16
 
17
+ ## Commands
18
+
19
+ * [record](#record)
20
+ * [list](#list)
21
+ * [inspect](#inspect)
22
+ * [export](#export)
23
+ * [version](#version)
24
+
17
25
  ## Usage
18
26
 
19
- For a list of available commands run `response_mate help`
27
+ For a list of available commands run `response_mate help`
20
28
  For help on a command run `response_mate help some_command`
21
29
 
22
- ## Setup
23
- A specific directory structure must be present to store the recordings.
24
- To scaffold it do:
25
- `response_mate setup`
30
+ ## Requests Manifest
31
+
32
+ Most ResponseMate's tasks depend on a manifest file where you declare
33
+ the requests to be made.
34
+ The default filename of this manifest is `requests.yml`.
35
+ You may specify another file using the `-r` option.
36
+ This file has to be in [YAML](http://yaml.org/) format (but keep in mind
37
+ that JSON is a valid compatible subset of YAML).
26
38
 
27
- ResponseMate's tasks heavily depend on a manifest file where you declare
28
- the requests to be made. The default expected filename of this manifest
29
- is `requests.yml`.
30
39
 
31
40
  Example:
32
41
 
@@ -44,30 +53,98 @@ requests:
44
53
  url: 'http://someapi.com/users/42/friends'
45
54
  params:
46
55
  since: 'childhood'
47
- honest: '{{are_my_friends_host}}'
56
+ honest: '{{are_my_friends_honest}}'
57
+ ```
58
+
59
+ Expressions inside `{{}}` will be evaluated as
60
+ [Mustache templates](http://mustache.github.io/mustache.5.html) using values from a file
61
+ named `environment.yml`.
62
+
63
+ You may specify a different location for the environment file using the
64
+ `-e` option.
65
+
66
+ Example:
67
+
68
+ ```shell
69
+ response_mate inspect issues_show -e ./response_mate/production_environment.yml
70
+ ```
71
+
72
+ If your requests manifest does not contain
73
+ [Mustache](http://mustache.github.io/mustache.5.html) tags you don't
74
+ need an environment file.
75
+
76
+
77
+ ## Environment File
78
+
79
+ In this file (default location: `./environment.yml`) you may place
80
+ variables to be used in the [requests manifest](#requests-manifest).
81
+ Where applicable you may configure the location of the environment file
82
+ using the `-e` option.
83
+
84
+ Example
85
+
86
+ ```yaml
87
+ response_mate record -e ./github/production_environment.yml
88
+ ```
89
+
90
+ This file has to be in [YAML](http://yaml.org/) format (but keep in mind
91
+ that JSON is a valid compatible subset of YAML).
92
+
93
+
94
+ ```yaml
95
+ # environment.yml
96
+ base_url: http://api.github.com
97
+ repo: rails/rails
98
+ ```
99
+
100
+ Then in the [requests manifest](#requests-manifest) any values of keys
101
+ declared in the environment file can be used as follows.
102
+
103
+ ```yaml
104
+ # requests.yml
105
+ requests:
106
+ -
107
+ key: repos_show
108
+ url: {{base_url}}/repos/{{repo}}
48
109
  ```
49
- Expressions inside `{{}}` will be evaluated as Mustache templates using
50
- values from a file `environment.yml` that may be present.
51
110
 
52
111
  ## Record
53
- ### Default
54
- Record all the keys of the requests manifest file being `requests.yml`
55
112
 
56
- `response_mate record`
113
+ Records the responses of HTTP requests declared in a [requests
114
+ manifest](#requests-manifest) file.
115
+
116
+ ```shell
117
+ response_mate record
118
+ ```
57
119
 
58
- ### Specific key(s)
120
+ > By default responses are stored in the current working directory, but the
121
+ output directory is configurable using the `-o` option.
59
122
 
60
- `response_mate record -k key1 key2`
123
+ ### Default Behavior
61
124
 
62
- ### Specify a different request manifest
125
+ Without any arguments / options it records all the keys of the [requests manifest](#requests-manifest).
63
126
 
64
- `response_mate record -r foo_api.yml`
127
+ ### Recording Specific Key(s)
65
128
 
66
- ## Clear
129
+ If you wish to record the responses of a subset of the declared requests
130
+ in the [requests manifest](#requests-manifest), you may use the `-k`
131
+ option. You have to provide a space separated list of keys to be recorded.
132
+
133
+ ```shell
134
+ response_mate record -k key1 key2
135
+ ```
67
136
 
68
- Remove any existing recordings
137
+ ### Custom Manifest Location
69
138
 
70
- `response_mate clear`
139
+ The requests are expected to be declared in a file named `requests.yml`
140
+ in the current working directory.
141
+
142
+ You may have many request files to use for various purposes.
143
+ To specify the one to be used you may supply the `-r` option.
144
+
145
+ ```shell
146
+ response_mate record -r github_api.yml
147
+ ```
71
148
 
72
149
  ## Inspect
73
150
 
@@ -77,37 +154,49 @@ Performs the request and displays the output without recording
77
154
 
78
155
  ## List
79
156
 
80
- Lists existing recordings
157
+ Lists recording keys, prompting either to record or to inspect
81
158
 
82
159
  `response_mate list`
83
160
 
161
+ Same as in the [record](#record) command you may specify the output
162
+ directory using the `-o` option.
163
+
84
164
  ## Export
85
165
 
86
- Exports a requests manifest file to a different format
87
- (currently only postman is supported)
166
+ Exports either the [requests manifest](#requests-manifest) or the environment file
167
+ to a different format (currently only [postman](http://getpostman.com) is supported)
88
168
 
89
- `response_mate export`
169
+ ```
170
+ response_mate export
171
+ ```
90
172
 
91
173
  ### Export in pretty json
92
174
 
93
- `response_mate export -f postman -p`
175
+ ```shell
176
+ response_mate export -f postman -p
177
+ ```
94
178
 
95
- ### Specify a different request manifest
179
+ ### Custom Manifest Location
96
180
 
97
- `response_mate export -f postman -r foo_api.yml`
181
+ ```shell
182
+ response_mate export -f postman -r github_requests.yml
183
+ ```
98
184
 
99
- ### Export the environment.yml
185
+ ### Export the Environment File
100
186
 
101
- `response_mate export --resource=environment`
187
+ ```shell
188
+ response_mate export --resource=environment
189
+ ```
102
190
 
103
191
  ### Upload the exported and get a link
104
192
 
105
- `response_mate export --resource=environment --upload`
193
+ ```shell
194
+ response_mate export --resource=environment --upload
195
+ ```
106
196
 
107
- # List of contributors
197
+ ## Version
108
198
 
109
- - [zorbash](https://github.com/zorbash)
110
- - [jimmikarily](https://github.com/jimmykarily)
199
+ Displays the version
111
200
 
112
201
  # Licence
113
202
  Released under the MIT License. See the
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rspec/core/rake_task'
6
6
  desc 'Run RSpec'
7
7
  RSpec::Core::RakeTask.new(:test) do |spec|
8
8
  spec.pattern = 'spec/**/*_spec.rb'
9
- spec.rspec_opts = ['--color', '--format nested']
9
+ spec.rspec_opts = ['--color', '--format documentation']
10
10
  end
11
11
 
12
12
  task default: :test
data/bin/response_mate CHANGED
@@ -5,4 +5,21 @@ require 'response_mate'
5
5
  Encoding.default_internal = Encoding::UTF_8
6
6
  Encoding.default_external = Encoding::UTF_8
7
7
 
8
- ResponseMate::CLI.start(ARGV)
8
+ # Exit codes try to follow sysexits(3)
9
+ begin
10
+ ResponseMate::CLI.start(ARGV)
11
+ rescue ResponseMate::ManifestMissing => e
12
+ puts ['The specified requests manifest '.red, e.message.underline, ' does not exist'.red].
13
+ join, 'You may specify a different requests manifest file using the "-r" option'
14
+
15
+ exit 66 # EX_NOINPUT
16
+ rescue ResponseMate::OutputDirError => e
17
+ puts ['The specified output directory '.red, e.message.underline, ' does not exist'.red].
18
+ join, 'You may specify a different output directory using the "-o" option'
19
+
20
+ exit 66 # EX_NOINPUT
21
+ rescue ResponseMate::KeysNotFound => e
22
+ puts "The following keys were not found: #{e.message.underline}".red
23
+
24
+ exit 65 # EX_DATAERR
25
+ end
data/lib/response_mate.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'thor'
2
- require 'colored'
2
+ require 'colorize'
3
3
  require 'awesome_print'
4
4
  require 'active_support/all'
5
5
  require 'faraday'
@@ -6,19 +6,21 @@ module ResponseMate
6
6
  desc 'record', 'Perform requests and record their output'
7
7
  method_option :requests_manifest, aliases: '-r', banner:
8
8
  'requests.yml'
9
+ method_option :environment, aliases: '-e', banner:
10
+ 'environment.yml'
9
11
  method_option :output_dir, aliases: '-o', type: :string, banner:
10
12
  './a_dir_to_place_the_recordings'
11
13
  method_option :keys, aliases: '-k', type: :array, default: [], banner:
12
14
  'key_to_record1 key_to_record2'
13
15
  def record
14
16
  ResponseMate::Commands::Record.new(args, options).run
15
- rescue ResponseMate::KeysNotFound => e
16
- puts "The requested keys: #{e.message} could not be found"
17
17
  end
18
18
 
19
19
  desc 'inspect [key1,key2]', 'Perform requests and print their output'
20
20
  method_option :requests_manifest, aliases: '-r', banner:
21
21
  'requests.yml'
22
+ method_option :environment, aliases: '-e', banner:
23
+ 'environment.yml'
22
24
  def inspect(*keys) # rubocop:disable Lint/UnusedMethodArgument
23
25
  ResponseMate::Commands::Inspect.new(args, options).run
24
26
  end
@@ -26,6 +28,10 @@ module ResponseMate
26
28
  desc 'list', 'List available keys to record or inspect'
27
29
  method_option :requests_manifest, aliases: '-r', banner:
28
30
  'requests.yml'
31
+ method_option :environment, aliases: '-e', banner:
32
+ 'environment.yml'
33
+ method_option :output_dir, aliases: '-o', type: :string, banner:
34
+ './a_dir_to_place_the_recordings'
29
35
  def list # rubocop:disable Lint/UnusedMethodArgument
30
36
  ResponseMate::Commands::List.new(args, options).run
31
37
  end
@@ -36,8 +42,6 @@ module ResponseMate
36
42
  end
37
43
  map ['--version'] => :version
38
44
 
39
- default_task :version
40
-
41
45
  desc 'export', 'Export manifest or environment to one of the available formats'
42
46
  method_option :requests_manifest, aliases: '-r', banner:
43
47
  'requests.yml'