response_mate 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +107 -0
  6. data/LICENSE +20 -0
  7. data/README.md +107 -0
  8. data/Rakefile +12 -0
  9. data/bin/response_mate +5 -0
  10. data/environment.yml.sample +4 -0
  11. data/lib/response_mate.rb +43 -0
  12. data/lib/response_mate/cli.rb +58 -0
  13. data/lib/response_mate/commands.rb +1 -0
  14. data/lib/response_mate/commands/base.rb +12 -0
  15. data/lib/response_mate/commands/clear.rb +24 -0
  16. data/lib/response_mate/commands/export.rb +29 -0
  17. data/lib/response_mate/commands/inspect.rb +42 -0
  18. data/lib/response_mate/commands/list.rb +48 -0
  19. data/lib/response_mate/commands/record.rb +27 -0
  20. data/lib/response_mate/commands/setup.rb +24 -0
  21. data/lib/response_mate/connection.rb +36 -0
  22. data/lib/response_mate/core.rb +29 -0
  23. data/lib/response_mate/environment.rb +22 -0
  24. data/lib/response_mate/exporter.rb +18 -0
  25. data/lib/response_mate/exporters/postman.rb +61 -0
  26. data/lib/response_mate/helpers/application.rb +3 -0
  27. data/lib/response_mate/http.rb +41 -0
  28. data/lib/response_mate/inspector.rb +54 -0
  29. data/lib/response_mate/manifest.rb +68 -0
  30. data/lib/response_mate/manifest_parser.rb +7 -0
  31. data/lib/response_mate/oauth.rb +17 -0
  32. data/lib/response_mate/recorder.rb +39 -0
  33. data/lib/response_mate/request.rb +2 -0
  34. data/lib/response_mate/tape.rb +18 -0
  35. data/lib/response_mate/version.rb +3 -0
  36. data/oauth.yml.sample +12 -0
  37. data/requests.yml.sample +16 -0
  38. data/response_mate.gemspec +41 -0
  39. data/roadmap.md +24 -0
  40. data/spec/fixtures/two_keys.yml.erb +8 -0
  41. data/spec/lib/response_mate/cli_spec.rb +108 -0
  42. data/spec/lib/response_mate/core_spec.rb +65 -0
  43. data/spec/lib/response_mate/recorder_spec.rb +103 -0
  44. data/spec/lib/response_mate_spec.rb +7 -0
  45. data/spec/spec_helper.rb +32 -0
  46. metadata +336 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzUyYjQzZWRjMjViY2FkOWNiNWNiZTBkZmNjYzVjOTEwYTQ5ODAyMA==
5
+ data.tar.gz: !binary |-
6
+ NDU1NjQxZTE1YjMzYzdiM2E5ZDZjOGUwOTVjMDNlZjFmZmY4M2IwZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGY2ZmUyY2Q5YmZmMzI5YWEwYWFhMGJmYmQ3OGM0ZmI4OTVkYTBjNDM1MGI5
10
+ NDY3NDdiYTIzYjdjZTVmZjBhNGU0NTU0NzQyYTFhYTlkZDk4YTQ0MGEyNTlm
11
+ OWJmZGY3MTc3MzQ4OWFlZTZkMmNmMmMxNGYzNTI1OGEzOGVhMTg=
12
+ data.tar.gz: !binary |-
13
+ YmFiZjUxNjZkYTExODQ3ZGQyZTNjZmNkZGNkNWJkMThhMTc3Y2NhYzU5ZTFj
14
+ ODZjYmZhNDExNGVjZmQ0OTJiYzQ2OThhMjc5MjkzZTJmMjc0MjU2MGE4OGNm
15
+ OTI5ZTFkY2JmMjZlYjM5MjRmOTQzMTZiZmMyZjdhYzNlODk4NGM=
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ coverage
2
+ rdoc
3
+ doc
4
+ log
5
+ pkg/*
6
+ tmp
7
+ .rvmrc
8
+ .rbenv*
9
+
10
+ output
11
+ oauth.yml
12
+
13
+ *.gem
14
+ .bundle
15
+
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: ruby-head
9
+ fast_finish: true
10
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ response_mate (0.1.0)
5
+ activesupport
6
+ addressable
7
+ awesome_print
8
+ colored
9
+ faraday
10
+ faraday_middleware
11
+ highline
12
+ mustache
13
+ thor (~> 0.18.1)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activesupport (4.0.2)
19
+ i18n (~> 0.6, >= 0.6.4)
20
+ minitest (~> 4.2)
21
+ multi_json (~> 1.3)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 0.3.37)
24
+ addressable (2.3.5)
25
+ ast (1.1.0)
26
+ atomic (1.1.14)
27
+ awesome_print (1.2.0)
28
+ coderay (1.0.9)
29
+ colored (1.2)
30
+ coveralls (0.7.0)
31
+ multi_json (~> 1.3)
32
+ rest-client
33
+ simplecov (>= 0.7)
34
+ term-ansicolor
35
+ thor
36
+ diff-lcs (1.2.5)
37
+ docile (1.1.1)
38
+ fakefs (0.4.3)
39
+ faraday (0.8.8)
40
+ multipart-post (~> 1.2.0)
41
+ faraday_middleware (0.9.0)
42
+ faraday (>= 0.7.4, < 0.9)
43
+ highline (1.6.20)
44
+ i18n (0.6.9)
45
+ method_source (0.8.2)
46
+ mime-types (2.0)
47
+ minitest (4.7.5)
48
+ multi_json (1.8.2)
49
+ multipart-post (1.2.0)
50
+ mustache (0.99.5)
51
+ parser (2.1.1)
52
+ ast (~> 1.1)
53
+ slop (~> 3.4, >= 3.4.5)
54
+ powerpack (0.0.9)
55
+ pry (0.9.12.2)
56
+ coderay (~> 1.0.5)
57
+ method_source (~> 0.8)
58
+ slop (~> 3.4)
59
+ pry-nav (0.2.3)
60
+ pry (~> 0.9.10)
61
+ pry-remote (0.1.7)
62
+ pry (~> 0.9)
63
+ slop (~> 3.0)
64
+ rainbow (1.99.0)
65
+ rake (10.1.0)
66
+ rest-client (1.6.7)
67
+ mime-types (>= 1.16)
68
+ rspec (2.14.1)
69
+ rspec-core (~> 2.14.0)
70
+ rspec-expectations (~> 2.14.0)
71
+ rspec-mocks (~> 2.14.0)
72
+ rspec-core (2.14.7)
73
+ rspec-expectations (2.14.4)
74
+ diff-lcs (>= 1.1.3, < 2.0)
75
+ rspec-mocks (2.14.4)
76
+ rubocop (0.16.0)
77
+ parser (~> 2.1)
78
+ powerpack (~> 0.0.6)
79
+ rainbow (>= 1.1.4)
80
+ simplecov (0.8.2)
81
+ docile (~> 1.1.0)
82
+ multi_json
83
+ simplecov-html (~> 0.8.0)
84
+ simplecov-html (0.8.0)
85
+ slop (3.4.6)
86
+ term-ansicolor (1.2.2)
87
+ tins (~> 0.8)
88
+ thor (0.18.1)
89
+ thread_safe (0.1.3)
90
+ atomic
91
+ tins (0.13.1)
92
+ tzinfo (0.3.38)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ bundler (~> 1.3)
99
+ coveralls
100
+ fakefs
101
+ pry
102
+ pry-nav
103
+ pry-remote
104
+ rake
105
+ response_mate!
106
+ rspec (~> 2.14)
107
+ rubocop
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Dimitris Zorbas / zorbash
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,107 @@
1
+ ## ResponseMate
2
+ [![Build Status](https://travis-ci.org/Zorbash/response_mate.png?branch=master)](https://travis-ci.org/Zorbash/response_mate)
3
+ [![Code Climate](https://codeclimate.com/github/Zorbash/response_mate.png)](https://codeclimate.com/github/Zorbash/response_mate)
4
+ [![Dependencies tatus](https://gemnasium.com/Zorbash/response_mate.png)](https://gemnasium.com/Zorbash/response_mate)
5
+ [[Coverage Status](https://coveralls.io/repos/Zorbash/response_mate/badge.png?branch=master)](https://coveralls.io/r/Zorbash/response_mate?branch=master)
6
+
7
+ ResponseMate is a command line tool that aims to make inspecting and
8
+ recording HTTP requests/responses. It is designed with APIs in mind.
9
+
10
+ It is a cli supplement/replacement of [postman](https://github.com/a85/POSTMan-Chrome-Extension)
11
+
12
+ #### Install
13
+ `gem install response_mate`
14
+
15
+ ## Usage
16
+
17
+ ## Setup
18
+ A specific directory structure must be present to store the recordings.
19
+ To scaffold it do:
20
+ `response_mate setup`
21
+
22
+ ResponseMate's tasks heavily depend on a manifest file where you declare
23
+ the requests to be made. The default expected filename of this manifest
24
+ is `requests.yml`.
25
+ The expected format of this file is like [this](https://gist.github.com/anonymous/8055040)
26
+
27
+ Example:
28
+
29
+ ```yaml
30
+ base_url: http://localhost:3000/api
31
+ default_headers:
32
+ accept: 'application/vnd.github.beta+json'
33
+ requests:
34
+ -
35
+ key: user_repos
36
+ request: 'GET /user/repos'
37
+ -
38
+ key: user_issues
39
+ request:
40
+ path: '/user/issues'
41
+ params:
42
+ sort: 'updated'
43
+ -
44
+ key: users_repos
45
+ request: 'GET /users/{{some_user_id}}/repos'
46
+
47
+ ```
48
+
49
+ ## Record
50
+ ### Default
51
+ Record all the keys of the requests manifest file being `requests.yml`
52
+
53
+ `response_mate record`
54
+
55
+ ### Specific key(s)
56
+
57
+ `response_mate -k key1 key2`
58
+
59
+ ### Specify a different request manifest
60
+
61
+ `response_mate -r foo_api.yml`
62
+
63
+ ### Specify a different base url for the requests
64
+
65
+ `response_mate -b http://api.foo.com`
66
+
67
+ ## Clear
68
+
69
+ Remove any existing recordings
70
+
71
+ `response_mate clear`
72
+
73
+ ## List
74
+
75
+ Lists existing recordings
76
+
77
+ `response_mate list`
78
+
79
+ ## Export
80
+
81
+ Exports a requests manifest file to a different format
82
+ (currently only postman is supported)
83
+
84
+ `response_mate export -f postman`
85
+
86
+ ### Export in pretty json
87
+
88
+ `response_mate export -f postman -p`
89
+
90
+ ### Specify a different request manifest
91
+
92
+ `response_mate export -f postman -r foo_api.yml`
93
+
94
+
95
+ # List of contributors
96
+
97
+ - [zorbash](https://github.com/zorbash)
98
+ - [jimmikarily](https://github.com/jimmykarily)
99
+
100
+ # Licence
101
+ Released under the MIT License. See the
102
+ [LICENSE](https://github.com/Zorbash/response_mate/blob/master/LICENSE) file
103
+ for further details.
104
+
105
+
106
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Zorbash/response_mate/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
107
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run RSpec'
7
+ RSpec::Core::RakeTask.new(:test) do |spec|
8
+ spec.pattern = 'spec/**/*_spec.rb'
9
+ spec.rspec_opts = ['--color', '--format nested']
10
+ end
11
+
12
+ task :default => :test
data/bin/response_mate ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'response_mate'
4
+
5
+ ResponseMate::CLI.start(ARGV)
@@ -0,0 +1,4 @@
1
+ foo: bar
2
+ taco: kokomo
3
+ duck: yellow
4
+ pina: colada
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ require 'thor'
3
+ require 'colored'
4
+ require 'awesome_print'
5
+ require 'active_support/all'
6
+ require 'faraday'
7
+ require 'faraday_middleware'
8
+ require 'addressable/uri'
9
+ require 'highline/import'
10
+ require 'mustache'
11
+ require 'ostruct'
12
+
13
+ require 'response_mate/version'
14
+
15
+ require 'response_mate/commands/base'
16
+
17
+ # Load all commands
18
+ Dir.glob(File.join(File.expand_path('..', __FILE__),
19
+ 'response_mate/commands/*')).each(&method(:require))
20
+
21
+ # Load all helpers
22
+ Dir.glob(File.join(File.expand_path('..', __FILE__), 'response_mate/helpers/*')).each(&method(:require))
23
+
24
+ require 'response_mate/manifest_parser'
25
+ require 'response_mate/connection'
26
+ require 'response_mate/http'
27
+ require 'response_mate/core'
28
+ require 'response_mate/request'
29
+ require 'response_mate/environment'
30
+ require 'response_mate/manifest'
31
+ require 'response_mate/oauth'
32
+ require 'response_mate/tape'
33
+ require 'response_mate/recorder'
34
+ require 'response_mate/inspector'
35
+ require 'response_mate/cli'
36
+ require 'response_mate/exporter'
37
+
38
+ # Load all exporters
39
+ require 'response_mate/exporters/postman'
40
+ Dir.glob(File.join(File.expand_path('..', __FILE__),
41
+ 'response_mate/exporters/*')).each(&method(:require))
42
+
43
+ ResponseMate.setup
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+
3
+ module ResponseMate
4
+ class CLI < ::Thor
5
+ package_name 'response_mate'
6
+
7
+ desc 'Perform requests and records their output', 'Records'
8
+ method_option :base_url, aliases: '-b'
9
+ method_option :requests_manifest, aliases: '-r'
10
+ method_option :keys, aliases: '-k', type: :array
11
+ def record
12
+ ResponseMate::Commands::Record.new(args, options).run
13
+
14
+ rescue ResponseMate::OutputDirError
15
+ puts 'Output directory does not exist, invoking setup..'
16
+ puts 'Please retry after setup'
17
+ invoke :setup, []
18
+ end
19
+
20
+ desc 'Perform requests and prints their output', 'Records'
21
+ method_option :base_url, aliases: '-b'
22
+ method_option :requests_manifest, aliases: '-r'
23
+ method_option :interactive, type: :boolean, aliases: "-i"
24
+ method_option :print, type: :string, aliases: '-p', default: 'raw'
25
+ def inspect(*keys)
26
+ ResponseMate::Commands::Inspect.new(args, options).run
27
+ end
28
+
29
+ desc 'Initializes the required directory structure', 'Initializes'
30
+ def setup(output_dir = '')
31
+ ResponseMate::Commands::Setup.new(args, options).run
32
+ end
33
+
34
+ desc 'Deletes existing response files', 'Cleans up recordings'
35
+ def clear(output_dir = '')
36
+ ResponseMate::Commands::Clear.new(args, options).run
37
+ end
38
+
39
+ desc 'Lists available recordings or keys to record', 'Recording listing'
40
+ method_option :requests_manifest, aliases: '-r'
41
+ def list(type = 'requests')
42
+ ResponseMate::Commands::List.new(args, options).run
43
+
44
+ rescue ResponseMate::OutputDirError
45
+ puts 'Output directory does not exist, invoking setup..'
46
+ puts 'Please retry after setup'
47
+ invoke :setup, []
48
+ end
49
+
50
+ desc 'Exports to one of the available formats', 'Exports'
51
+ method_option :requests_manifest, aliases: '-r'
52
+ method_option :format, aliases: '-f'
53
+ method_option :pretty, aliases: '-p', default: false
54
+ def export
55
+ ResponseMate::Commands::Export.new(args, options).run
56
+ end
57
+ end
58
+ end
@@ -0,0 +1 @@
1
+ module ResponseMate::Commands; end
@@ -0,0 +1,12 @@
1
+ module ResponseMate
2
+ module Commands
3
+ class Base
4
+ attr_accessor :args, :options
5
+
6
+ def initialize(args, options)
7
+ @args = args
8
+ @options = options.dup.symbolize_keys
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module ResponseMate
2
+ module Commands
3
+ # Handles the invocation of the clear command
4
+ class ResponseMate::Commands::Clear < Base
5
+ attr_accessor :output_dir
6
+
7
+ def initialize(args, options)
8
+ super(args, options)
9
+ @options = options.dup
10
+
11
+ @output_dir = if args.present?
12
+ args.first
13
+ else
14
+ ResponseMate.configuration.output_dir
15
+ end
16
+ end
17
+
18
+ def run
19
+ FileUtils.rm_rf(output_dir + '.')
20
+ puts "All clean and shiny!"
21
+ end
22
+ end
23
+ end
24
+ end