fakerest 0.0.6 → 0.0.7

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.
File without changes
@@ -28,27 +28,17 @@ get "/requests/:count" do
28
28
  end_index = user_requests.count
29
29
  range = start_index..end_index
30
30
 
31
- requests_template = '<%= "No requests found" if user_requests.empty? %>
32
- <% user_requests.each do |request| %>
33
- <%= "<b>Method:</b> #{request.method} <b>Status:</b> #{request.response_status_code} <b>URL:</b> #{request.url}" %></br>
34
- <pre><%= request.body %></pre>
35
- <% if request.request_file_path != nil %>
36
- <a href="/<%= request.request_file_path%>"><%= request.request_file_path%></a><br/>
37
- Type: <%= request.request_file_type%>
38
- <% end %>
39
- <hr/>
40
- <% end %>'
41
-
42
- erb requests_template, :locals => {:user_requests => user_requests[range].reverse}
31
+ content_type :json
32
+ user_requests[range].reverse.to_json
43
33
  end
44
34
 
45
35
  get "/" do
46
36
 
47
37
  template = '<div>
48
- Current Profile : <%= current_profile%>
38
+ Current Profile : <%= current_profile%>
49
39
  </div>
50
40
  <br/>'
51
41
 
52
- erb template, :locals => {:current_profile => profile_file_path}
42
+ erb template, :locals => {:current_profile => profile_file_path}
53
43
  end
54
44
 
@@ -25,8 +25,8 @@ module FakeRest
25
25
  options[:port] = prt
26
26
  end
27
27
 
28
- opts.on("-o","--bind HOSTNAME/IP_ADDR","String specifying the hostname or IP address of the interface to listen on . Default = localhost") do |prt|
29
- options[:bind] = prt
28
+ opts.on("-o","--bind HOSTNAME/IP_ADDR","String specifying the hostname or IP address of the interface to listen on . Default = localhost") do |host|
29
+ options[:bind] = host
30
30
  end
31
31
 
32
32
  opts.on("-w","--views VIEWS_FOLDER","Folder path that contains the views. Default = <WORKING_DIR>/views") do |views|
@@ -48,7 +48,7 @@ module FakeRest
48
48
  status request_mapping.status_code
49
49
  request_body = UserRequests.generate_request_body(params, request)
50
50
 
51
- UserRequests.add UserRequest.new(request.request_method, request.url, request_body, request_mapping.status_code, request_file_path, request_file_type)
51
+ UserRequests.add UserRequest.new(request.request_method, request.url, request_body, request_mapping.status_code, params, request_file_path, request_file_type)
52
52
  erb request_mapping.response_file.to_sym, params
53
53
  }
54
54
 
@@ -1,17 +1,25 @@
1
+ require 'json'
2
+
1
3
  module FakeRest
2
4
  class UserRequest
3
5
  attr_reader :response_status_code, :url, :body, :method, :request_file_path, :request_file_type
4
- def initialize(method, url, body, response_status_code, request_file_path = "", request_file_type = "")
6
+ def initialize(method, url, body, response_status_code, params = {}, request_file_path = "", request_file_type = "")
5
7
  @method = method
6
8
  @url = url
7
9
  @body = body
10
+ @params = params
8
11
  @response_status_code = response_status_code
9
12
  @request_file_path = request_file_path
10
13
  @request_file_type = request_file_type
11
14
  end
12
15
 
13
- def to_s
14
- "#{method} #{url} #{response_status_code}\n#{body}\n\n"
16
+ def to_json(*ur)
17
+ {
18
+ "method" => @method,
19
+ "url" => @url,
20
+ "body" => @body,
21
+ "params" => @params.reject {|key,value| key == 'file' or key == 'splat' or key == 'captures' or key == 'outvar' or key =='default_encoding' }
22
+ }.to_json(*ur)
15
23
  end
16
24
  end
17
25
 
@@ -25,7 +33,7 @@ module FakeRest
25
33
  request_body += value != nil ? (key + "=" + value + ",") : (key + ",")
26
34
  end
27
35
 
28
- request_body += "\nBody is: " + request.body.read
36
+ request_body = request.body.read
29
37
  request_body
30
38
  end
31
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakerest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000 Z
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -69,9 +69,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  - - ! '>='
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
- segments:
73
- - 0
74
- hash: 3863224738504212216
75
72
  required_rubygems_version: !ruby/object:Gem::Requirement
76
73
  none: false
77
74
  requirements: