2017-07-03 22:12:09 +00:00
|
|
|
"
|
2017-07-05 11:17:44 +00:00
|
|
|
I contain simple general functionality used by Grafoscopio, Dataviz
|
|
|
|
or other related projects.
|
2017-07-03 22:12:09 +00:00
|
|
|
"
|
|
|
|
Class {
|
2017-07-06 21:23:22 +00:00
|
|
|
#name : #GrafoscopioUtils,
|
2017-07-03 22:12:09 +00:00
|
|
|
#superclass : #Object,
|
|
|
|
#category : #'Grafoscopio-Utils'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #'graphical interface' }
|
2017-07-06 21:23:22 +00:00
|
|
|
GrafoscopioUtils class >> downloadingFrom: downloadUrl withMessage: aString into: location [
|
2017-07-03 22:12:09 +00:00
|
|
|
| fileName |
|
2017-08-15 11:54:55 +00:00
|
|
|
fileName := (self sanitize: downloadUrl) segments last.
|
2017-08-11 13:37:35 +00:00
|
|
|
(location / fileName) ensureDelete.
|
2017-07-03 22:12:09 +00:00
|
|
|
[: bar |
|
|
|
|
bar title: aString.
|
|
|
|
[ZnClient new
|
|
|
|
enforceHttpSuccess: true;
|
|
|
|
url: downloadUrl;
|
|
|
|
downloadTo: location;
|
|
|
|
signalProgress: true
|
|
|
|
]
|
|
|
|
on: HTTPProgress
|
|
|
|
do: [ :progress |
|
|
|
|
progress isEmpty ifFalse: [ bar current: progress percentage ].
|
|
|
|
progress resume ].
|
|
|
|
] asJob run.
|
|
|
|
]
|
2017-08-11 13:37:35 +00:00
|
|
|
|
2017-08-15 11:54:55 +00:00
|
|
|
{ #category : #'graphical interface' }
|
|
|
|
GrafoscopioUtils class >> getContentsFrom: url withMessage: aString [
|
|
|
|
| client |
|
|
|
|
[: bar |
|
|
|
|
bar title: aString.
|
|
|
|
[client := ZnClient new
|
|
|
|
enforceHttpSuccess: true;
|
|
|
|
get: (url);
|
|
|
|
signalProgress: true
|
|
|
|
]
|
|
|
|
on: HTTPProgress
|
|
|
|
do: [ :progress |
|
|
|
|
progress isEmpty ifFalse: [ bar current: progress percentage ].
|
|
|
|
progress resume ].
|
|
|
|
] asJob run.
|
|
|
|
^ client contents.
|
|
|
|
]
|
|
|
|
|
2017-08-11 13:37:35 +00:00
|
|
|
{ #category : #private }
|
|
|
|
GrafoscopioUtils class >> sanitize: url [
|
|
|
|
"I remove white spaces in url's and prepend 'http://' to urls when it is ommited, so
|
|
|
|
operations that rely on sane and well formed urls don't throw error messages."
|
|
|
|
| sanitized modUrl |
|
|
|
|
modUrl := url.
|
|
|
|
[modUrl endsWith: ' ']
|
|
|
|
whileTrue: [ modUrl := modUrl copyFrom: 1 to: (modUrl size - 1) ].
|
|
|
|
(url beginsWith: 'http://')
|
|
|
|
ifFalse: [ sanitized := ('http://', modUrl) asUrl ]
|
|
|
|
ifTrue: [ sanitized := modUrl asUrl ].
|
|
|
|
^ sanitized
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #updating }
|
|
|
|
GrafoscopioUtils class >> update [
|
|
|
|
"Updates GrafoscopioUtils with new versions of itself take from the source code repository."
|
|
|
|
Gofer new
|
|
|
|
smalltalkhubUser: 'Offray' project: 'Grafoscopio';
|
2017-08-11 13:39:08 +00:00
|
|
|
package: 'Grafoscopio-Utils';
|
2017-08-11 13:37:35 +00:00
|
|
|
load.
|
|
|
|
]
|