class Weekdone::Api

Constants

API_URL

Attributes

client[R]
loglevel[RW]
token_code[RW]

Public Class Methods

new(client_id, client_secret, loglevel: Logger::DEBUG) click to toggle source
# File lib/weekdone/api.rb, line 14
def initialize(client_id, client_secret, loglevel: Logger::DEBUG)
  @logger = Logger.new(STDERR)
  @logger.level = loglevel

  @client = OAuth2::Client.new(
    client_id, client_secret,
    {
      site: 'https://weekdone.com',
      authorize_url: 'oauth_authorize',
      token_url: 'oauth_token',
      redirect_uri: 'http://localhost:8080/oauth2/callback'
    }
  )
end

Public Instance Methods

addItemComment() click to toggle source
# File lib/weekdone/api.rb, line 134
def addItemComment
  raise NotImplementedError
end
addItemLike() click to toggle source
# File lib/weekdone/api.rb, line 113
def addItemLike
  raise NotImplementedError
end
addObjectiveComment() click to toggle source
# File lib/weekdone/api.rb, line 246
def addObjectiveComment
  raise NotImplementedError
end
addObjectiveResult() click to toggle source
# File lib/weekdone/api.rb, line 258
def addObjectiveResult
  raise NotImplementedError
end
assignItemToAnotherUser() click to toggle source
# File lib/weekdone/api.rb, line 96
def assignItemToAnotherUser
  raise NotImplementedError
end
authenticate() click to toggle source
# File lib/weekdone/api.rb, line 29
def authenticate
  puts "open URL to authorize:"
  puts authorization_request

  print "\ninput authorization code: "
  auth_code = gets.chomp
  authorization_grant(auth_code)
end
authorization_grant(auth_code) click to toggle source
# File lib/weekdone/api.rb, line 42
def authorization_grant(auth_code)
  @token = client.auth_code.get_token(
    auth_code,
    redirect_uri: 'http://localhost:8080/oauth2/authorized'
  )

  @token_code = @token.token
end
authorization_request() click to toggle source
# File lib/weekdone/api.rb, line 38
def authorization_request
  @client.auth_code.authorize_url
end
createItem() click to toggle source
# File lib/weekdone/api.rb, line 88
def createItem
  raise NotImplementedError
end
createNewObjective() click to toggle source
# File lib/weekdone/api.rb, line 225
def createNewObjective
  raise NotImplementedError
end
deleteItem() click to toggle source
# File lib/weekdone/api.rb, line 100
def deleteItem
  raise NotImplementedError
end
deleteItemComment() click to toggle source
# File lib/weekdone/api.rb, line 138
def deleteItemComment
  raise NotImplementedError
end
deleteItemLike() click to toggle source
# File lib/weekdone/api.rb, line 117
def deleteItemLike
  raise NotImplementedError
end
deleteObjective() click to toggle source
# File lib/weekdone/api.rb, line 233
def deleteObjective
  raise NotImplementedError
end
deleteObjectiveComment() click to toggle source
# File lib/weekdone/api.rb, line 254
def deleteObjectiveComment
  raise NotImplementedError
end
deleteObjectiveResult() click to toggle source
# File lib/weekdone/api.rb, line 266
def deleteObjectiveResult
  raise NotImplementedError
end
getAllObjectives(type: nil, departmentid: nil, teamid: nil, userid: nil, period: nil) click to toggle source
# File lib/weekdone/api.rb, line 210
def getAllObjectives(type: nil, departmentid: nil, teamid: nil, userid: nil, period: nil)
  refresh

  params = { token: @token_code }
  params[:type] = type if not type.nil?
  params[:department_id] = departmentid if not departmentid.nil?
  params[:team_id] = teamid if not teamid.nil?
  params[:user_id] = userid if not userid.nil?
  params[:period] = period if not period.nil?

  @logger.debug("params: #{params}")
  response = Faraday.get(API_URL + '/1/objective', params)
  JSON.parse(response.body)
end
getAllTags() click to toggle source
# File lib/weekdone/api.rb, line 183
def getAllTags
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/tag', params)
  JSON.parse(response.body)
end
getAllTeams() click to toggle source
# File lib/weekdone/api.rb, line 153
def getAllTeams
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/teams', params)
  JSON.parse(response.body)
end
getAllTypes() click to toggle source
# File lib/weekdone/api.rb, line 173
def getAllTypes
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/types', params)
  JSON.parse(response.body)
end
getAllUsers() click to toggle source
# File lib/weekdone/api.rb, line 163
def getAllUsers
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/users', params)
  JSON.parse(response.body)
end
getCompanyInfo() click to toggle source
# File lib/weekdone/api.rb, line 271
def getCompanyInfo
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/company', params)
  JSON.parse(response.body)
end
getItemComments(item_id) click to toggle source
# File lib/weekdone/api.rb, line 125
def getItemComments(item_id)
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + "/1/item/#{item_id}/comments", params)
  JSON.parse(response.body)
end
getItemLikes(item_id) click to toggle source
# File lib/weekdone/api.rb, line 104
def getItemLikes(item_id)
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + "/1/item/#{item_id}/likes", params)
  JSON.parse(response.body)
end
getReport() click to toggle source
# File lib/weekdone/api.rb, line 143
def getReport
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + '/1/report', params)
  JSON.parse(response.body)
end
getSingleTag(tag_id) click to toggle source
# File lib/weekdone/api.rb, line 192
def getSingleTag(tag_id)
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + "/1/tag/#{tag_id}", params)
  JSON.parse(response.body)
end
listObjectiveComments(objective_id) click to toggle source
# File lib/weekdone/api.rb, line 237
def listObjectiveComments(objective_id)
  refresh

  params = { token: @token_code }

  response = Faraday.get(API_URL + "/1/objective/#{objective_id}/comments", params)
  JSON.parse(response.body)
end
refresh() click to toggle source
# File lib/weekdone/api.rb, line 51
def refresh
  @logger.debug("tokencode=#{@token_code} clientid=#{@client.id}")

  if @token.expired?
    @token = @token.refresh!
    @logger.info("refreshed token due to expire (new token expires at #{Time.at(@token.expires_at)}).")
  elsif
    @logger.debug("token is still valid (token expires at #{Time.at(@token.expires_at)}).")
  end

  @token_code = @token.token
end
searchForItems(user_id: nil, team_id: nil, period: nil) click to toggle source
# File lib/weekdone/api.rb, line 76
def searchForItems(user_id: nil, team_id: nil, period: nil)
  refresh

  params = { token: @token_code }
  params[:user_id] = user_id if not user_id.nil?
  params[:team_id] = team_id if not team_id.nil?
  params[:period] = period if not period.nil?

  response = Faraday.get(API_URL + '/1/items', params)
  JSON.parse(response.body)
end
sortItems() click to toggle source
# File lib/weekdone/api.rb, line 121
def sortItems
  raise NotImplementedError
end
token_hash() click to toggle source
# File lib/weekdone/api.rb, line 64
def token_hash
  @token.to_hash
end
token_hash=(hash) click to toggle source
# File lib/weekdone/api.rb, line 68
def token_hash=(hash)
  @logger.debug("update oauth token from hash=#{hash}")

  @token = OAuth2::AccessToken.from_hash(@client, hash)
  @token_code = @token.token
end
updateItem() click to toggle source
# File lib/weekdone/api.rb, line 92
def updateItem
  raise NotImplementedError
end
updateObjective() click to toggle source
# File lib/weekdone/api.rb, line 229
def updateObjective
  raise NotImplementedError
end
updateObjectiveComment() click to toggle source
# File lib/weekdone/api.rb, line 250
def updateObjectiveComment
  raise NotImplementedError
end
updateObjectiveResult() click to toggle source
# File lib/weekdone/api.rb, line 262
def updateObjectiveResult
  raise NotImplementedError
end
updateTagPriority() click to toggle source
# File lib/weekdone/api.rb, line 201
def updateTagPriority
  raise NotImplementedError
end
updateTagStatus() click to toggle source
# File lib/weekdone/api.rb, line 205
def updateTagStatus
  raise NotImplementedError
end