Class: Weekdone::Api
- Inherits:
-
Object
- Object
- Weekdone::Api
- Defined in:
- lib/weekdone/api.rb
Constant Summary collapse
- API_URL =
'https://api.weekdone.com'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#loglevel ⇒ Object
Returns the value of attribute loglevel.
-
#token_code ⇒ Object
Returns the value of attribute token_code.
Instance Method Summary collapse
- #addItemComment ⇒ Object
- #addItemLike ⇒ Object
- #addObjectiveComment ⇒ Object
- #addObjectiveResult ⇒ Object
- #assignItemToAnotherUser ⇒ Object
- #authenticate ⇒ Object
- #authorization_grant(auth_code) ⇒ Object
- #authorization_request ⇒ Object
- #createItem ⇒ Object
- #createNewObjective ⇒ Object
- #deleteItem ⇒ Object
- #deleteItemComment ⇒ Object
- #deleteItemLike ⇒ Object
- #deleteObjective ⇒ Object
- #deleteObjectiveComment ⇒ Object
- #deleteObjectiveResult ⇒ Object
- #getAllObjectives(type: nil, departmentid: nil, teamid: nil, userid: nil, period: nil) ⇒ Object
- #getAllTags ⇒ Object
- #getAllTeams ⇒ Object
- #getAllTypes ⇒ Object
- #getAllUsers ⇒ Object
- #getCompanyInfo ⇒ Object
- #getItemComments(item_id) ⇒ Object
- #getItemLikes(item_id) ⇒ Object
- #getReport ⇒ Object
- #getSingleTag(tag_id) ⇒ Object
-
#initialize(client_id, client_secret, loglevel: Logger::DEBUG) ⇒ Api
constructor
A new instance of Api.
- #listObjectiveComments(objective_id) ⇒ Object
- #refresh ⇒ Object
- #searchForItems(user_id: nil, team_id: nil, period: nil) ⇒ Object
- #sortItems ⇒ Object
- #token_hash ⇒ Object
- #token_hash=(hash) ⇒ Object
- #updateItem ⇒ Object
- #updateObjective ⇒ Object
- #updateObjectiveComment ⇒ Object
- #updateObjectiveResult ⇒ Object
- #updateTagPriority ⇒ Object
- #updateTagStatus ⇒ Object
Constructor Details
#initialize(client_id, client_secret, loglevel: Logger::DEBUG) ⇒ Api
Returns a new instance of Api.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/weekdone/api.rb', line 11 def client @client end |
#loglevel ⇒ Object
Returns the value of attribute loglevel.
12 13 14 |
# File 'lib/weekdone/api.rb', line 12 def loglevel @loglevel end |
#token_code ⇒ Object
Returns the value of attribute token_code.
12 13 14 |
# File 'lib/weekdone/api.rb', line 12 def token_code @token_code end |
Instance Method Details
#addItemComment ⇒ Object
134 135 136 |
# File 'lib/weekdone/api.rb', line 134 def addItemComment raise NotImplementedError end |
#addItemLike ⇒ Object
113 114 115 |
# File 'lib/weekdone/api.rb', line 113 def addItemLike raise NotImplementedError end |
#addObjectiveComment ⇒ Object
246 247 248 |
# File 'lib/weekdone/api.rb', line 246 def addObjectiveComment raise NotImplementedError end |
#addObjectiveResult ⇒ Object
258 259 260 |
# File 'lib/weekdone/api.rb', line 258 def addObjectiveResult raise NotImplementedError end |
#assignItemToAnotherUser ⇒ Object
96 97 98 |
# File 'lib/weekdone/api.rb', line 96 def assignItemToAnotherUser raise NotImplementedError end |
#authenticate ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/weekdone/api.rb', line 29 def authenticate puts "open URL to authorize:" puts print "\ninput authorization code: " auth_code = gets.chomp (auth_code) end |
#authorization_grant(auth_code) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/weekdone/api.rb', line 42 def (auth_code) @token = client.auth_code.get_token( auth_code, redirect_uri: 'http://localhost:8080/oauth2/authorized' ) @token_code = @token.token end |
#authorization_request ⇒ Object
38 39 40 |
# File 'lib/weekdone/api.rb', line 38 def @client.auth_code. end |
#createItem ⇒ Object
88 89 90 |
# File 'lib/weekdone/api.rb', line 88 def createItem raise NotImplementedError end |
#createNewObjective ⇒ Object
225 226 227 |
# File 'lib/weekdone/api.rb', line 225 def createNewObjective raise NotImplementedError end |
#deleteItem ⇒ Object
100 101 102 |
# File 'lib/weekdone/api.rb', line 100 def deleteItem raise NotImplementedError end |
#deleteItemComment ⇒ Object
138 139 140 |
# File 'lib/weekdone/api.rb', line 138 def deleteItemComment raise NotImplementedError end |
#deleteItemLike ⇒ Object
117 118 119 |
# File 'lib/weekdone/api.rb', line 117 def deleteItemLike raise NotImplementedError end |
#deleteObjective ⇒ Object
233 234 235 |
# File 'lib/weekdone/api.rb', line 233 def deleteObjective raise NotImplementedError end |
#deleteObjectiveComment ⇒ Object
254 255 256 |
# File 'lib/weekdone/api.rb', line 254 def deleteObjectiveComment raise NotImplementedError end |
#deleteObjectiveResult ⇒ Object
266 267 268 |
# File 'lib/weekdone/api.rb', line 266 def deleteObjectiveResult raise NotImplementedError end |
#getAllObjectives(type: nil, departmentid: nil, teamid: nil, userid: nil, period: nil) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# 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 ⇒ Object
183 184 185 186 187 188 189 190 |
# 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 ⇒ Object
153 154 155 156 157 158 159 160 |
# 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 ⇒ Object
173 174 175 176 177 178 179 180 |
# 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 ⇒ Object
163 164 165 166 167 168 169 170 |
# 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 ⇒ Object
271 272 273 274 275 276 277 278 |
# 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) ⇒ Object
125 126 127 128 129 130 131 132 |
# 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) ⇒ Object
104 105 106 107 108 109 110 111 |
# 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 ⇒ Object
143 144 145 146 147 148 149 150 |
# 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) ⇒ Object
192 193 194 195 196 197 198 199 |
# 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) ⇒ Object
237 238 239 240 241 242 243 244 |
# 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 ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
121 122 123 |
# File 'lib/weekdone/api.rb', line 121 def sortItems raise NotImplementedError end |
#token_hash ⇒ Object
64 65 66 |
# File 'lib/weekdone/api.rb', line 64 def token_hash @token.to_hash end |
#token_hash=(hash) ⇒ Object
68 69 70 71 72 73 |
# 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 ⇒ Object
92 93 94 |
# File 'lib/weekdone/api.rb', line 92 def updateItem raise NotImplementedError end |
#updateObjective ⇒ Object
229 230 231 |
# File 'lib/weekdone/api.rb', line 229 def updateObjective raise NotImplementedError end |
#updateObjectiveComment ⇒ Object
250 251 252 |
# File 'lib/weekdone/api.rb', line 250 def updateObjectiveComment raise NotImplementedError end |
#updateObjectiveResult ⇒ Object
262 263 264 |
# File 'lib/weekdone/api.rb', line 262 def updateObjectiveResult raise NotImplementedError end |
#updateTagPriority ⇒ Object
201 202 203 |
# File 'lib/weekdone/api.rb', line 201 def updateTagPriority raise NotImplementedError end |
#updateTagStatus ⇒ Object
205 206 207 |
# File 'lib/weekdone/api.rb', line 205 def updateTagStatus raise NotImplementedError end |