Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File extensions #66

Merged
merged 3 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Copy link
Contributor

@javaguirre javaguirre Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of unreadable, could you rewrite it in a way It's easier to read? Thank you! :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I think It's fine this way 👍


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