<commit_before>"use strict"

window.Sailor = ((env) ->
  lang = navigator.language.split("-")[0]
  if env is 'development' then api = 'http://localhost:1337' else api = 'http://sailor-twitter-api.herokuapp.com'

  _proxy = (type, method, parameters = {}, background = false) ->
    promise = new Hope.Promise()
    unless background then __.Dialog.Loading.show()
    token = if session? then session.token else null
    $$.ajax
      url         : "#{api}/#{lang}/#{method}"
      type        : type
      data        : parameters
      dataType    : 'json'
      contentType : "application/x-www-form-urlencoded"
      success: (xhr) ->
        unless background then do __.Dialog.Loading.hide
        promise.done null, xhr
      error: (xhr, response) =>
        unless background then do __.Dialog.Loading.hide
        error = code: xhr.status, message: xhr.responseJSON.message
        promise.done error, null
    promise

  _socket = (type, method, parameters = {}) ->
    io.socket[type.toLowerCase()] "/#{lang}/#{method}", parameters, (res, jw) =>

  _on = (Model, callback) -> io.socket.on Model, (callback)

  _session = (data = {}) ->
    if Object.keys(data).length is 0
      JSON.parse(localStorage.getItem('user'))
    else
      localStorage.setItem('user', JSON.stringify(data))

  # EXPORTS
  ## URL Paths
  host    : api
  login   : "user/login"
  signup  : "user"
  user    : "user"
  tweet   : "tweet"
  tweets  : "tweet?sort=id asc"
  ## Methods
  proxy   : _proxy
  socket  : _socket
  on      : _on
  session : _session
  ## Environment
  environment : env
)("production")

window.Atoms.Twitter = do ->
  _start = ->
    Sailor.socket "GET", Sailor.user, (users, jw) ->
      __.Entity.User.create user for user in users

    Sailor.socket "GET", Sailor.tweets, (tweets, jw) ->
      __.Entity.Tweet.create tweet for tweet in tweets

    Sailor.on Sailor.tweet, (tweet) ->
      __.Entity.Tweet.create tweet.data if tweet.verb is 'created'

    Sailor.on Sailor.user, (user) ->
      __.Entity.User.create user.data if user.verb is 'created'

  # EXPORTS
  ## Core
  Organism: {}
  Molecule: {}<commit_msg>regenerated<commit_after>"use strict"

window.Sailor = ((env) ->
  lang = navigator.language.split("-")[0]
  if env is 'development' then api = 'http://localhost:1337' else api = 'http://sailor-twitter-api.herokuapp.com'

  _proxy = (type, method, parameters = {}, background = false) ->
    promise = new Hope.Promise()
    unless background then __.Dialog.Loading.show()
    token = if session? then session.token else null
    $$.ajax
      url         : "#{api}/#{lang}/#{method}"
      type        : type
      data        : parameters
      dataType    : 'json'
      contentType : "application/x-www-form-urlencoded"
      success: (xhr) ->
        unless background then do __.Dialog.Loading.hide
        promise.done null, xhr
      error: (xhr, response) =>
        unless background then do __.Dialog.Loading.hide
        error = code: xhr.status, message: xhr.responseJSON.message
        promise.done error, null
    promise

  _socket = (type, method, parameters = {}) ->
    io.socket[type.toLowerCase()] "/#{lang}/#{method}", parameters, (res, jw) =>

  _on = (Model, callback) -> io.socket.on Model, (callback)

  _session = (data = {}) ->
    if Object.keys(data).length is 0
      JSON.parse(localStorage.getItem('user'))
    else
      localStorage.setItem('user', JSON.stringify(data))

  # EXPORTS
  ## URL Paths
  host    : api
  login   : "user/login"
  signup  : "user"
  user    : "user"
  tweet   : "tweet"
  tweets  : "tweet?sort=id asc"
  ## Methods
  proxy   : _proxy
  socket  : _socket
  on      : _on
  session : _session
  ## Environment
  environment : env
)("development")

window.Atoms.Twitter = do ->
  _start = ->
    Sailor.socket "GET", Sailor.user, (users, jw) ->
      __.Entity.User.create user for user in users

    Sailor.socket "GET", Sailor.tweets, (tweets, jw) ->
      __.Entity.Tweet.create tweet for tweet in tweets

    Sailor.on Sailor.tweet, (tweet) ->
      __.Entity.Tweet.create tweet.data if tweet.verb is 'created'

    Sailor.on Sailor.user, (user) ->
      __.Entity.User.create user.data if user.verb is 'created'

  # EXPORTS
  ## Core
  Organism: {}
  Molecule: {}
{'fraction_non_alphanumeric': 0.14268950950481107, 'fraction_numerical': 0.002816240319173903, 'mean_word_length': 2.59662447257384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '719747', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1423, 'n_words': 350}