whurl_engine 1.2.2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/README.markdown +2 -0
  2. data/Rakefile +2 -12
  3. data/app/assets/javascripts/whurl_engine/application.js +0 -159
  4. data/app/assets/javascripts/whurl_engine/jquery-ujs.js +315 -0
  5. data/app/assets/javascripts/whurl_engine/jquery.livequery.js +226 -0
  6. data/app/assets/javascripts/whurl_engine/whurl.js +136 -0
  7. data/app/assets/stylesheets/whurl_engine/application.css.scss +88 -1
  8. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_flat_100_ffffff_40x100.png +0 -0
  9. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_flat_10_000000_40x100.png +0 -0
  10. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_flat_18_f6ecd5_40x100.png +0 -0
  11. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_flat_20_666666_40x100.png +0 -0
  12. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  13. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_highlight-hard_100_dddddd_1x100.png +0 -0
  14. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_highlight-hard_100_eeeeee_1x100.png +0 -0
  15. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_highlight-hard_40_f6a828_1x100.png +0 -0
  16. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-bg_highlight-soft_75_f1fbe5_1x100.png +0 -0
  17. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_1c94c4_256x240.png +0 -0
  18. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_222222_256x240.png +0 -0
  19. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_8cce3b_256x240.png +0 -0
  20. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_cd0a0a_256x240.png +0 -0
  21. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_ef8c08_256x240.png +0 -0
  22. data/app/assets/stylesheets/whurl_engine/custom-theme/images/ui-icons_ffffff_256x240.png +0 -0
  23. data/app/assets/stylesheets/whurl_engine/custom-theme/jquery-ui-1.8.16.custom.css +562 -0
  24. data/app/assets/stylesheets/whurl_engine/whurl.css.scss +128 -0
  25. data/app/controllers/whurl_engine/application_controller.rb +2 -0
  26. data/app/controllers/whurl_engine/categories_controller.rb +36 -0
  27. data/app/controllers/whurl_engine/parameter_definitions_controller.rb +32 -0
  28. data/app/controllers/whurl_engine/resources_controller.rb +36 -0
  29. data/app/controllers/whurl_engine/whurls_controller.rb +42 -0
  30. data/app/models/whurl_engine/category.rb +7 -0
  31. data/app/models/whurl_engine/parameter_definition.rb +7 -0
  32. data/app/models/whurl_engine/resource.rb +12 -0
  33. data/app/models/whurl_engine/whurl.rb +66 -0
  34. data/app/views/layouts/whurl_engine/application.html.haml +41 -44
  35. data/app/views/whurl_engine/categories/_category.html.haml +15 -0
  36. data/app/views/whurl_engine/categories/_form.html.haml +24 -0
  37. data/app/views/whurl_engine/categories/create.js.haml +5 -0
  38. data/app/views/whurl_engine/categories/destroy.js.haml +1 -0
  39. data/app/views/whurl_engine/categories/edit.js.haml +3 -0
  40. data/app/views/whurl_engine/categories/index.html.haml +6 -0
  41. data/app/views/whurl_engine/categories/new.js.haml +3 -0
  42. data/app/views/whurl_engine/categories/update.js.haml +6 -0
  43. data/app/views/whurl_engine/parameter_definitions/_form.html.haml +31 -0
  44. data/app/views/whurl_engine/parameter_definitions/_parameter_definition.html.haml +14 -0
  45. data/app/views/whurl_engine/parameter_definitions/create.js.haml +5 -0
  46. data/app/views/whurl_engine/parameter_definitions/destroy.js.haml +1 -0
  47. data/app/views/whurl_engine/parameter_definitions/edit.js.haml +3 -0
  48. data/app/views/whurl_engine/parameter_definitions/new.js.haml +3 -0
  49. data/app/views/whurl_engine/parameter_definitions/update.js.haml +6 -0
  50. data/app/views/whurl_engine/resources/_form.html.haml +40 -0
  51. data/app/views/whurl_engine/resources/_resource.html.haml +6 -0
  52. data/app/views/whurl_engine/resources/create.js.haml +5 -0
  53. data/app/views/whurl_engine/resources/destroy.js.haml +1 -0
  54. data/app/views/whurl_engine/resources/edit.js.haml +3 -0
  55. data/app/views/whurl_engine/resources/new.js.haml +3 -0
  56. data/app/views/whurl_engine/resources/show.html.haml +29 -0
  57. data/app/views/whurl_engine/resources/update.js.haml +6 -0
  58. data/app/views/whurl_engine/shared/_error.js.haml +2 -0
  59. data/app/views/whurl_engine/whurls/_edit_form.html.haml +29 -0
  60. data/app/views/whurl_engine/whurls/_form.html.haml +42 -0
  61. data/app/views/whurl_engine/{whurl_requests → whurls}/_input_set.html.haml +1 -1
  62. data/app/views/whurl_engine/whurls/_response.html.haml +5 -0
  63. data/app/views/whurl_engine/whurls/_whurl.html.haml +18 -0
  64. data/app/views/whurl_engine/whurls/destroy.js.haml +2 -0
  65. data/app/views/whurl_engine/{whurl_requests → whurls}/edit.html.haml +3 -4
  66. data/app/views/whurl_engine/whurls/edit.js.haml +3 -0
  67. data/app/views/whurl_engine/whurls/show.html.haml +4 -0
  68. data/config/initializers/httparty/request.rb +9 -0
  69. data/config/initializers/httparty/response.rb +7 -25
  70. data/config/initializers/net/http_generic_request.rb +9 -0
  71. data/config/initializers/nilclass.rb +5 -0
  72. data/config/initializers/string.rb +32 -0
  73. data/config/routes.rb +6 -3
  74. data/db/migrate/20110209054322_create_whurls_table.rb +14 -0
  75. data/db/migrate/20111210192724_add_description_to_whurl.rb +9 -0
  76. data/db/migrate/20111210201607_add_custom_url_to_whurl.rb +9 -0
  77. data/db/migrate/20111211030904_rename_whurls_to_requests.rb +8 -0
  78. data/db/migrate/20111220233800_create_fields_for_whurl_requests.rb +10 -10
  79. data/db/migrate/20120106033416_create_responses.rb +11 -0
  80. data/db/migrate/20120106190508_create_categories_table.rb +9 -0
  81. data/db/migrate/20120107011500_create_resources_table.rb +15 -0
  82. data/db/migrate/20120107065652_create_parameters_table.rb +12 -0
  83. data/db/migrate/20120110205837_rename_parameters_to_parameter_definitions.rb +5 -0
  84. data/db/migrate/20120110205853_rename_requests_to_whurls.rb +19 -0
  85. data/db/migrate/20120111014928_add_raw_request_to_whurls.rb +5 -0
  86. data/lib/whurl_engine/version.rb +1 -1
  87. metadata +140 -177
  88. data/app/assets/stylesheets/whurl_engine/code.css.scss +0 -13
  89. data/app/assets/stylesheets/whurl_engine/jquery.ui.autocomplete.css.scss +0 -55
  90. data/app/assets/stylesheets/whurl_engine/whurls.css.scss +0 -358
  91. data/app/controllers/whurl_engine/whurl_requests_controller.rb +0 -52
  92. data/app/models/whurl_engine/any_client.rb +0 -7
  93. data/app/models/whurl_engine/whurl_request.rb +0 -37
  94. data/app/views/whurl_engine/whurl_requests/_form.html.haml +0 -51
  95. data/app/views/whurl_engine/whurl_requests/show.html.haml +0 -1
  96. data/db/migrate/20110209054322_create_whurl_requests_table.rb +0 -14
  97. data/db/migrate/20111210192724_add_description_to_whurl_requests.rb +0 -9
  98. data/db/migrate/20111210201607_add_custom_url_to_whurl_requests.rb +0 -9
  99. data/db/migrate/20111221010348_copy_data_to_new_fields.rb +0 -39
  100. data/db/migrate/20111221011145_drop_data_from_whurl_requestss.rb +0 -9
  101. data/test/dummy/Rakefile +0 -7
  102. data/test/dummy/app/assets/javascripts/application.js +0 -9
  103. data/test/dummy/app/assets/stylesheets/application.css +0 -7
  104. data/test/dummy/app/controllers/application_controller.rb +0 -3
  105. data/test/dummy/app/helpers/application_helper.rb +0 -2
  106. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  107. data/test/dummy/app/views/layouts/whurl_engine/application.html.haml +0 -56
  108. data/test/dummy/config/application.rb +0 -45
  109. data/test/dummy/config/boot.rb +0 -10
  110. data/test/dummy/config/database.sample.yml +0 -17
  111. data/test/dummy/config/database.yml +0 -17
  112. data/test/dummy/config/environment.rb +0 -5
  113. data/test/dummy/config/environments/development.rb +0 -30
  114. data/test/dummy/config/environments/production.rb +0 -60
  115. data/test/dummy/config/environments/test.rb +0 -39
  116. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  117. data/test/dummy/config/initializers/inflections.rb +0 -10
  118. data/test/dummy/config/initializers/mime_types.rb +0 -5
  119. data/test/dummy/config/initializers/secret_token.rb +0 -7
  120. data/test/dummy/config/initializers/session_store.rb +0 -8
  121. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  122. data/test/dummy/config/locales/en.yml +0 -5
  123. data/test/dummy/config/routes.rb +0 -4
  124. data/test/dummy/config.ru +0 -4
  125. data/test/dummy/db/schema.rb +0 -31
  126. data/test/dummy/log/development.log +0 -80
  127. data/test/dummy/public/404.html +0 -26
  128. data/test/dummy/public/422.html +0 -26
  129. data/test/dummy/public/500.html +0 -26
  130. data/test/dummy/public/favicon.ico +0 -0
  131. data/test/dummy/script/rails +0 -6
  132. data/test/dummy/tmp/cache/assets/C6D/500/sprockets%2Fa60a126c749b135b047d47c9116f7010 +0 -0
  133. data/test/dummy/tmp/cache/assets/C85/760/sprockets%2F67d86b8948de011684953a4b2d30c280 +0 -0
  134. data/test/dummy/tmp/cache/assets/CB8/FF0/sprockets%2F789d641670bfe15510034f63eb635ff8 +0 -0
  135. data/test/dummy/tmp/cache/assets/CB9/340/sprockets%2Fc383855f31a6f96cfad737d462029019 +0 -0
  136. data/test/dummy/tmp/cache/assets/CBD/A60/sprockets%2F8e7fec8543052565b343a93c7b174d78 +0 -0
  137. data/test/dummy/tmp/cache/assets/CE6/140/sprockets%2F97da5e07430aa9249a9633e88c5073ea +0 -0
  138. data/test/dummy/tmp/cache/assets/D01/6E0/sprockets%2F3974f4fd239fc76f2d9700899609da7e +0 -0
  139. data/test/dummy/tmp/cache/assets/D09/700/sprockets%2F68ca75710cc64126df7d1a6638ca16d1 +0 -0
  140. data/test/dummy/tmp/cache/assets/D18/6A0/sprockets%2Fdf8266a6da92a42ce29b771318176dc9 +0 -0
  141. data/test/dummy/tmp/cache/assets/D1C/440/sprockets%2Fd5f5cd99df7e614581ec5f2256403e33 +0 -0
  142. data/test/dummy/tmp/cache/assets/D2C/DB0/sprockets%2F802a914bb4d275c8c34a3aa5ec134d54 +0 -0
  143. data/test/dummy/tmp/cache/assets/D39/780/sprockets%2F0da3fdc5af08e2938cc21829334b1d48 +0 -0
  144. data/test/dummy/tmp/cache/assets/D3D/010/sprockets%2F389924c72fa75b369a0e61aacfa230e8 +0 -0
  145. data/test/dummy/tmp/cache/assets/D4C/8D0/sprockets%2F024e6456c9877ae45cdb28d7d16e06fe +0 -0
  146. data/test/dummy/tmp/cache/assets/D66/D70/sprockets%2Ffdf1533f584b1ba62ce0ca92848b14d3 +0 -0
  147. data/test/dummy/tmp/cache/assets/D6F/A10/sprockets%2F3fa8ede522a279bfc12817267d1ca57e +0 -0
  148. data/test/dummy/tmp/cache/assets/D9D/AC0/sprockets%2F082b6d491d42f3a4febe3cb4d0983e6d +0 -0
  149. data/test/dummy/tmp/cache/assets/DA4/180/sprockets%2F118a85fd98ac4bda49f6485fd41aca44 +0 -0
  150. data/test/dummy/tmp/cache/assets/DB4/C60/sprockets%2F6ee1d0983f6518ba5dc089797bfc6ffa +0 -0
  151. data/test/dummy/tmp/cache/assets/DBD/7A0/sprockets%2F872f84e976ebe7654383dfdc7cfec1c6 +0 -0
  152. data/test/dummy/tmp/cache/assets/DD7/420/sprockets%2F11c951f1c4e2bfc0d7c1b10e0bb1b2be +0 -0
  153. data/test/dummy/tmp/cache/assets/E29/F00/sprockets%2F5b6ee8619eacc15eaf00c329cedff60a +0 -0
  154. data/test/dummy/tmp/cache/assets/E5D/680/sprockets%2F5ef33ecefc8e09aafd4d2725c0ef0a9c +0 -0
  155. data/test/fixtures/whurl_engine/whurl_requests.yml +0 -11
  156. data/test/functional/whurl_engine/api_call_controller_test.rb +0 -21
  157. data/test/integration/navigation_test.rb +0 -10
  158. data/test/test_helper.rb +0 -10
  159. data/test/unit/helpers/whurl_engine/api_call_helper_test.rb +0 -6
  160. data/test/unit/whurl_engine/whurl_request_test.rb +0 -9
  161. data/test/whurl_engine_test.rb +0 -7
  162. /data/app/views/whurl_engine/{whurl_requests → whurls}/new.html.haml +0 -0
@@ -0,0 +1,128 @@
1
+ $dark: #2B2F38;
2
+ $highlight: #F1CB31;
3
+
4
+ @mixin rounded-corners($topleft, $topright: $topleft, $bottomright: $topleft, $bottomleft: $topleft) {
5
+ border-radius: $topleft $topright $bottomright $bottomleft;
6
+ -moz-border-radius: $topleft $topright $bottomright $bottomleft;
7
+ -webkit-border-radius: $topleft $topright $bottomright $bottomleft;
8
+ }
9
+
10
+ @mixin rotate($degrees) {
11
+ transform: rotate($degrees);
12
+ -ms-transform: rotate($degrees);
13
+ -webkit-transform: rotate($degrees);
14
+ -o-transform: rotate($degrees);
15
+ -moz-transform: rotate($degrees);
16
+ }
17
+
18
+ .whurls.show {
19
+ .menu {
20
+ position: fixed;
21
+ bottom: 20px;
22
+ left: 0;
23
+ border: 1px solid #666;
24
+ border-left: none;
25
+ background-color: #f6a828;
26
+ border-radius: 0 20px 20px 0;
27
+ width: auto;
28
+ font-size: 16px;
29
+ padding: 5px;
30
+ }
31
+ }
32
+
33
+ .whurl {
34
+ td.line_numbers pre, td.code pre, td.code span {
35
+ font-family: monospace;
36
+ }
37
+
38
+ table.CodeRay {
39
+ border-collapse: collapse;
40
+ }
41
+
42
+ td.line_numbers {
43
+ background-color: #DDD;
44
+ text-align: right;
45
+ padding: 0 5px;
46
+ }
47
+ }
48
+
49
+ .whurl_form {
50
+ .headers, .params, .url, .post_body, .button_row {
51
+ margin-left: 162px;
52
+ min-height: 31px;
53
+ margin-bottom: 10px;
54
+ }
55
+
56
+ .header_pair, .param_pair {
57
+ padding: 4px 0;
58
+ }
59
+
60
+ .key {
61
+ width: 200px;
62
+ }
63
+
64
+ .value {
65
+ width: 400px;
66
+ }
67
+
68
+ .long {
69
+ width: 525px;
70
+ }
71
+
72
+ #whurl_request_url {
73
+ width: 514px;
74
+ }
75
+
76
+ input.one {
77
+ width: 480px;
78
+ }
79
+
80
+ input.two {
81
+ width: 225px;
82
+ }
83
+
84
+ input.three {
85
+ width: 350px;
86
+ margin-left: 10px;
87
+ }
88
+
89
+ input.four {
90
+ width: 350px;
91
+ }
92
+
93
+ textarea#whurl_request_body {
94
+ width: 610px;
95
+ height: 55px;
96
+ margin-bottom: 10px;
97
+ }
98
+
99
+ .textarea_disabled {
100
+ background-color: lightgray;
101
+ }
102
+
103
+ .section_title {
104
+ padding: 4px 0;
105
+ float: left;
106
+ text-align: right;
107
+ width: 155px;
108
+ line-height: 26px;
109
+ }
110
+
111
+ a.copy_link {
112
+ width: 115.5px;
113
+ height: 44px;
114
+ background: url('copyURL.png') no-repeat 0 0;
115
+ margin: 30px 0 0 45px;
116
+ display: block;
117
+ }
118
+
119
+ a.copy_link:hover {
120
+ background-position: -116px 0;
121
+ }
122
+
123
+ .param_pair:first-child,
124
+ .header_pair:first-child
125
+ {
126
+ display: none;
127
+ }
128
+ }
@@ -1,3 +1,5 @@
1
+ require 'rinku'
2
+
1
3
  module WhurlEngine
2
4
  class ApplicationController < ActionController::Base
3
5
  end
@@ -0,0 +1,36 @@
1
+ module WhurlEngine
2
+ class CategoriesController < ApplicationController
3
+ def index
4
+ @categories = WhurlEngine::Category.all.sort
5
+ end
6
+
7
+ def new
8
+ @category = WhurlEngine::Category.new
9
+ end
10
+
11
+ def create
12
+ @category = WhurlEngine::Category.new(params[:category])
13
+ unless @category.save
14
+ render :partial => 'whurl_engine/shared/error', :locals => {:object => @category}
15
+ end
16
+ end
17
+
18
+ def edit
19
+ @category = WhurlEngine::Category.find(params[:id])
20
+ end
21
+
22
+ def update
23
+ @category = WhurlEngine::Category.find(params[:id])
24
+ unless @category.update_attributes(params[:category])
25
+ render :partial => 'whurl_engine/shared/error', :locals => {:object => @category}
26
+ end
27
+ end
28
+
29
+ def destroy
30
+ @category = WhurlEngine::Category.find(params[:id])
31
+ unless @category.destroy
32
+ render :partial => 'whurl_engine/shared/error', :locals => {:object => @category}
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module WhurlEngine
2
+ class ParameterDefinitionsController < ApplicationController
3
+ def new
4
+ @parameter = WhurlEngine::ParameterDefinition.new(:resource_id => params[:resource_id])
5
+ end
6
+
7
+ def create
8
+ @parameter = WhurlEngine::ParameterDefinition.new(params[:parameter])
9
+ unless @parameter.save
10
+ render :partial => 'error'
11
+ end
12
+ end
13
+
14
+ def edit
15
+ @parameter = WhurlEngine::ParameterDefinition.find(params[:id])
16
+ end
17
+
18
+ def update
19
+ @parameter = WhurlEngine::ParameterDefinition.find(params[:id])
20
+ unless @parameter.update_attributes(params[:parameter])
21
+ render :partial => 'error'
22
+ end
23
+ end
24
+
25
+ def destroy
26
+ @parameter = WhurlEngine::ParameterDefinition.find(params[:id])
27
+ unless @parameter.destroy
28
+ render :partial => 'error'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module WhurlEngine
2
+ class ResourcesController < ApplicationController
3
+ def show
4
+ @resource = WhurlEngine::Resource.find(params[:id])
5
+ end
6
+
7
+ def new
8
+ @resource = WhurlEngine::Resource.new(:category_id => params[:category_id])
9
+ end
10
+
11
+ def create
12
+ @resource = WhurlEngine::Resource.new(params[:resource])
13
+ unless @resource.save
14
+ render :partial => 'error'
15
+ end
16
+ end
17
+
18
+ def edit
19
+ @resource = WhurlEngine::Resource.find(params[:id])
20
+ end
21
+
22
+ def update
23
+ @resource = WhurlEngine::Resource.find(params[:id])
24
+ unless @resource.update_attributes(params[:resource])
25
+ render :partial => 'error'
26
+ end
27
+ end
28
+
29
+ def destroy
30
+ @resource = WhurlEngine::Resource.find(params[:id])
31
+ unless @resource.destroy
32
+ render :partial => 'error'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ module WhurlEngine
2
+ class WhurlsController < ApplicationController
3
+ def new
4
+ @whurl = Whurl.new
5
+ end
6
+
7
+ def create
8
+ request_params = params[:whurl]
9
+ request_params[:request_headers] = HTTParty::Response::Headers.new(Hash[params[:header_keys].zip(params[:header_values])].delete_if { |k, _| k.blank? })
10
+ request_params[:request_parameters] = Hash[params[:param_keys].zip(params[:param_values])].delete_if { |k, _| k.blank? }
11
+ @whurl = Whurl.new(request_params)
12
+
13
+ unless @whurl.save
14
+ flash[:alert] = @whurl.errors.map {|k,v| "#{k.to_s.titleize} #{v}"}.join('\n')
15
+ render :new and return
16
+ end
17
+ redirect_to short_whurl_path(@whurl)
18
+ end
19
+
20
+ def edit
21
+ @whurl = Whurl.find_by_hash_key(params[:id])
22
+ end
23
+
24
+ def update
25
+ @whurl = Whurl.find_by_hash_key(params[:id])
26
+ unless @whurl.update_attributes(params[:whurl])
27
+ render :partial => 'whurl_engine/shared/error', :locals => {:object => @whurl}
28
+ end
29
+ redirect_to resource_path(params[:whurl][:resource_id])
30
+ end
31
+ def destroy
32
+ @whurl = Whurl.find_by_hash_key(params[:id])
33
+ unless @whurl.destroy
34
+ render :partial => 'whurl_engine/shared/error', :locals => {:object => @whurl}
35
+ end
36
+ end
37
+
38
+ def show
39
+ @whurl = Whurl.find_by_hash_key(params[:id])
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ module WhurlEngine
2
+ class Category < ActiveRecord::Base
3
+ validates_presence_of :name
4
+
5
+ has_many :resources, :order => :relative_path
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module WhurlEngine
2
+ class ParameterDefinition < ActiveRecord::Base
3
+ belongs_to :resource
4
+
5
+ validates_presence_of :name
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module WhurlEngine
2
+ class Resource < ActiveRecord::Base
3
+ belongs_to :category
4
+ has_many :parameter_definitions
5
+ has_many :whurls
6
+ validates_presence_of :base_uri, :relative_path
7
+
8
+ def url
9
+ File.join(base_uri, relative_path)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ require 'httmultiparty'
2
+ require "whurl_engine/version"
3
+
4
+ module WhurlEngine
5
+ class Whurl < ActiveRecord::Base
6
+ serialize :request_parameters, Hash
7
+ serialize :request_headers, ::HTTParty::Response::Headers
8
+ serialize :response_headers, ::HTTParty::Response::Headers
9
+
10
+ after_initialize :default_values
11
+ before_create :make_request
12
+
13
+ belongs_to :resource
14
+
15
+ def to_param
16
+ hash_key
17
+ end
18
+
19
+ def to_curl
20
+ ret_str = "curl \"#{url}\" --include --request #{http_method.upcase}"
21
+ headers.each do |k, v|
22
+ ret_str << " -H #{k}:#{v}"
23
+ end
24
+ if ['put', 'post'].include?(http_method.downcase)
25
+ ret_str << " --data \"#{body}\""
26
+ end
27
+
28
+ ret_str << " --head" if http_method.downcase == 'head'
29
+ ret_str
30
+ end
31
+
32
+ private
33
+
34
+ class AnyClient
35
+ include HTTMultiParty
36
+ #debug_output $stderr
37
+ end
38
+
39
+ def make_request
40
+ response = AnyClient.send(request_method.downcase,
41
+ request_url,
42
+ :headers => request_headers.to_hash,
43
+ :query => request_parameters.blank? ? nil : request_parameters,
44
+ :body => request_body
45
+ )
46
+ self.response_content_type = response.content_type
47
+ self.response_body = response.body
48
+ self.response_headers = response.headers
49
+ self.raw_request = response.request.to_s
50
+ end
51
+
52
+ def default_values
53
+ generate_hash_key if new_record?
54
+ end
55
+
56
+ def generate_hash_key
57
+ upper_bound = 36**6 -1 #max 6 characters
58
+ new_hash_key = rand(upper_bound).to_s(36)
59
+ if new_hash_key.match(/^whurl/)
60
+ generate_hash_key
61
+ else
62
+ self.hash_key = new_hash_key
63
+ end
64
+ end
65
+ end
66
+ end
@@ -4,53 +4,50 @@
4
4
  = stylesheet_link_tag("whurl_engine/application")
5
5
  = javascript_include_tag("whurl_engine/jquery-1.7.1.min")
6
6
  = javascript_include_tag("whurl_engine/jquery-ui-1.8.16.min")
7
+ = javascript_include_tag("whurl_engine/jquery-ujs")
8
+ = javascript_include_tag("whurl_engine/jquery.livequery")
7
9
  = javascript_include_tag("whurl_engine/application")
10
+ = javascript_include_tag("whurl_engine/whurl")
8
11
  = javascript_include_tag("whurl_engine/ZeroClipboard")
9
12
  :javascript
10
- $(document).ready(function() {
11
- ZeroClipboard.setMoviePath('#{asset_path('whurl_engine/ZeroClipboard10.swf')}');
13
+ $(function() {
14
+ ZeroClipboard.setMoviePath('#{asset_path('whurl_engine/ZeroClipboard10.swf')}');
15
+ $( "input:submit, input:reset, input:button, button, .button").livequery(function() {
16
+ $(this).button();
17
+ $("a.popup").button('option', 'icons', {primary: 'ui-icon-newwin'});
18
+ $("a.add").button('option', 'icons', {primary: 'ui-icon-plusthick'});
19
+ $("a.destroy").button('option', 'icons', {primary: 'ui-icon-closethick'});
20
+ $("a.trash").button('option', 'icons', {primary: 'ui-icon-trash'});
21
+ $("a.edit").button('option', 'icons', {primary: 'ui-icon-pencil'});
22
+ $("a.save").button('option', 'icons', {secondary: 'ui-icon-folder-open'});
23
+ $("a.destroy, a.edit, a.add, a.trash").button('option', 'text', false);
24
+ });
25
+
26
+ $( ".accordion" ).accordion({
27
+ autoHeight: false,
28
+ navigation: true,
29
+ collapsible: true,
30
+ active: false
31
+ });
12
32
  });
13
33
 
14
34
  %title Whurl - API Console
15
- :javascript
16
- $(function() {
17
- $('#saved_whurls').hover(
18
- function () {
19
- $(this).stop().animate({'marginLeft':'-2px'},200);
20
- },
21
- function () {
22
- $(this).stop().animate({'marginLeft':'-400px'},200);
23
- }
24
- );
25
- });
26
- %body
27
- - if flash[:message] || flash[:warning]
28
- .flash
29
- - if flash[:message]
30
- %span.message= flash[:message]
31
- - if flash[:warning]
32
- %span.warning= flash[:warning]
33
- #wrapper
34
- =link_to(image_tag("whurl_engine/logo.png", :height => "147", :width => "521", :class => 'logo'), root_url)
35
- %p.tagline The Whurl Console makes HTTP requests against the API of your choice.
36
- .containerTop  
37
- #container
38
- .content
39
- = yield
40
- .footer
41
- %p
42
- Created by
43
- = succeed "." do
44
- %a.contact{:href => "mailto:will.read@gmail.com"} Will Read
45
- See it on
46
- = succeed "." do
47
- %a{:href => "https://github.com/tildewill/whurl"} Github
48
- %br/
49
- %span.meadowfete
50
- Designed by
51
- = succeed "." do
52
- %a.meadowfete{:href => "http://meadowfete.com", :target => "_blank"} Meadowfete
53
- =image_tag("whurl_engine/container_bottom.png", :height => "56", :width => "980")
54
- %ol#saved_whurls
55
- - WhurlEngine::WhurlRequest.saved.each do |whurl|
56
- %li=link_to(whurl.custom_url, short_path(:slug => whurl.custom_url))
35
+ %body{:class => [controller_name, action_name]}
36
+ .content
37
+ - if notice || alert
38
+ .flash
39
+ - if notice
40
+ .ui-state-highlight.ui-corner-all
41
+ = notice
42
+ - if alert
43
+ .ui-state-error.ui-corner-all
44
+ = alert
45
+ = yield
46
+ .footer
47
+ %p
48
+ Created by
49
+ = succeed "." do
50
+ %a.contact{:href => "mailto:will.read@gmail.com"} Will Read
51
+ See it on
52
+ = succeed "." do
53
+ %a{:href => "https://github.com/tildewill/whurl"} Github
@@ -0,0 +1,15 @@
1
+ %div{:id => "category_#{category.id}"}
2
+ %h2
3
+ = category.name
4
+ = link_to('Add Resource', new_resource_path(:category_id => category.id), :remote => true, :class => 'popup button')
5
+ = link_to('', edit_category_path(category), :remote => true, :class => 'edit button icon_only')
6
+ = link_to( '', category, :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => 'destroy button icon_only')
7
+ %p=category.description
8
+ %table{:id => "category_#{category.id}"}
9
+ %thead
10
+ %tr
11
+ %th Resource
12
+ %th Description
13
+ %tbody.resources
14
+ - category.resources.each do |resource|
15
+ = render(resource)
@@ -0,0 +1,24 @@
1
+ :javascript
2
+ $(function() {
3
+ $( ".new_whurl_engine_category, .edit_whurl_engine_category" ).dialog(
4
+ {
5
+ modal: true,
6
+ autoOpen: false,
7
+ title: 'Manage Categories',
8
+ minWidth: 375,
9
+ minHeight: 300,
10
+ close: function(event, ui) {
11
+ $(this).remove();
12
+ }
13
+ });
14
+ });
15
+
16
+ = form_for category, :remote => true do |f|
17
+ %div
18
+ = f.label :name
19
+ = f.text_field :name, :placeholder => 'eg. Users, Projects, Tweets, etc.'
20
+ %div
21
+ = f.label :description
22
+ %div
23
+ = f.text_area :description
24
+ = f.submit :value => 'Submit'
@@ -0,0 +1,5 @@
1
+ $(".new_whurl_engine_category").dialog('close');
2
+
3
+ - content = escape_javascript(render(@category))
4
+ $('.categories').append("#{content}");
5
+ $("#category_#{@category.id}").effect("highlight", {}, 3000);
@@ -0,0 +1 @@
1
+ $("#category_#{@category.id}").fadeOut()
@@ -0,0 +1,3 @@
1
+ - content = escape_javascript(render(:partial => 'form', :locals => {:category => @category}))
2
+ $('.content').append("#{content}");
3
+ $('.edit_whurl_engine_category').dialog('open');
@@ -0,0 +1,6 @@
1
+ %h1
2
+ REST API Resources
3
+ = link_to('Add Category', new_category_path, :remote => true, :class => 'popup button')
4
+ .categories
5
+ - @categories.each do |category|
6
+ = render(category)
@@ -0,0 +1,3 @@
1
+ - content = escape_javascript(render(:partial => 'form', :locals => {:category => @category}))
2
+ $('.content').append("#{content}");
3
+ $('.new_whurl_engine_category').dialog('open');
@@ -0,0 +1,6 @@
1
+ $(".edit_whurl_engine_category").dialog('close');
2
+
3
+ - content = escape_javascript(render(@category));
4
+ target_row = $("#category_#{@category.id}");
5
+ target_row.replaceWith("#{content}");
6
+ $("#category_#{@category.id}").effect("highlight", {}, 3000);
@@ -0,0 +1,31 @@
1
+ :javascript
2
+ $(function() {
3
+ $( ".new_whurl_engine_parameter_definition, .edit_whurl_engine_parameter_definition" ).dialog(
4
+ {
5
+ modal: true,
6
+ autoOpen: false,
7
+ title: 'Manage Parameters',
8
+ minWidth: 375,
9
+ minHeight: 300,
10
+ close: function(event, ui) {
11
+ $(this).remove();
12
+ }
13
+ });
14
+ });
15
+
16
+ = form_for(@parameter_definition, :remote => true) do |f|
17
+ = f.hidden_field :resource_id
18
+ %div
19
+ = f.label :name
20
+ = f.text_field :name
21
+ %div
22
+ = f.check_box :required
23
+ = f.label :required
24
+ %div
25
+ = f.label :example_value
26
+ = f.text_field :example_value
27
+ %div
28
+ = f.label :description
29
+ %div
30
+ = f.text_area :description
31
+ = f.submit :value => 'Submit'
@@ -0,0 +1,14 @@
1
+ %tr{:id => "parameter_definition_#{parameter_definition.id}"}
2
+ %td
3
+ %strong= parameter_definition.name
4
+ %br
5
+ = parameter_definition.required? ? "required" : "optional"
6
+ %br
7
+ = link_to('', edit_parameter_definition_path(parameter_definition), :remote => true, :class => 'edit button icon_only')
8
+ = link_to( '', parameter_definition, :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => 'destroy button icon_only')
9
+
10
+ %td
11
+ = parameter_definition.description
12
+ %div
13
+ Example Value:
14
+ = parameter_definition.example_value
@@ -0,0 +1,5 @@
1
+ $(".new_whurl_engine_parameter_definition").dialog('close');
2
+
3
+ - content = escape_javascript(render(@parameter_definition))
4
+ $('.parameter_definition').append("#{content}");
5
+ $("#parameter_definition_#{@parameter_definition.id}").effect("highlight", {}, 3000);
@@ -0,0 +1 @@
1
+ $("#parameter_definition_#{@parameter_definition.id}").fadeOut()
@@ -0,0 +1,3 @@
1
+ - content = escape_javascript(render(:partial => 'form', :locals => {:parameter_definition => @parameter_definition}))
2
+ $('.content').append("#{content}");
3
+ $('.edit_whurl_engine_parameter_definition').dialog('open');
@@ -0,0 +1,3 @@
1
+ - content = escape_javascript(render(:partial => 'form', :locals => {:parameter_definition => @parameter_definition}))
2
+ $('.content').append("#{content}");
3
+ $('.new_whurl_engine_parameter_definition').dialog('open');
@@ -0,0 +1,6 @@
1
+ $(".edit_whurl_engine_parameter_definition").dialog('close');
2
+
3
+ - content = escape_javascript(render(@parameter_definition));
4
+ target_row = $("#parameter_#{@parameter_definition.id}");
5
+ target_row.replaceWith("#{content}");
6
+ $("#parameter_definition_#{@parameter_definition.id}").effect("highlight", {}, 3000);
@@ -0,0 +1,40 @@
1
+ :javascript
2
+ $(function() {
3
+ $( ".new_whurl_engine_resource, .edit_whurl_engine_resource" ).dialog(
4
+ {
5
+ modal: true,
6
+ autoOpen: false,
7
+ title: 'Manage Resources',
8
+ minWidth: 375,
9
+ minHeight: 300,
10
+ close: function(event, ui) {
11
+ $(this).remove();
12
+ }
13
+ });
14
+ });
15
+
16
+ = form_for @resource, :remote => true do |f|
17
+ = f.hidden_field :category_id
18
+ %div
19
+ = f.label :http_method
20
+ = f.select(:http_method, options_for_select(['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'], 'GET'))
21
+ %div
22
+ = f.label :base_uri
23
+ = f.text_field :base_uri, :placeholder => 'eg. https://api.twitter.com/1, https://api.groupon.com/v1, etc.'
24
+ %div
25
+ = f.label :relative_path
26
+ = f.text_field :relative_path, :placeholder => 'eg. statuses/home_timeline, users/:id/edit, etc.'
27
+ %div
28
+ = f.check_box :rate_limited
29
+ = f.label :rate_limited
30
+ %div
31
+ = f.check_box :requires_authentication
32
+ = f.label :requires_authentication
33
+ %div
34
+ = f.label :response_formats
35
+ = f.text_field :response_formats
36
+ %div
37
+ = f.label :description
38
+ %div
39
+ = f.text_area :description
40
+ = f.submit :value => 'Submit'