tmp-json-parsing

bwstearns 2016-05-28T18:08:38.000005Z

so yeah, you're going to want to a) read this in using a json reader so it's native clojure data

dmbennett 2016-05-28T18:09:42.000007Z

sorry if this painful to read, I don’t know clojure conventions either

bwstearns 2016-05-28T18:10:09.000008Z

no worries. it's not that tough to read (mostly follows convention)

dmbennett 2016-05-28T18:11:56.000009Z

lines 26+ are where I’m mucking around/shouldn’t work

dmbennett 2016-05-28T18:12:40.000010Z

the ideal goal is I end up with a list of items that have (= :field “status”)

dmbennett 2016-05-28T18:12:49.000011Z

and all the other pertinent data within the item

bwstearns 2016-05-28T18:12:56.000012Z

so your filter-status function doesn't actually filter anything

bwstearns 2016-05-28T18:13:11.000014Z

it just returns the first element of (presumably) a vector

bwstearns 2016-05-28T18:14:03.000015Z

ah, and get-status does a bit of the same

dmbennett 2016-05-28T18:15:05.000016Z

I think I was unsure how to filter through the data that (items) returns since it’s a lazy seq

dmbennett 2016-05-28T18:16:17.000017Z

the json I gave you is what the histories function returns

bwstearns 2016-05-28T18:17:11.000019Z

you can filter lazy-seqs as well

bwstearns 2016-05-28T18:17:37.000020Z

(filter (fn [x] (= 0 (mod x 3))) (range 1 10))

dmbennett 2016-05-28T18:18:50.000021Z

When I run something like that I get an arity error?

bwstearns 2016-05-28T18:19:44.000022Z

it probably means that your input to the predicate function (the first argument here) is not what you think

bwstearns 2016-05-28T18:20:24.000023Z

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]

bwstearns 2016-05-28T18:20:48.000024Z

so you might accidentally be calling it on a seq/collection of objects instead of on a single collection of objects.

dmbennett 2016-05-28T18:21:52.000025Z

ok

dmbennett 2016-05-28T18:22:10.000026Z

let me work this around for a little bit and see if I can get the filter running correctly

bwstearns 2016-05-28T18:22:53.000027Z

ok cool.

dmbennett 2016-05-28T18:23:16.000028Z

thanks for helping so far

bwstearns 2016-05-28T18:23:38.000029Z

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

bwstearns 2016-05-28T18:24:19.000030Z

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.

dmbennett 2016-05-28T18:24:53.000031Z

what does the double bracket syntax indicate?

dmbennett 2016-05-28T18:24:58.000032Z

[[x]]

bwstearns 2016-05-28T18:25:13.000033Z

so it's argument destructuring.

bwstearns 2016-05-28T18:25:50.000034Z

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

bwstearns 2016-05-28T18:26:37.000035Z

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)

bwstearns 2016-05-28T18:27:21.000036Z

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

dmbennett 2016-05-28T18:28:58.000039Z

clojira.core=> (filter (fn [x] (= "status" (:field x))) items)

dmbennett 2016-05-28T18:29:59.000043Z

=> ()

bwstearns 2016-05-28T18:30:17.000045Z

so at least in the data you sent me: there is no :field data, there is "field" data

dmbennett 2016-05-28T18:31:13.000046Z

java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn

bwstearns 2016-05-28T18:31:33.000047Z

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)

dmbennett 2016-05-28T18:31:50.000049Z

EDN?

bwstearns 2016-05-28T18:32:21.000050Z

EDN is extensible data notation (?) dunno, I just think of it as clojure's funny-json

bwstearns 2016-05-28T18:33:13.000051Z

{:this "is" :edn "data"} is like {this: "is", json: "data"}

dmbennett 2016-05-28T18:33:38.000052Z

ok

bwstearns 2016-05-28T18:33:56.000054Z

in clojure you can use keywords as functions on maps

bwstearns 2016-05-28T18:34:50.000055Z

so

(def my-item {:foo "bar" :baz [1 2 3]}
(:baz my-item) ;; => [1 2 3]

dmbennett 2016-05-28T18:35:20.000057Z

so to convert the rest json to edn

bwstearns 2016-05-28T18:35:23.000058Z

makes it a lot more concise than having extra gets everywhere

dmbennett 2016-05-28T18:35:26.000059Z

when I get the response I should create a function that converts it?

bwstearns 2016-05-28T18:35:39.000061Z

I think your http library should have a function or arg that does it

bwstearns 2016-05-28T18:38:42.000062Z

try adding the content type header application/edn as per the output coercion section here: https://github.com/dakrone/clj-http

dmbennett 2016-05-28T18:39:22.000064Z

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}))

bwstearns 2016-05-28T18:43:08.000065Z

I actually don't know the specifics of adding headers to http-get requests

bwstearns 2016-05-28T18:43:36.000066Z

good repl practice for the throw-shit-at-wall workflow lol.

bwstearns 2016-05-28T18:43:55.000067Z

could also google around a bit and try to find an example

bwstearns 2016-05-28T18:45:13.000068Z

I gotta run off to a bbq, but I hope I was able to help out a little bit.

dmbennett 2016-05-28T18:47:56.000069Z

ok, thanks!

dmbennett 2016-05-28T20:19:37.000073Z

Ok, so here is where I got to

dmbennett 2016-05-28T20:19:45.000074Z

but got stuck again

dmbennett 2016-05-28T20:20:05.000075Z

I’ve created a binding called “items”

dmbennett 2016-05-28T20:21:15.000077Z

items has those values

dmbennett 2016-05-28T20:22:04.000078Z

In order to get the first map and check it for (=“status” :field)

dmbennett 2016-05-28T20:22:44.000079Z

I call (:field (first (first items)))

dmbennett 2016-05-28T20:23:47.000080Z

for some reason calling (:field (first items)) returns nil