Fork me on GitHub
#yada
<
2015-12-28
>
nha09:12:34

I am using ->source

malcolmsparks10:12:41

"No implementation of method: :to-body of protocol: #'yada.body/MessageBody found for class: manifold.stream.async.CoreAsyncSource" ;; :via ;; [{:type clojure.lang.ExceptionInfo

nha11:12:41

Well in this case yes I get it. I have to use ->source, but I don't get why the second fails ?

(assoc :body (let [ch (chan)]
                             (go-loop []
                               (>! ch " ok ")
                               (<! (timeout 100))
                               (recur))
                             (s/->source ch)))))

malcolmsparks11:12:39

@nha hey, I answered your StackOverflow!

nha11:12:46

Thanks !

malcolmsparks11:12:11

suggest you raise issues on GH for now, then once yada is released we can start building a StackOverflow KB

malcolmsparks11:12:37

I don't want to clutter up SO for future users with issues that were due to yada's relative current immaturity simple_smile

nha11:12:53

Ok sure. So it is a version problem ? I tried 1.0.0 and 1.1.0-SNAPSHOT

malcolmsparks11:12:53

I've just pushed a commit

nha11:12:59

Ok great !

malcolmsparks11:12:59

Let me release it for you

malcolmsparks11:12:37

just running my tests...

malcolmsparks11:12:05

deploying to clojars...

malcolmsparks11:12:39

done - this version also supports CORS now - see phonebook example for how this is done - basically you add an access-control entry to the resource

malcolmsparks11:12:11

I'm tending to prefer that resource models are complete and contain everything needed prior to handling requests

malcolmsparks11:12:38

that way things are faster (when requests arrive) and easier to debug when developing (no surprises)

malcolmsparks11:12:50

@nha let me know if that new release does what you need

nha11:12:04

@malcolmsparks: I will ! Thanks simple_smile

malcolmsparks11:12:42

today I will be working on @stijn's security (authn/authz)

nha11:12:44

I should try 1.1.0-SNAPSHOT , right ?

malcolmsparks11:12:56

go with [yada "1.1.0-20151228.110457-4"]

malcolmsparks11:12:17

reason is, you protect yourself from surprises if I choose to release a new snapshot

nha11:12:08

Well since I am still in a prototype phase if I can find things early that's still fine simple_smile

malcolmsparks11:12:08

clojars gives us 'immutable' versions, even for snapshots - it's a nice idea and helps during a alpha/beta phase not to have to keep changing the project.clj

malcolmsparks11:12:10

yeah, you can always go with 1.1.0-SNAPSHOT but the trouble is Maven will avoid checking for a new update if you have a version that is less than a day old - so it won't guarentee you the newest anyway

malcolmsparks11:12:24

anyway good luck !

malcolmsparks11:12:52

> "One of the things I think would be great is if the order of the interceptors is: parse-parameters > authentication > get-properties > authorization. The thing is that in get-properties you often need stuff like the currently logged-in user to retrieve something from the database (like 'my posts' or something)" - @stijn

nha11:12:14

Just tried it, got a new error : clojure.lang.Compiler$CompilerException: clojure.lang.ArityException: Wrong number of args (2) passed to: core/yada, compiling:(ts.clj:9:3)

malcolmsparks11:12:17

this is a really nice idea - because authentication should depend on the parameters (headers, cookies, etc.) but be independent of the resource itself

nha11:12:28

There is a change in the yadafn ?

malcolmsparks11:12:36

authorization needs to be determined in the context of the resource - is this user (e.g. bob) allowed to access THIS resource

malcolmsparks11:12:43

so it fits really nicely

nha11:12:09

That make sense (the order of interceptors)

malcolmsparks11:12:25

@nha there have been a few changes, but nothing major, send me any errors you're getting

nha11:12:07

Well it is just my first example that throws en exception :

(def get-stream
  "a stream of timestamps of this particular machine"
  (yada (fn [ctx]
          (-> (:response ctx)
              (assoc :status 202)
              (assoc :body (s/periodically 1000 #(str (System/currentTimeMillis) " ")))))
        {:representations [{:media-type "application/json"
                            :charset    "UTF-8"}
                           {:media-type "application/edn"
                            :charset    "UTF-8"}]})) 
Maybe I should look at your new examples.

malcolmsparks11:12:17

what's the exception?

nha11:12:31

clojure.lang.Compiler$CompilerException: clojure.lang.ArityException: Wrong number of args (2) passed to: core/yada, compiling:(ts.clj:9:3)
            clojure.lang.ArityException: Wrong number of args (2) passed to: core/yada

malcolmsparks11:12:51

yada only takes one argument now

nha11:12:55

No problem simple_smile

malcolmsparks11:12:01

you need to rewrite to...

malcolmsparks11:12:43

`clojure (yada (yada/resource {:methods {:get (fn [ctx] (as before))} :produces [...]})

malcolmsparks11:12:52

whoops, let me try that again

malcolmsparks11:12:00

clojure
(yada (yada/resource {:methods {:get (fn [ctx] (as before))} :produces [...]})

malcolmsparks11:12:16

have a look at the phonebook example, that's similar to what you're doing

nha11:12:41

Ok doing that thanks again simple_smile

malcolmsparks11:12:55

basically the {:methods ... :produces ...} map is called the resource-model - we turn it into a resource with (yada/resource) that does nothing more than validate your map basically

malcolmsparks11:12:38

then, if your map has passed that validation check you get a Resource you can give to the yada function - it's single arity now and I think the second argument just allowed confusion to slip in

nha11:12:30

Sounds good simple_smile

nha11:12:58

I will let you know how it goes simple_smile

malcolmsparks11:12:32

thanks to @dominicm for the travis stuff

nha11:12:44

@malcolmsparks: the change worked simple_smile