Move atom.inbox => {NylasAPI} = require 'nylas-exports'

Conflicts:
	spec-nylas/tasks/file-upload-task-spec.coffee
This commit is contained in:
Ben Gotow 2015-05-14 17:34:29 -07:00
parent 91edef9f7a
commit 29c3e2993b
19 changed files with 66 additions and 54 deletions

View file

@ -26,6 +26,7 @@ Exports =
Actions: require '../src/flux/actions'
# API Endpoints
NylasAPI: require '../src/flux/inbox-api'
EdgehillAPI: require '../src/flux/edgehill-api'
# Testing

View file

@ -7,6 +7,7 @@ _ = require 'underscore-plus'
Tag,
Message,
FocusedTagStore,
NylasAPI,
Thread} = require 'nylas-exports'
AccountSidebarStore = Reflux.createStore
@ -107,7 +108,7 @@ AccountSidebarStore = Reflux.createStore
_refetchFromAPI: ->
namespace = NamespaceStore.current()
return unless namespace
atom.inbox.getCollection(namespace.id, 'tags')
NylasAPI.getCollection(namespace.id, 'tags')
# Inbound Events

View file

@ -1,6 +1,11 @@
Reflux = require 'reflux'
_ = require 'underscore-plus'
{DatabaseStore, NamespaceStore, Actions, Event, Calendar} = require 'nylas-exports'
{DatabaseStore,
NamespaceStore,
Actions,
Event,
Calendar,
NylasAPI} = require 'nylas-exports'
moment = require 'moment'
CalendarBarEventStore = Reflux.createStore
@ -50,7 +55,7 @@ CalendarBarEventStore = Reflux.createStore
oneDayAgo = Math.round(moment({hour: 0, milliseconds: -1}).valueOf() / 1000.0)
DatabaseStore.findAll(Calendar, namespaceId: namespace.id).then (calendars) ->
calendars.forEach (calendar) ->
atom.inbox.getCollection(namespace.id, 'events', {calendar_id: calendar.id, ends_after: oneDayAgo})
NylasAPI.getCollection(namespace.id, 'events', {calendar_id: calendar.id, ends_after: oneDayAgo})
# Inbound Events

View file

@ -6,6 +6,7 @@ MessageParticipants = require "./message-participants"
MessageTimestamp = require "./message-timestamp"
{Utils,
Actions,
NylasAPI,
MessageUtils,
ComponentRegistry,
FileDownloadStore} = require 'nylas-exports'
@ -194,7 +195,7 @@ class MessageItem extends React.Component
app = remote.require('app')
tmpfile = path.join(app.getPath('temp'), @props.message.id)
atom.inbox.makeRequest
NylasAPI.makeRequest
headers:
Accept: 'message/rfc822'
path: "/n/#{@props.message.namespaceId}/messages/#{@props.message.id}"

View file

@ -1,4 +1,5 @@
Actions = require '../../src/flux/actions'
NylasAPI = require '../../src/flux/inbox-api'
AddRemoveTagsTask = require '../../src/flux/tasks/add-remove-tags'
DatabaseStore = require '../../src/flux/stores/database-store'
Thread = require '../../src/flux/models/thread'
@ -116,21 +117,21 @@ describe "AddRemoveTagsTask", ->
@task = new AddRemoveTagsTask(testThread, ['archive'], ['inbox'])
it "should start an API request with the Draft JSON", ->
spyOn(atom.inbox, 'makeRequest')
spyOn(NylasAPI, 'makeRequest')
@task.performLocal()
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@task.performRemote()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/#{testThread.namespaceId}/threads/#{testThread.id}")
expect(options.method).toBe('PUT')
expect(options.body.add_tags[0]).toBe('archive')
expect(options.body.remove_tags[0]).toBe('inbox')
it "should pass returnsModel:true so that the draft is saved to the data store when returned", ->
spyOn(atom.inbox, 'makeRequest')
spyOn(NylasAPI, 'makeRequest')
@task.performLocal()
@task.performRemote()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.returnsModel).toBe(true)

View file

@ -1,5 +1,6 @@
proxyquire = require 'proxyquire'
_ = require 'underscore-plus'
NylasAPI = require '../../src/flux/inbox-api'
File = require '../../src/flux/models/file'
Message = require '../../src/flux/models/message'
Actions = require '../../src/flux/actions'
@ -73,7 +74,7 @@ describe "FileUploadTask", ->
beforeEach ->
spyOn(Actions, "uploadStateChanged")
@req = jasmine.createSpyObj('req', ['abort'])
spyOn(atom.inbox, 'makeRequest').andCallFake (reqParams) =>
spyOn(NylasAPI, 'makeRequest').andCallFake (reqParams) =>
reqParams.success(testResponse) if reqParams.success
return @req
@ -85,7 +86,7 @@ describe "FileUploadTask", ->
it "should start an API request", ->
waitsForPromise => @task.performRemote().then ->
options = atom.inbox.makeRequest.mostRecentCall.args[0]
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/nsid/files")
expect(options.method).toBe('POST')
expect(options.formData.file.value).toBe("Read Stream")
@ -131,7 +132,7 @@ describe "FileUploadTask", ->
it "should not do anything if the request has finished", ->
req = jasmine.createSpyObj('req', ['abort'])
reqSuccess = null
spyOn(atom.inbox, 'makeRequest').andCallFake (reqParams) ->
spyOn(NylasAPI, 'makeRequest').andCallFake (reqParams) ->
reqSuccess = reqParams.success
req
@ -142,7 +143,7 @@ describe "FileUploadTask", ->
it "should cancel the request if it's in flight", ->
req = jasmine.createSpyObj('req', ['abort'])
spyOn(atom.inbox, 'makeRequest').andCallFake (reqParams) -> req
spyOn(NylasAPI, 'makeRequest').andCallFake (reqParams) -> req
spyOn(Actions, "uploadStateChanged")
@task.performRemote()
@ -153,5 +154,3 @@ describe "FileUploadTask", ->
state: "aborted"
bytesUploaded: 0
expect(Actions.uploadStateChanged).toHaveBeenCalledWith(data)

View file

@ -1,3 +1,4 @@
NylasAPI = require '../../src/flux/inbox-api'
Actions = require '../../src/flux/actions'
MarkMessageReadTask = require '../../src/flux/tasks/mark-message-read'
DatabaseStore = require '../../src/flux/stores/database-store'
@ -56,10 +57,9 @@ describe "MarkMessageReadTask", ->
describe "performRemote", ->
it "should make the PUT request to the message endpoint", ->
spyOn(atom.inbox, 'makeRequest')
spyOn(NylasAPI, 'makeRequest')
@task.performRemote()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/#{@message.namespaceId}/messages/#{@message.id}")
expect(options.method).toBe('PUT')
expect(options.body.unread).toBe(false)

View file

@ -1,3 +1,4 @@
NylasAPI = require '../../src/flux/inbox-api'
Actions = require '../../src/flux/actions'
SyncbackDraftTask = require '../../src/flux/tasks/syncback-draft'
SendDraftTask = require '../../src/flux/tasks/send-draft'
@ -111,7 +112,7 @@ describe "SendDraftTask", ->
email: 'dummy@nylas.com'
@draftLocalId = "local-123"
@task = new SendDraftTask(@draftLocalId)
spyOn(atom.inbox, 'makeRequest').andCallFake (options) =>
spyOn(NylasAPI, 'makeRequest').andCallFake (options) =>
options.success(@draft.toJSON()) if options.success
spyOn(DatabaseStore, 'findByLocalId').andCallFake (klass, localId) =>
Promise.resolve(@draft)
@ -146,8 +147,8 @@ describe "SendDraftTask", ->
it "should start an API request to /send", ->
waitsForPromise =>
@task.performRemote().then =>
expect(atom.inbox.makeRequest.calls.length).toBe(1)
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest.calls.length).toBe(1)
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/#{@draft.namespaceId}/send")
expect(options.method).toBe('POST')
@ -155,8 +156,8 @@ describe "SendDraftTask", ->
it "should send the draft ID and version", ->
waitsForPromise =>
@task.performRemote().then =>
expect(atom.inbox.makeRequest.calls.length).toBe(1)
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest.calls.length).toBe(1)
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.body.version).toBe(@draft.version)
expect(options.body.draft_id).toBe(@draft.id)
@ -176,15 +177,15 @@ describe "SendDraftTask", ->
it "should send the draft JSON", ->
waitsForPromise =>
@task.performRemote().then =>
expect(atom.inbox.makeRequest.calls.length).toBe(1)
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest.calls.length).toBe(1)
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.body).toEqual(@draft.toJSON(joined: true))
it "should pass returnsModel:true so that the draft is saved to the data store when returned", ->
waitsForPromise =>
@task.performRemote().then ->
expect(atom.inbox.makeRequest.calls.length).toBe(1)
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest.calls.length).toBe(1)
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.returnsModel).toBe(true)
describe "failing performRemote", ->

View file

@ -1,6 +1,7 @@
_ = require 'underscore-plus'
{generateTempId, isTempId} = require '../../src/flux/models/utils'
NylasAPI = require '../../src/flux/inbox-api'
Task = require '../../src/flux/tasks/task'
Actions = require '../../src/flux/actions'
Message = require '../../src/flux/models/message'
@ -48,29 +49,29 @@ describe "SyncbackDraftTask", ->
describe "performRemote", ->
beforeEach ->
spyOn(atom.inbox, 'makeRequest').andCallFake (opts) ->
spyOn(NylasAPI, 'makeRequest').andCallFake (opts) ->
opts.success(remoteDraft.toJSON()) if opts.success
it "does nothing if no draft can be found in the db", ->
task = new SyncbackDraftTask("missingDraftId")
waitsForPromise =>
task.performRemote().then ->
expect(atom.inbox.makeRequest).not.toHaveBeenCalled()
expect(NylasAPI.makeRequest).not.toHaveBeenCalled()
it "should start an API request with the Message JSON", ->
task = new SyncbackDraftTask("localDraftId")
waitsForPromise =>
task.performRemote().then ->
expect(atom.inbox.makeRequest).toHaveBeenCalled()
reqBody = atom.inbox.makeRequest.mostRecentCall.args[0].body
expect(NylasAPI.makeRequest).toHaveBeenCalled()
reqBody = NylasAPI.makeRequest.mostRecentCall.args[0].body
expect(reqBody.subject).toEqual testData.subject
it "should do a PUT when the draft has already been saved", ->
task = new SyncbackDraftTask("remoteDraftId")
waitsForPromise =>
task.performRemote().then ->
expect(atom.inbox.makeRequest).toHaveBeenCalled()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest).toHaveBeenCalled()
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/abc123/drafts/remoteid1234")
expect(options.method).toBe('PUT')
@ -78,8 +79,8 @@ describe "SyncbackDraftTask", ->
task = new SyncbackDraftTask("localDraftId")
waitsForPromise =>
task.performRemote().then ->
expect(atom.inbox.makeRequest).toHaveBeenCalled()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest).toHaveBeenCalled()
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/n/abc123/drafts")
expect(options.method).toBe('POST')
@ -87,8 +88,8 @@ describe "SyncbackDraftTask", ->
task = new SyncbackDraftTask("localDraftId")
waitsForPromise =>
task.performRemote().then ->
expect(atom.inbox.makeRequest).toHaveBeenCalled()
options = atom.inbox.makeRequest.mostRecentCall.args[0]
expect(NylasAPI.makeRequest).toHaveBeenCalled()
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.returnsModel).toBe(false)
it "should swap the ids if we got a new one from the DB", ->
@ -108,7 +109,7 @@ describe "SyncbackDraftTask", ->
describe "When the api throws a 404 error", ->
beforeEach ->
spyOn(TaskQueue, "enqueue")
spyOn(atom.inbox, "makeRequest").andCallFake (opts) ->
spyOn(NylasAPI, "makeRequest").andCallFake (opts) ->
opts.error(testError(opts)) if opts.error
it "resets the id", ->

View file

@ -169,7 +169,6 @@ class Atom extends Model
ThemeManager = require './theme-manager'
StyleManager = require './style-manager'
ActionBridge = require './flux/action-bridge'
InboxAPI = require './flux/inbox-api'
MenuManager = require './menu-manager'
{devMode, safeMode, resourcePath} = @getLoadSettings()
configDirPath = @getConfigDirPath()
@ -209,9 +208,6 @@ class Atom extends Model
@menu = new MenuManager({resourcePath})
@clipboard = new Clipboard()
# Edgehill-specific
@inbox = new InboxAPI()
# initialize spell checking
require('web-frame').setSpellCheckProvider("en-US", false, {
spellCheck: (text) ->
@ -619,7 +615,6 @@ class Atom extends Model
windowPackages} = @getLoadSettings()
@loadConfig()
@inbox.APIToken = atom.config.get('inbox.token')
@keymaps.loadBundledKeymaps()
@themes.loadBaseStylesheets()

View file

@ -248,4 +248,4 @@ class InboxAPI
qs: params
returnsModel: true
module.exports = InboxAPI
module.exports = new InboxAPI()

View file

@ -9,6 +9,7 @@ _ = require 'underscore-plus'
Actions = require '../actions'
progress = require 'request-progress'
NamespaceStore = require '../stores/namespace-store'
NylasAPI = require '../inbox-api'
class Download
constructor: ({@fileId, @targetPath, @progressCallback}) ->
@ -39,7 +40,7 @@ class Download
# Does the file already exist on disk? If so, just resolve immediately.
fs.exists @targetPath, (exists) =>
return resolve(@) if exists
@request = atom.inbox.makeRequest
@request = NylasAPI.makeRequest
path: "/n/#{namespace}/files/#{@fileId}/download"
success: => resolve(@)
error: => reject(@)
@ -101,7 +102,7 @@ FileDownloadStore = Reflux.createStore
fileId: file.id
targetPath: targetPath
progressCallback: => @trigger()
cleanup = =>
@_cleanupDownload(download)
Promise.resolve(download)

View file

@ -6,6 +6,7 @@ DatabaseStore = require "./database-store"
NamespaceStore = require "./namespace-store"
FocusedContentStore = require "./focused-content-store"
MarkThreadReadTask = require '../tasks/mark-thread-read'
NylasAPI = require '../inbox-api'
async = require 'async'
_ = require 'underscore-plus'
@ -121,7 +122,7 @@ MessageStore = Reflux.createStore
# are returned, this will trigger a refresh here.
if @_items.length is 0
namespace = NamespaceStore.current()
atom.inbox.getCollection namespace.id, 'messages', {thread_id: @_thread.id}
NylasAPI.getCollection namespace.id, 'messages', {thread_id: @_thread.id}
loaded = false
@_expandItemsToDefault()
@ -160,7 +161,7 @@ MessageStore = Reflux.createStore
@_inflight[id] = true
namespace = NamespaceStore.current()
atom.inbox.makeRequest
NylasAPI.makeRequest
path: "/n/#{namespace.id}/messages/#{id}"
returnsModel: true
success: =>

View file

@ -2,6 +2,7 @@ _ = require 'underscore-plus'
Utils = require '../models/utils'
DatabaseStore = require './database-store'
ModelView = require './model-view'
NylasAPI = require '../inbox-api'
class SearchView extends ModelView
@ -45,7 +46,7 @@ class SearchView extends ModelView
@_pages[idx] = page
atom.inbox.makeRequest
NylasAPI.makeRequest
method: 'POST'
path: "/n/#{@_namespaceId}/threads/search?offset=#{idx * @_pageSize}&limit=#{@_pageSize}"
body: {"query": @_query, "sort": @_querySort}

View file

@ -1,4 +1,5 @@
Task = require './task'
NylasAPI = require '../inbox-api'
DatabaseStore = require '../stores/database-store'
Actions = require '../actions'
Tag = require '../models/tag'
@ -53,7 +54,7 @@ class AddRemoveTagsTask extends Task
performRemote: ->
new Promise (resolve, reject) =>
# queue the operation to the server
atom.inbox.makeRequest
NylasAPI.makeRequest
path: "/n/#{@namespaceId}/threads/#{@thread.id}"
method: 'PUT'
body:

View file

@ -7,6 +7,7 @@ Actions = require '../actions'
NamespaceStore = require '../stores/namespace-store'
DatabaseStore = require '../stores/database-store'
{isTempId} = require '../models/utils'
NylasAPI = require '../inbox-api'
class FileUploadTask extends Task
@ -24,7 +25,7 @@ class FileUploadTask extends Task
new Promise (resolve, reject) =>
Actions.uploadStateChanged @_uploadData("started")
@req = atom.inbox.makeRequest
@req = NylasAPI.makeRequest
path: "/n/#{@_namespaceId()}/files"
method: "POST"
json: false

View file

@ -1,6 +1,7 @@
Task = require './task'
DatabaseStore = require '../stores/database-store'
Actions = require '../actions'
NylasAPI = require '../inbox-api'
_ = require 'underscore-plus'
module.exports =
@ -21,7 +22,7 @@ class MarkMessageReadTask extends Task
performRemote: ->
new Promise (resolve, reject) =>
# queue the operation to the server
atom.inbox.makeRequest {
NylasAPI.makeRequest {
path: "/n/#{@message.namespaceId}/messages/#{@message.id}"
method: 'PUT'
body: {

View file

@ -6,6 +6,7 @@ Message = require '../models/message'
Task = require './task'
TaskQueue = require '../stores/task-queue'
SyncbackDraftTask = require './syncback-draft'
NylasAPI = require '../inbox-api'
module.exports =
class SendDraftTask extends Task
@ -44,7 +45,7 @@ class SendDraftTask extends Task
# Pass joined:true so the draft body is included
body = draft.toJSON(joined: true)
atom.inbox.makeRequest
NylasAPI.makeRequest
path: "/n/#{draft.namespaceId}/send"
method: 'POST'
body: body

View file

@ -3,6 +3,7 @@ _ = require 'underscore-plus'
Actions = require '../actions'
DatabaseStore = require '../stores/database-store'
NylasAPI = require '../inbox-api'
Task = require './task'
Message = require '../models/message'
@ -54,7 +55,7 @@ class SyncbackDraftTask extends Task
initialId = draft.id
@_saveAttempts += 1
atom.inbox.makeRequest
NylasAPI.makeRequest
path: path
method: method
body: body
@ -124,4 +125,3 @@ class SyncbackDraftTask extends Task
TaskQueue.enqueue @
@notifyErrorMessage(msg)