so yeah, you're going to want to a) read this in using a json reader so it's native clojure data
sorry if this painful to read, I don’t know clojure conventions either
no worries. it's not that tough to read (mostly follows convention)
lines 26+ are where I’m mucking around/shouldn’t work
the ideal goal is I end up with a list of items that have (= :field “status”)
and all the other pertinent data within the item
so your filter-status function doesn't actually filter anything
it just returns the first element of (presumably) a vector
ah, and get-status does a bit of the same
I think I was unsure how to filter through the data that (items) returns since it’s a lazy seq
the json I gave you is what the histories function returns
you can filter lazy-seqs as well
(filter (fn [x] (= 0 (mod x 3))) (range 1 10))
When I run something like that I get an arity error?
it probably means that your input to the predicate function (the first argument here) is not what you think
cljs.user=> (filter even? (range 1 10))
(2 4 6 8)
cljs.user=> (filter even? (range 1 10) (range 11 20))
WARNING: Wrong number of args (3) passed to cljs.core/filter at line 1 <cljs repl>
#object[Error Error: Invalid arity: 3]
so you might accidentally be calling it on a seq/collection of objects instead of on a single collection of objects.
ok
let me work this around for a little bit and see if I can get the filter running correctly
ok cool.
thanks for helping so far
another thing to think about before you go is 1) argument destructuring (map (fn [[x y]] (+ x y)) {1 2 3 4 5 6})
and also take a look at reduce/reduce-kv
the braveclojure site has a really good section on the map/filter/reduce operations which are really powerful for data operations once you get comfortable composing them.
what does the double bracket syntax indicate?
[[x]]
so it's argument destructuring.
when you map over a map you actually get the list (x y) as a tuple (I think?) out of the collection as opposed to each value being passed individually
so the first data that gets passed to our anonymous function isn't actually the values 1
and 2
but rather the pair (1 2)
the brackets indicated that one collection argument with two elements is going to be passed in, and that the first element should be assigned to x, and the second to y
clojira.core=> (filter (fn [x] (= "status" (:field x))) items)
=> ()
so at least in the data you sent me: there is no :field
data, there is "field"
data
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn
so you'd need to either change the original parsing so that it's stored as an EDN structure (recommended) or use (get "field" x)
EDN?
EDN is extensible data notation (?) dunno, I just think of it as clojure's funny-json
{:this "is" :edn "data"}
is like {this: "is", json: "data"}
ok
in clojure you can use keywords as functions on maps
so
(def my-item {:foo "bar" :baz [1 2 3]}
(:baz my-item) ;; => [1 2 3]
so to convert the rest json to edn
makes it a lot more concise than having extra gets everywhere
when I get the response I should create a function that converts it?
I think your http library should have a function or arg that does it
try adding the content type header application/edn
as per the output coercion section here: https://github.com/dakrone/clj-http
so in my call-jira function:
(client/get "<https://uptake.atlassian.net/rest/api/latest/issue/BAD-101/?expand=changelog>" {:basic-auth [username pass] :as :auto}))
I actually don't know the specifics of adding headers to http-get requests
good repl practice for the throw-shit-at-wall workflow lol.
could also google around a bit and try to find an example
I gotta run off to a bbq, but I hope I was able to help out a little bit.
ok, thanks!
Ok, so here is where I got to
but got stuck again
I’ve created a binding called “items”
items has those values
In order to get the first map and check it for (=“status” :field)
I call (:field (first (first items)))
for some reason calling (:field (first items))
returns nil