whurl_engine 1.2.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.
Files changed (148) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +61 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/flash/whurl_engine/ZeroClipboard.swf +0 -0
  5. data/app/assets/flash/whurl_engine/ZeroClipboard10.swf +0 -0
  6. data/app/assets/flash/whurl_engine/clippy.swf +0 -0
  7. data/app/assets/images/whurl_engine/add.png +0 -0
  8. data/app/assets/images/whurl_engine/bg_new.png +0 -0
  9. data/app/assets/images/whurl_engine/clipboard.png +0 -0
  10. data/app/assets/images/whurl_engine/container_bg.png +0 -0
  11. data/app/assets/images/whurl_engine/container_bottom.png +0 -0
  12. data/app/assets/images/whurl_engine/container_top.png +0 -0
  13. data/app/assets/images/whurl_engine/copyURL.png +0 -0
  14. data/app/assets/images/whurl_engine/delete.png +0 -0
  15. data/app/assets/images/whurl_engine/devil_128x128.png +0 -0
  16. data/app/assets/images/whurl_engine/devil_16x16.png +0 -0
  17. data/app/assets/images/whurl_engine/devil_256x256.png +0 -0
  18. data/app/assets/images/whurl_engine/devil_32x32.png +0 -0
  19. data/app/assets/images/whurl_engine/devil_64x64.png +0 -0
  20. data/app/assets/images/whurl_engine/header_button.png +0 -0
  21. data/app/assets/images/whurl_engine/input_titles.png +0 -0
  22. data/app/assets/images/whurl_engine/logo.png +0 -0
  23. data/app/assets/images/whurl_engine/param_button.png +0 -0
  24. data/app/assets/images/whurl_engine/rails.png +0 -0
  25. data/app/assets/images/whurl_engine/send_button.jpg +0 -0
  26. data/app/assets/images/whurl_engine/splash.png +0 -0
  27. data/app/assets/javascripts/whurl_engine/ZeroClipboard.js +311 -0
  28. data/app/assets/javascripts/whurl_engine/application.js +159 -0
  29. data/app/assets/javascripts/whurl_engine/jquery-1.7.1.min.js +4 -0
  30. data/app/assets/javascripts/whurl_engine/jquery-ui-1.8.16.min.js +791 -0
  31. data/app/assets/stylesheets/whurl_engine/application.css.scss +7 -0
  32. data/app/assets/stylesheets/whurl_engine/code.css.scss +13 -0
  33. data/app/assets/stylesheets/whurl_engine/jquery.ui.autocomplete.css.scss +55 -0
  34. data/app/assets/stylesheets/whurl_engine/whurls.css.scss +358 -0
  35. data/app/controllers/whurl_engine/application_controller.rb +4 -0
  36. data/app/controllers/whurl_engine/whurl_requests_controller.rb +50 -0
  37. data/app/helpers/whurl_engine/application_helper.rb +32 -0
  38. data/app/models/whurl_engine/any_client.rb +7 -0
  39. data/app/models/whurl_engine/whurl_request.rb +37 -0
  40. data/app/views/layouts/whurl_engine/application.html.haml +56 -0
  41. data/app/views/whurl_engine/whurl_requests/_form.html.haml +51 -0
  42. data/app/views/whurl_engine/whurl_requests/_input_set.html.haml +4 -0
  43. data/app/views/whurl_engine/whurl_requests/edit.html.haml +29 -0
  44. data/app/views/whurl_engine/whurl_requests/new.html.haml +5 -0
  45. data/app/views/whurl_engine/whurl_requests/show.html.haml +1 -0
  46. data/config/initializers/httparty/response.rb +37 -0
  47. data/config/routes.rb +5 -0
  48. data/db/migrate/20110209054322_create_whurl_requests_table.rb +14 -0
  49. data/db/migrate/20111210192724_add_description_to_whurl_requests.rb +9 -0
  50. data/db/migrate/20111210201607_add_custom_url_to_whurl_requests.rb +9 -0
  51. data/db/migrate/20111220233800_create_fields_for_whurl_requests.rb +18 -0
  52. data/db/migrate/20111221010348_copy_data_to_new_fields.rb +39 -0
  53. data/db/migrate/20111221011145_drop_data_from_whurl_requestss.rb +9 -0
  54. data/lib/tasks/whurl_engine_tasks.rake +4 -0
  55. data/lib/whurl_engine.rb +5 -0
  56. data/lib/whurl_engine/engine.rb +5 -0
  57. data/lib/whurl_engine/version.rb +3 -0
  58. data/test/dummy/Rakefile +7 -0
  59. data/test/dummy/app/assets/javascripts/application.js +9 -0
  60. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  61. data/test/dummy/app/controllers/application_controller.rb +3 -0
  62. data/test/dummy/app/helpers/application_helper.rb +2 -0
  63. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  64. data/test/dummy/app/views/layouts/whurl_engine/application.html.haml +56 -0
  65. data/test/dummy/config.ru +4 -0
  66. data/test/dummy/config/application.rb +45 -0
  67. data/test/dummy/config/boot.rb +10 -0
  68. data/test/dummy/config/database.sample.yml +17 -0
  69. data/test/dummy/config/database.yml +17 -0
  70. data/test/dummy/config/environment.rb +5 -0
  71. data/test/dummy/config/environments/development.rb +30 -0
  72. data/test/dummy/config/environments/production.rb +60 -0
  73. data/test/dummy/config/environments/test.rb +39 -0
  74. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/test/dummy/config/initializers/inflections.rb +10 -0
  76. data/test/dummy/config/initializers/mime_types.rb +5 -0
  77. data/test/dummy/config/initializers/secret_token.rb +7 -0
  78. data/test/dummy/config/initializers/session_store.rb +8 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/test/dummy/config/locales/en.yml +5 -0
  81. data/test/dummy/config/routes.rb +4 -0
  82. data/test/dummy/db/schema.rb +31 -0
  83. data/test/dummy/log/development.log +5633 -0
  84. data/test/dummy/public/404.html +26 -0
  85. data/test/dummy/public/422.html +26 -0
  86. data/test/dummy/public/500.html +26 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/dummy/script/rails +6 -0
  89. data/test/dummy/tmp/cache/assets/C1B/810/sprockets%2Ff86f239423289738079ca3c0620b0203 +0 -0
  90. data/test/dummy/tmp/cache/assets/C3A/230/sprockets%2F86b30811052f3f9107867785fe676b98 +0 -0
  91. data/test/dummy/tmp/cache/assets/C3C/1E0/sprockets%2F8930cb230c644524697589c895d58c58 +0 -0
  92. data/test/dummy/tmp/cache/assets/C6D/500/sprockets%2Fa60a126c749b135b047d47c9116f7010 +0 -0
  93. data/test/dummy/tmp/cache/assets/C6E/690/sprockets%2F541821c1465d0b184df51e0a086c2617 +0 -0
  94. data/test/dummy/tmp/cache/assets/C71/B70/sprockets%2F2608911ae1a9d40c31128bea84417087 +0 -0
  95. data/test/dummy/tmp/cache/assets/C85/760/sprockets%2F67d86b8948de011684953a4b2d30c280 +0 -0
  96. data/test/dummy/tmp/cache/assets/CA5/D90/sprockets%2F718b681081f0c3ab0096b20afc567359 +0 -0
  97. data/test/dummy/tmp/cache/assets/CB8/FF0/sprockets%2F789d641670bfe15510034f63eb635ff8 +0 -0
  98. data/test/dummy/tmp/cache/assets/CB9/340/sprockets%2Fc383855f31a6f96cfad737d462029019 +0 -0
  99. data/test/dummy/tmp/cache/assets/CBD/A60/sprockets%2F8e7fec8543052565b343a93c7b174d78 +0 -0
  100. data/test/dummy/tmp/cache/assets/CE6/140/sprockets%2F97da5e07430aa9249a9633e88c5073ea +0 -0
  101. data/test/dummy/tmp/cache/assets/CE8/710/sprockets%2F0578ecd79cad102753e7972f371ea580 +0 -0
  102. data/test/dummy/tmp/cache/assets/D01/6E0/sprockets%2F3974f4fd239fc76f2d9700899609da7e +0 -0
  103. data/test/dummy/tmp/cache/assets/D09/700/sprockets%2F68ca75710cc64126df7d1a6638ca16d1 +0 -0
  104. data/test/dummy/tmp/cache/assets/D18/6A0/sprockets%2Fdf8266a6da92a42ce29b771318176dc9 +0 -0
  105. data/test/dummy/tmp/cache/assets/D1C/440/sprockets%2Fd5f5cd99df7e614581ec5f2256403e33 +0 -0
  106. data/test/dummy/tmp/cache/assets/D20/140/sprockets%2F5014845cec156ff8444609f3f9dc84ce +0 -0
  107. data/test/dummy/tmp/cache/assets/D20/DF0/sprockets%2Fb3f333b87e8897356bf2e2e9138bb4d5 +0 -0
  108. data/test/dummy/tmp/cache/assets/D2C/DB0/sprockets%2F802a914bb4d275c8c34a3aa5ec134d54 +0 -0
  109. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  110. data/test/dummy/tmp/cache/assets/D37/320/sprockets%2F1c5dd3b8b6b30a68c19225a0915d8c6f +0 -0
  111. data/test/dummy/tmp/cache/assets/D39/780/sprockets%2F0da3fdc5af08e2938cc21829334b1d48 +0 -0
  112. data/test/dummy/tmp/cache/assets/D3D/010/sprockets%2F389924c72fa75b369a0e61aacfa230e8 +0 -0
  113. data/test/dummy/tmp/cache/assets/D47/370/sprockets%2Fdab9545772e7beac9914f404d45c462e +0 -0
  114. data/test/dummy/tmp/cache/assets/D47/570/sprockets%2F78c33a7e0fcca296909068fb8173cc1f +0 -0
  115. data/test/dummy/tmp/cache/assets/D4C/8D0/sprockets%2F024e6456c9877ae45cdb28d7d16e06fe +0 -0
  116. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  117. data/test/dummy/tmp/cache/assets/D59/1C0/sprockets%2Fdd4546ee9edb36c3647329828e791dfd +0 -0
  118. data/test/dummy/tmp/cache/assets/D66/D70/sprockets%2Ffdf1533f584b1ba62ce0ca92848b14d3 +0 -0
  119. data/test/dummy/tmp/cache/assets/D6F/A10/sprockets%2F3fa8ede522a279bfc12817267d1ca57e +0 -0
  120. data/test/dummy/tmp/cache/assets/D7A/860/sprockets%2F1ee925188e47da5e45dcedfd81f71441 +0 -0
  121. data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  122. data/test/dummy/tmp/cache/assets/D89/CF0/sprockets%2Fb85f0f6129d17ceff85999cf571f3f1b +0 -0
  123. data/test/dummy/tmp/cache/assets/D90/E50/sprockets%2Fec69848c01c4dd45c809da4f0bb0a11c +0 -0
  124. data/test/dummy/tmp/cache/assets/D92/D80/sprockets%2Fada8029522185c3ca0656cf64bccb3fe +0 -0
  125. data/test/dummy/tmp/cache/assets/D9D/AC0/sprockets%2F082b6d491d42f3a4febe3cb4d0983e6d +0 -0
  126. data/test/dummy/tmp/cache/assets/DA4/180/sprockets%2F118a85fd98ac4bda49f6485fd41aca44 +0 -0
  127. data/test/dummy/tmp/cache/assets/DB4/C60/sprockets%2F6ee1d0983f6518ba5dc089797bfc6ffa +0 -0
  128. data/test/dummy/tmp/cache/assets/DBD/7A0/sprockets%2F872f84e976ebe7654383dfdc7cfec1c6 +0 -0
  129. data/test/dummy/tmp/cache/assets/DBF/440/sprockets%2F88adba908c22af8b331e4d1a7b5ad07b +0 -0
  130. data/test/dummy/tmp/cache/assets/DD7/420/sprockets%2F11c951f1c4e2bfc0d7c1b10e0bb1b2be +0 -0
  131. data/test/dummy/tmp/cache/assets/DD9/530/sprockets%2Fca5bb0d6ddfeec8760903809a7c9bb98 +0 -0
  132. data/test/dummy/tmp/cache/assets/DE2/AA0/sprockets%2Fd355cc1e9a71d9e9ae68a8a4e48d9ae6 +0 -0
  133. data/test/dummy/tmp/cache/assets/DED/EF0/sprockets%2Fba8239fd72bb07104cbbac6a91cd70ef +0 -0
  134. data/test/dummy/tmp/cache/assets/DF6/6E0/sprockets%2Fe6bd0ba980148fb1e6621e7fdda61afb +0 -0
  135. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  136. data/test/dummy/tmp/cache/assets/E29/F00/sprockets%2F5b6ee8619eacc15eaf00c329cedff60a +0 -0
  137. data/test/dummy/tmp/cache/assets/E2E/590/sprockets%2Fe4c10fd74fddddb456cc924c38ddc26c +0 -0
  138. data/test/dummy/tmp/cache/assets/E56/EE0/sprockets%2Fb7fe1dd66e801cfbf780cb27aeece10a +0 -0
  139. data/test/dummy/tmp/cache/assets/E5D/680/sprockets%2F5ef33ecefc8e09aafd4d2725c0ef0a9c +0 -0
  140. data/test/dummy/tmp/pids/server.pid +1 -0
  141. data/test/fixtures/whurl_engine/whurl_requests.yml +11 -0
  142. data/test/functional/whurl_engine/api_call_controller_test.rb +21 -0
  143. data/test/integration/navigation_test.rb +10 -0
  144. data/test/test_helper.rb +10 -0
  145. data/test/unit/helpers/whurl_engine/api_call_helper_test.rb +6 -0
  146. data/test/unit/whurl_engine/whurl_request_test.rb +9 -0
  147. data/test/whurl_engine_test.rb +7 -0
  148. metadata +394 -0
@@ -0,0 +1,32 @@
1
+ module WhurlEngine
2
+ module ApplicationHelper
3
+ def clippy(text, bgcolor='#FFFFFF')
4
+ swf_path = asset_path('whurl_engine/clippy.swf')
5
+ html = <<-EOF
6
+ <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
7
+ width="16"
8
+ height="16"
9
+ id="clippy" >
10
+ <param name="movie" value="#{swf_path}"/>
11
+ <param name="allowScriptAccess" value="always" />
12
+ <param name="quality" value="high" />
13
+ <param name="scale" value="noscale" />
14
+ <param NAME="FlashVars" value="text=#{text}">
15
+ <param name="bgcolor" value="#{bgcolor}">
16
+ <embed src="#{swf_path}"
17
+ width="16"
18
+ height="16"
19
+ name="clippy"
20
+ quality="high"
21
+ allowScriptAccess="always"
22
+ type="application/x-shockwave-flash"
23
+ pluginspage="http://www.macromedia.com/go/getflashplayer"
24
+ FlashVars="text=#{text}"
25
+ bgcolor="#{bgcolor}"
26
+ />
27
+ </object>
28
+ EOF
29
+ html.html_safe
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'httmultiparty'
2
+
3
+ module WhurlEngine
4
+ class AnyClient
5
+ include HTTMultiParty
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ module WhurlEngine
2
+ class WhurlRequest < ActiveRecord::Base
3
+ serialize :data
4
+ serialize :query, Hash
5
+ serialize :headers, Hash
6
+
7
+ after_initialize {
8
+ default_values
9
+ generate_hash_key if new_record?
10
+ }
11
+
12
+ validates_uniqueness_of :custom_url, :if => Proc.new { |model| !model.custom_url.blank? }
13
+ validates_format_of :custom_url, :allow_blank => true, :allow_nil => true, :with => /^[\w\-]+$/i, :message => "can only contain letters, numbers, hyphens and underscores."
14
+
15
+ scope :saved, where("custom_url IS NOT NULL AND custom_url <> ''").order(:custom_url)
16
+
17
+ def slug
18
+ hash_key || custom_url
19
+ end
20
+
21
+ private
22
+ def default_values
23
+ self.query ||= {}
24
+ self.headers ||= {}
25
+ end
26
+
27
+ def generate_hash_key
28
+ upper_bound = 36**6 -1 #max 6 characters
29
+ new_hash_key = rand(upper_bound).to_s(36)
30
+ if new_hash_key.match(/^whurl/)
31
+ generate_hash_key
32
+ else
33
+ self.hash_key = new_hash_key
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ = stylesheet_link_tag("whurl_engine/application")
5
+ = javascript_include_tag("whurl_engine/jquery-1.7.1.min")
6
+ = javascript_include_tag("whurl_engine/jquery-ui-1.8.16.min")
7
+ = javascript_include_tag("whurl_engine/application")
8
+ = javascript_include_tag("whurl_engine/ZeroClipboard")
9
+ :javascript
10
+ $(document).ready(function() {
11
+ ZeroClipboard.setMoviePath('#{asset_path('whurl_engine/ZeroClipboard10.swf')}');
12
+ });
13
+
14
+ %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))
@@ -0,0 +1,51 @@
1
+ - if @whurl.errors.any?
2
+ %ul#errors
3
+ - @whurl.errors.full_messages.each do |msg|
4
+ %li= msg
5
+ .top
6
+ = form_for(@whurl, :method => :post, :url => {:action => :create}) do |f|
7
+ .row
8
+ .section_title
9
+ %span.hTitle URL
10
+ = f.select(:http_method, options_for_select(["GET", "POST", "PUT", "DELETE"], @whurl.http_method))
11
+ \/
12
+ \#{f.text_field(:url, :class => "long")}
13
+ .row
14
+ .section_title
15
+ .hTitle
16
+ %a#trashheaders= image_tag('whurl_engine/delete.png', :class => 'action_button', :title => "trash all headers")
17
+ %a#add_header= image_tag('whurl_engine/add.png', :class => 'action_button', :title => "add another header")
18
+ Headers
19
+ #headers
20
+ = render :partial => 'input_set', :locals => {:set_name => 'header', :f => f, :key => nil, :value => nil, :disabled => true}
21
+ - @whurl.headers.each do |key, value|
22
+ = render :partial => 'input_set', :locals => {:set_name => 'header', :f => f, :key => key, :value => value, :disabled => false}
23
+ = render :partial => 'input_set', :locals => {:set_name => 'header', :f => f, :key => nil, :value => nil, :disabled => false}
24
+ .row
25
+ .section_title
26
+ .hTitle
27
+ %a#trashqueries= image_tag('whurl_engine/delete.png', :class => 'action_button', :title => "trash all parameters")
28
+ %a#add_param= image_tag('whurl_engine/add.png', :class => 'action_button', :title => "add another parameter")
29
+ Query
30
+ #params
31
+ = render :partial => 'input_set', :locals => {:set_name => 'param', :f => f, :key => nil, :value => nil, :disabled => true}
32
+ - @whurl.query.each do |key, value|
33
+ = render :partial => 'input_set', :locals => {:set_name => 'param', :f => f, :key => key, :value => value, :disabled => false}
34
+ = render :partial => 'input_set', :locals => {:set_name => 'param', :f => f, :key => nil, :value => nil, :disabled => false}
35
+ .row
36
+ .section_title
37
+ .hTitle Body
38
+ #post_body
39
+ = f.text_area(:body)
40
+ .row
41
+ .section_title
42
+ %span.hTitle Description (optional)
43
+ #post_description
44
+ = f.text_area(:description)
45
+ .row
46
+ .section_title
47
+ %span.hTitle Custom URL (optional)
48
+ #custom_url
49
+ = f.text_field(:custom_url, :value => nil)
50
+ %input.submit{:type => "submit", :value => "Give it a Whurl!"}/
51
+ %input#clearFields.reset{:type => "button", :value => "Reset"}/
@@ -0,0 +1,4 @@
1
+ %div{:class => "#{set_name}_pair"}
2
+ = text_field_tag("#{set_name}_keys[]", key, :class => "key", :disabled => disabled)
3
+ = text_field_tag("#{set_name}_values[]", value, :class => "value", :disabled => disabled)
4
+ %a{:class => "delete_#{set_name}"}= image_tag("whurl_engine/delete.png", :class => 'delete_button')
@@ -0,0 +1,29 @@
1
+ = javascript_include_tag("whurl_engine/ZeroClipboard")
2
+
3
+ - unless @description.blank?
4
+ .response_section
5
+ .response_section_title Description
6
+ #edit_description
7
+ = @description
8
+ .response_section
9
+ .response_section_title Response Headers
10
+ #response_header
11
+ = find_and_preserve(@response_headers)
12
+ .response_section
13
+ .response_section_title
14
+ Response Body #{image_tag("whurl_engine/clipboard.png", :id => "copy_to_clipboard")}
15
+ .response_container
16
+ = find_and_preserve(@api_response)#.force_encoding(WhurlEngine::Application.config.encoding))
17
+ = render :partial => 'form'
18
+ #permalink_container
19
+ Share this Whurl:
20
+ %input#permalink_text_box{:type => "text", :value => request.url, :readonly => true}
21
+ =clippy(request.url, "#F7E391")
22
+ :javascript
23
+ $(function() {
24
+ ZeroClipboard.setMoviePath('#{asset_path('whurl_engine/ZeroClipboard10.swf')}' );
25
+ var clip = new ZeroClipboard.Client();
26
+ clip.setHandCursor(true);
27
+ clip.setText($('.CodeRay td.code').text());
28
+ clip.glue('copy_to_clipboard');
29
+ });
@@ -0,0 +1,5 @@
1
+ = render :partial => 'form'
2
+ :javascript
3
+ $(document).ready(function() {
4
+ $('#url').focus();
5
+ });
@@ -0,0 +1 @@
1
+ = @api_response
@@ -0,0 +1,37 @@
1
+ require 'json'
2
+ require 'coderay'
3
+ require 'httparty'
4
+
5
+ module HTTParty
6
+ class Response < HTTParty::BasicObject
7
+ class Headers
8
+ def to_s
9
+ headers = []
10
+ each_capitalized do |name, value|
11
+ headers << "#{name}: #{value}"
12
+ end
13
+ headers.join("\n")
14
+ end
15
+
16
+ def to_html(options = {:line_numbers => nil})
17
+ ::CodeRay.scan(to_s, :txt).div(options)
18
+ end
19
+ end
20
+
21
+ def to_html(options = {:line_numbers => :table})
22
+ return "<pre>(Empty)</pre>" unless body.present?
23
+ case content_type
24
+ when /xml/
25
+ ::CodeRay.scan(body, :xml).div(options)
26
+ when /html/
27
+ ::CodeRay.scan(body, :html).div(options)
28
+ when /json|javascript/
29
+ ::CodeRay.scan(::JSON.pretty_generate(::JSON.parse(body)), :json).div(options)
30
+ when /image|jpg|jpeg|gif|png|bmp|binary/
31
+ "<img src=\"data:binary/octet;base64,#{Base64.encode64(response.body)}\" />"
32
+ else
33
+ body
34
+ end
35
+ end
36
+ end
37
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ WhurlEngine::Engine.routes.draw do
2
+ root :to => 'whurl_requests#new'
3
+ resources :whurl_requests
4
+ match '/:slug' => 'whurl_requests#edit', :as => :short
5
+ end
@@ -0,0 +1,14 @@
1
+ class CreateWhurlRequestsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :whurl_engine_whurl_requests do |t|
4
+ t.string :hash_key, :limit => 6, :null => false
5
+ t.text :data
6
+ t.timestamps
7
+ end
8
+ add_index :whurl_engine_whurl_requests, :hash_key, :unique => true
9
+ end
10
+
11
+ def self.down
12
+ drop_table :whurl_engine_whurl_requests
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class AddDescriptionToWhurlRequests < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :whurl_engine_whurl_requests, :description, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :whurl_engine_whurl_requests, :description
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddCustomUrlToWhurlRequests < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :whurl_engine_whurl_requests, :custom_url, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :whurl_engine_whurl_requests, :custom_url
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ class CreateFieldsForWhurlRequests < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :whurl_engine_whurl_requests, :http_method, :string, :limit => 10
4
+ add_column :whurl_engine_whurl_requests, :body, :text
5
+ add_column :whurl_engine_whurl_requests, :query, :text
6
+ add_column :whurl_engine_whurl_requests, :headers, :text
7
+ add_column :whurl_engine_whurl_requests, :url, :text
8
+
9
+ end
10
+
11
+ def self.down
12
+ remove_column :whurl_engine_whurl_requests, :http_method
13
+ remove_column :whurl_engine_whurl_requests, :body
14
+ remove_column :whurl_engine_whurl_requests, :query
15
+ remove_column :whurl_engine_whurl_requests, :headers
16
+ remove_column :whurl_engine_whurl_requests, :url
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ class CopyDataToNewFields < ActiveRecord::Migration
2
+ def self.up
3
+ WhurlEngine::WhurlRequest.all.each do |whurl|
4
+ return if whurl.data.nil?
5
+ whurl.http_method = whurl.data[:http_method]
6
+ whurl.query = whurl.data[:query]
7
+ whurl.url = whurl.data[:url]
8
+ whurl.body = whurl.data[:body]
9
+ whurl.headers = whurl.data[:headers]
10
+ unless whurl.save
11
+ puts "-" * 100
12
+ p whurl.id
13
+ pp whurl.errors
14
+ puts "-" * 100
15
+ else
16
+ p "Updated #{whurl.id}"
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ WhurlEngine::WhurlRequest.all.each do |whurl|
23
+ whurl.data ||= {}
24
+ whurl.data[:http_method] = whurl.http_method
25
+ whurl.data[:query] = whurl.query
26
+ whurl.data[:url] = whurl.url
27
+ whurl.data[:body] = whurl.body
28
+ whurl.data[:headers] = whurl.headers
29
+ unless whurl.save
30
+ puts "-" * 100
31
+ p whurl.id
32
+ pp whurl.errors
33
+ puts "-" * 100
34
+ else
35
+ p "Updated #{whurl.id}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ class DropDataFromWhurlRequestss < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :whurl_engine_whurl_requests, :data
4
+ end
5
+
6
+ def self.down
7
+ add_column :whurl_engine_whurl_requests, :data, :text
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :whurl_engine do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ require 'whurl_engine/engine'
2
+ require 'haml'
3
+
4
+ module WhurlEngine
5
+ end
@@ -0,0 +1,5 @@
1
+ module WhurlEngine
2
+ class Engine < Rails::Engine
3
+ isolate_namespace WhurlEngine
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module WhurlEngine
2
+ VERSION = "1.2.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */