2
|a b |
a := ZnClient new.
a get: 'http://cloud-storage.com/login'.
a
formAt: 'username' put: 'jom';
formAt: 'password' put: 'mypass';
post;
get: 'http://cloud-storage.com/my-file'.
"Here I want to refresh the session for every 60sec and"
"to checking for newer data"
b := a maxNumberOfRedirects:60
Transcript show: b; cr.

I would like to implement a method that can refresh the ZnClient session every 60s for checking for newer data on the server I am logged into. I tried the redirect method of pharo but it does not seem to work. or say It does not show anything. Any idea?

ludo
  • 543
  • 3
  • 14
  • Could you share your code and explain what "does not work" means exactly? – MartinW Nov 24 '17 at 12:53
  • 1
    @MartinW I added a few line of code in the post and also what I am trying to execute. Thanks – ludo Nov 24 '17 at 13:18
  • 2
    Have a look at the comment for `maxNumberOfRedirects:` in a System Browser. It does something entirely different than what you thought it does: "Set the maximum number of HTTP redirect that will be followed to count." _Redirect_ is something different than _repeat_. – MartinW Nov 24 '17 at 13:33

1 Answers1

2
| session data |

session := ZnClient new url: 'http://cloud-storage.com'.

"Login"
session path: '/login';
    formAt: 'email' put: 'jom';
    formAt: 'password' put: 'mypass';
    post.

"Get data"
data := session path: '/my-file'; get; contents.

"Check for new data every 60 secs for maximum 100 tries"
[
    100 timesRepeat: [
        | newData |
        (Delay forSeconds: 60) wait.
        newData := session path: '/my-file'; get; contents.
        (data ~= newData) ifTrue: [Transcript show: newData; cr]
    ]
] fork.

NB. Despite above example code you may want to consider trying If-Modified-Since method in ZnClient.

draegtun
  • 22,441
  • 5
  • 48
  • 71
  • 4
    Thanks for the answer. Thanks also for showing us how to properly write Smalltalk code here using ``, which many of us weren't aware of! – Leandro Caniglia Nov 25 '17 at 15:11
  • @draegtun, thank you. This seems like the right example I needed – ludo Nov 26 '17 at 16:47
  • @LeandroCaniglia - Actually `lang-smalltalk` is a bum steer :( See this Meta question about adding [Smalltalk syntax highlighting](https://meta.stackoverflow.com/questions/360494/smalltalk-tagged-questions-not-automatically-syntax-highlighted). – draegtun Dec 11 '17 at 22:14
  • @LeandroCaniglia - re: There are pros & cons with the `lang-default` change. This will mean `#symbol` and `#()` will be shown with comment highligting :( Is this a price worth paying? – draegtun Dec 11 '17 at 22:39