Skip to content

Commit

Permalink
Merge pull request #66 from jonatanklosko/file-extensions
Browse files Browse the repository at this point in the history
File extensions
  • Loading branch information
ddavison authored Oct 12, 2016
2 parents ddefd1d + 53dccdb commit 0c79079
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rest-client-view.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$, ScrollView} = require 'atom-space-pen-views'
{Emitter} = require 'atom'
querystring = require 'querystring'
mime = require 'mime-types'

RestClientResponse = require './rest-client-response'
RestClientEditor = require './rest-client-editor'
Expand Down Expand Up @@ -125,17 +126,18 @@ class RestClientView extends ScrollView
@a class: "#{rest_form.result_headers_link.split('.')[1]}", 'Headers'
@span ' | '
@span class: "#{rest_form.status.split('.')[1]}"
@span class: "text-info lnk #{rest_form.open_in_editor.split('.')[1]}", 'Open in separate editor'

@span class: "#{rest_form.loading.split('.')[1]} loading loading-spinner-small inline-block", style: 'display: none;'
@pre class: "#{rest_form.result_headers.split('.')[1]}", ""
@pre class: "#{rest_form.result.split('.')[1]}", "#{RestClientResponse.DEFAULT_RESPONSE}"
@div class: "text-info lnk #{rest_form.open_in_editor.split('.')[1]}", 'Open in separate editor'

initialize: ->
@COLLECTIONS_PATH = "#{PACKAGE_PATH}/collections.json"
@RECENT_REQUESTS_PATH = "#{PACKAGE_PATH}/recent.json"

@lastRequest = null
@lastResponse = null

@recentRequests = new RestClientPersist(@RECENT_REQUESTS_PATH)
@recentRequests.setRequestFileLimit(RECENT_REQUESTS_FILE_LIMIT)
Expand Down Expand Up @@ -194,10 +196,13 @@ class RestClientView extends ScrollView

openInEditor: ->
textResult = $(rest_form.result).text()
file_name = "#{current_method} - #{$(rest_form.url).val()}"
editor = new RestClientEditor(textResult, file_name)
editor = new RestClientEditor(textResult, @constructFileName())
editor.open()

constructFileName: ->
extension = mime.extension(@lastResponse.headers['content-type'])
"#{@lastRequest.method} #{@lastRequest.url}#{'.' + extension if extension}"

encodePayload: ->
$(rest_form.payload).val(
RestClientHttp.encodePayload($(rest_form.payload).val())
Expand Down Expand Up @@ -267,6 +272,7 @@ class RestClientView extends ScrollView
body: @getRequestBody()

onResponse: (error, response, body) =>
@setLastResponse(response)
if !error
statusMessage = response.statusCode + " " + response.statusMessage

Expand Down Expand Up @@ -386,6 +392,9 @@ class RestClientView extends ScrollView
setLastRequest: (request) =>
@lastRequest = request

setLastResponse: (response) =>
@lastResponse = response

getHeadersAsString: (headers) ->
output = ''

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"atom-space-pen-views": "^2.0.3",
"mime-types": "^2.1.12",
"request": "*"
}
}
6 changes: 6 additions & 0 deletions spec/rest-client-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ describe "RestClientView test", ->
describe "View", ->
it "the view is loaded", ->
expect(restClient.find('.rest-client-send')).toExist()

describe "constructFileName", ->
it "contains the url, the method and an extension inferred from the response content-type", ->
restClient.setLastRequest { url: "http://example.com", method: "GET" }
restClient.setLastResponse { headers: { "content-type": "application/json" } }
expect(restClient.constructFileName()).toEqual "GET http://example.com.json"
4 changes: 4 additions & 0 deletions styles/rest-client.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
float: right;
width: 50%;

.rest-client-open-in-editor {
float: right;
}

@media only screen and (min-width: 800px) {
padding-top: 0;
}
Expand Down

0 comments on commit 0c79079

Please sign in to comment.