class ShiftNote

All ShiftNote functionality, whether extended or just here.

Public Class Methods

new(username: nil, password: nil) click to toggle source

Initialize a new ShiftNote variable, via login credentials. @param username [String] the username of the user. @param password [String] the password of the user.

# File lib/shiftnote.rb, line 14
def initialize(username: nil, password: nil)
  @credentials = { username: username, password: password }
  generate_cookie(username, password)
end

Public Instance Methods

date_of_next(day) click to toggle source

Method to find the next instance of the given date. @!visibility private @param day [String] what day to find

# File lib/shiftnote.rb, line 59
def date_of_next(day)
  date  = Date.parse(day)
  delta = date > Date.today ? 0 : 7
  date + delta
end
employee(id) click to toggle source

Get an employee (by id) @param id [Integer] the id of the employee

# File lib/shiftnote.rb, line 101
def employee(id)
  Employee.new(id: id)
end
get_next_week_shifts(day = "Monday") click to toggle source

@param day [String] what day the week starts on. @return [ScheduleThisWeek] the schedule for next week.

# File lib/shiftnote.rb, line 107
def get_next_week_shifts(day = "Monday")
  nextmonday = date_of_next(day)

  week2 = RestClient.get("https://ww1.shiftnote.com/Schedules/ScheduleMine/?startDate=#{nextmonday.month}%2F#{nextmonday.day}%2F#{nextmonday.year}&noContainer=true&_=#{Time.now.to_i * 1000}", Cookie: cookie)

  week2doc = Nokogiri::HTML.parse(week2.body)
  dataweek2 = JSON.parse(scrapejunk(week2doc.at('script').text))
  User.new(dataweek2).schedule_this_week
end
scrapejunk(string) click to toggle source

Useful method (for the gem that is) that gets rid of stuff we don't need. @!visibility private @param string [String] a string to scrape the junk off

# File lib/shiftnote.rb, line 52
def scrapejunk(string)
  string.gsub('<script>', '').delete(';').gsub('</script>', '').gsub('window.scheduleMinebindings = ShiftNote.Bind(window.scheduleMinemodel)', '').gsub('window.scheduleMinemodel = ', '')
end
send_message(recipients, subject, body, urgent) click to toggle source

Send a message to a user (or group of them) @param recipients [Array<Integer>] who will receive this message

# File lib/shiftnote.rb, line 119
def send_message(recipients, subject, body, urgent)
  data = {
    "ToUserIDs" => recipients,
    "Subject" => subject,
    "Body" => body,
    "Priority" => urgent
  }
  RestClient.post('https://ww1.shiftnote.com/Message/SendMessages', URI.encode_www_form(data), Cookie: @cookie)
end
user() click to toggle source

Get the information of the currently logged in user. @return [User] the user

# File lib/shiftnote.rb, line 82
def user
  shiftnote = RestClient.get('https://ww1.shiftnote.com/BulletinBoard/', Cookie: @cookie)

  doc = Nokogiri::HTML.parse(shiftnote.body)

  begin
    data = doc.search('div#MyScheduleDiv').at('script').text
  rescue NoMethodError
    generate_cookie(@credentials[:username], @credentials[:password])
    retry
  end

  data = data.gsub('<script>', '').delete(';').gsub('</script>', '').gsub('window.scheduleMinebindings = ShiftNote.Bind(window.scheduleMinemodel)', '').gsub('window.scheduleMinemodel = ', '')

  User.new(JSON.parse(data))
end