Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zorbash committed Jul 20, 2014
1 parent d85c26a commit 4c4b529
Show file tree
Hide file tree
Showing 36 changed files with 63 additions and 121 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ DEPENDENCIES
rake
response_mate!
rspec (~> 2.14.0)
rubocop
simplecov (~> 0.8.2)
1 change: 0 additions & 1 deletion bin/response_mate
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
# coding: utf-8

require 'response_mate'

Expand Down
1 change: 0 additions & 1 deletion lib/response_mate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
require 'thor'
require 'colored'
require 'awesome_print'
Expand Down
17 changes: 7 additions & 10 deletions lib/response_mate/cli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
class CLI < ::Thor
package_name 'response_mate'
Expand All @@ -16,24 +14,24 @@ def record

desc 'inspect [key1,key2]', 'Perform requests and print their output'
method_option :requests_manifest, aliases: '-r'
def inspect(*keys)
def inspect(*keys) # rubocop:disable Lint/UnusedMethodArgument
ResponseMate::Commands::Inspect.new(args, options).run
end

desc 'setup', 'Initialize the required directory structure'
def setup(output_dir = '')
def setup(output_dir = '') # rubocop:disable Lint/UnusedMethodArgument
ResponseMate::Commands::Setup.new(args, options).run
end

desc 'clear [output_dir]', 'Delete existing response files'
def clear(output_dir = '')
def clear(output_dir = '') # rubocop:disable Lint/UnusedMethodArgument
ResponseMate::Commands::Clear.new(args, options).run
end

desc 'list [request_type] (requests or recordings)',
'List available recordings or keys to record'
desc 'list [request_type] (requests or recordings)', 'List available recordings' \
'or keys to record'
method_option :requests_manifest, aliases: '-r'
def list(type = 'requests')
def list(type = 'requests') # rubocop:disable Lint/UnusedMethodArgument
ResponseMate::Commands::List.new(args, options).run
end

Expand All @@ -43,8 +41,7 @@ def version
end
map ['--version'] => :version

desc 'export',
'Export manifest or environment to one of the available formats'
desc 'export', 'Export manifest or environment to one of the available formats'
method_option :requests_manifest, aliases: '-r'
method_option :format, required: true, aliases: '-f', default: 'postman'
method_option :pretty, aliases: '-p', default: false
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/commands/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
module Commands
class Base
Expand Down
12 changes: 5 additions & 7 deletions lib/response_mate/commands/clear.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
module Commands
# Handles the invocation of the clear command
Expand All @@ -11,15 +9,15 @@ def initialize(args, options)
@options = options.dup

@output_dir = if args.present?
args.first
else
ResponseMate.configuration.output_dir
end
args.first
else
ResponseMate.configuration.output_dir
end
end

def run
FileUtils.rm_rf(output_dir + '.')
puts "All clean and shiny!"
puts 'All clean and shiny!'
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/response_mate/commands/export.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# coding: utf-8

module ResponseMate
module Commands
class ResponseMate::Commands::Export < Base

def initialize(args, options)
super(args, options)
@type = args.first || 'requests'
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/commands/inspect.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Commands::Inspect < ResponseMate::Commands::Base
attr_reader :inspector
attr_accessor :history
Expand Down
5 changes: 2 additions & 3 deletions lib/response_mate/commands/list.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
class ResponseMate::Commands::List < ResponseMate::Commands::Base
def run
environment = ResponseMate::Environment.new(options[:environment])
Expand All @@ -24,10 +23,10 @@ def ask_action
end

def ask_key(available_keys)
choose { |menu|
choose do |menu|
menu.prompt = 'Which one?'
menu.choices(*available_keys)
}.to_s
end.to_s
end

def perform_action(action, key)
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/commands/record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
module Commands
# Handles the invocation of the record command
Expand Down
10 changes: 4 additions & 6 deletions lib/response_mate/commands/setup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
module Commands
# Handles the invocation of the setup command
Expand All @@ -11,10 +9,10 @@ def initialize(args, options)
@options = options.dup

@output_dir = if args.present?
args.first
else
ResponseMate.configuration.output_dir
end
args.first
else
ResponseMate.configuration.output_dir
end
end

def run
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/connection.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

# This class provides a layer above the HTTP client
class ResponseMate::Connection
delegate :params, to: :client
Expand Down
3 changes: 1 addition & 2 deletions lib/response_mate/core.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# coding: utf-8
# The main module of the tool contains configuration code and some constants
module ResponseMate
class OutputDirError < StandardError; end
class KeysNotFound < StandardError; end

HTTP_METHODS = %w(GET POST PUT PATCH DELETE HEAD OPTIONS)
HTTP_METHODS = %w[GET POST PUT PATCH DELETE HEAD OPTIONS]
DEFAULT_HEADERS = { 'User-Agent' => 'Response-Mate' }

class << self
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Environment
attr_accessor :filename, :env, :environment_text

Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/exporter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
class Exporter
attr_accessor :format, :handler, :manifest, :environment, :resource
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/exporters/postman.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate::Exporters
# Handles exporting to postman format
# Example output
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/exporters/postman/collection.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Exporters::Postman
# Handles exporting to postman format
# Example output
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/exporters/postman/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Exporters::Postman
# Handles exporting to postman format
# Example output
Expand Down
4 changes: 1 addition & 3 deletions lib/response_mate/inspector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Inspector
attr_accessor :conn, :manifest

Expand All @@ -9,7 +7,7 @@ def initialize(args = {})
@conn = ResponseMate::Connection.new
end

def inspect_key(key, options = {})
def inspect_key(key)
request = manifest.requests.find { |r| r.key == key }

puts request.to_cli_format
Expand Down
22 changes: 10 additions & 12 deletions lib/response_mate/manifest.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

class ResponseMate::Manifest
attr_accessor :filename, :requests, :requests_text, :environment
attr_reader :name, :description
Expand All @@ -18,7 +16,7 @@ def preprocess_manifest
exit 1
end

if environment.present?
if environment.present? # rubocop:disable Style/GuardClause
@requests_text = Mustache.render(@requests_text, environment.try(:env) || {})
end
end
Expand All @@ -34,17 +32,17 @@ def parse
end

def requests_for_keys(keys)
if keys.present?
existing_keys = requests.map(&:key)
missing_keys = keys - existing_keys
return [] if keys.empty?

existing_keys = requests.map(&:key)
missing_keys = keys - existing_keys

if missing_keys.present?
raise ResponseMate::KeysNotFound.new(missing_keys.join(','))
end
if missing_keys.present?
fail ResponseMate::KeysNotFound.new(missing_keys.join(','))
end

requests.select! do |r|
keys.include? r.key
end
requests.select! do |r|
keys.include? r.key
end
end
end
2 changes: 0 additions & 2 deletions lib/response_mate/recorder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
# Handles recording requests
class Recorder
Expand Down
8 changes: 3 additions & 5 deletions lib/response_mate/request.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# coding: utf-8

class ResponseMate::Request < OpenStruct
delegate :[], to: :request

def normalize!
unless ResponseMate::HTTP_METHODS.include? self.request[:verb]
self.request[:verb] = 'GET'
unless ResponseMate::HTTP_METHODS.include? request[:verb]
request[:verb] = 'GET'
end

self.request[:url] = URI.encode(adjust_scheme(request[:url], request[:scheme]))
request[:url] = URI.encode(adjust_scheme(request[:url], request[:scheme]))

self
end
Expand Down
9 changes: 5 additions & 4 deletions lib/response_mate/tape.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# encoding: utf-8

class ResponseMate::Tape
def write(key, request, response, meta = {}, output_dir = nil)
output_dir = output_dir || ResponseMate.configuration.output_dir
output_dir ||= ResponseMate.configuration.output_dir

output_path = File.join output_dir, "#{key}.yml"

Expand Down Expand Up @@ -30,7 +28,10 @@ def _utf8_encode(object)
when String
object.force_encoding('UTF-8')
when Hash
object.each { |k, v| k = _utf8_encode(v); v = _utf8_encode(v) }
object.each do |k, v|
k = _utf8_encode(v)
v = _utf8_encode(v)
end
when Array
object.each { |v| _utf8_encode(v) }
end
Expand Down
2 changes: 0 additions & 2 deletions lib/response_mate/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module ResponseMate
VERSION = '0.2.2'
end
10 changes: 5 additions & 5 deletions response_mate.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'response_mate/version'
Expand All @@ -11,17 +10,18 @@ Gem::Specification.new do |spec|
spec.description = <<-DESC
Cli tool to make inspecting and recording HTTP requests fun again
DESC
spec.summary = %q{A cli tool for browsing and recording api requests with ease}
spec.summary = %q(A cli tool for browsing and recording api requests with ease)
spec.homepage = 'https://github.com/Zorbash/response_mate'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'

spec.add_dependency 'thor', '~> 0.19'
spec.add_dependency 'awesome_print'
Expand Down
4 changes: 1 addition & 3 deletions spec/lib/response_mate/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper'

describe ResponseMate::CLI do
Expand Down Expand Up @@ -28,7 +26,7 @@
end
end

describe'#inspect' do
describe '#inspect' do
before do
allow(ResponseMate::Commands::Inspect).to receive(:new).and_return(command)
end
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/response_mate/commands/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper'

describe ResponseMate::Commands::Inspect do
Expand All @@ -16,7 +14,7 @@
end
end

expect(error_output.strip).to eq("At least one key has to be specified".red)
expect(error_output.strip).to eq('At least one key has to be specified'.red)
end
end

Expand Down Expand Up @@ -46,7 +44,7 @@

it 'includes the response status' do
expect(captured_output).
to include(":status => #{fake_response_user_issues[:status].to_s}")
to include(":status => #{fake_response_user_issues[:status]}")
end

it 'includes the response body' do
Expand Down
2 changes: 0 additions & 2 deletions spec/lib/response_mate/commands/list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper'

describe ResponseMate::Commands::List do
Expand Down

0 comments on commit 4c4b529

Please sign in to comment.