Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable `latest-version.json' endpoint #315

Merged
merged 2 commits into from
Apr 14, 2015

Conversation

dotemacs
Copy link
Contributor

@dotemacs dotemacs commented Apr 3, 2015

My motivation for creating this is to be able to retreive the latest
version of a given clojar as JSON in the format of:

{"version": "0.1.3"}

So that we can have pretty badges like this:

Example clojar badge

as provided by http://shields.io/.

I'm well aware that /some-clojar/latest-version.svg endpoint exists, and it renders the badge already. But isn't in the same format as all the badges provided by GitHub et la.

With this PR you get the uniform look of the badges handled for you by this third party service, should the users want to. All you've got to provide them with is JSON. Which, if we're going to split hairs, would consume less bandwidth than the XML currently generated.

Also, somebody already created a PR on the shields repo: badges/shields#388 where they would use the /search end point. Which isn't going to be very efficient, since it won't try to look up a particular clojar's version, but it'll search through all the clojars first, only to return the latest version of one clojar. Which isn't optimal.

(defn make-latest-version-json [group-id artifact-id]
"Return the latest version of a JAR as JSON"
(let [jar (find-jar group-id artifact-id)]
(str "{\"version\":\"" (:version jar) "\"}")))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm creating this JSON string here manually, as I figured that it doesn't justify pulling in cheshire into this namespace just for this.

@tobias tobias modified the milestone: 0.15.12 Apr 13, 2015
@tobias
Copy link
Member

tobias commented Apr 13, 2015

This looks good to me so far. I'll take a closer look and merge before the next release.

(= file-format "svg") (-> (response/response (view/make-latest-version-svg artifact-id artifact-id))
(response/header "Cache-Control" "no-cache")
(response/content-type "image/svg+xml"))))

(GET ["/:group-id/:artifact-id/latest-version.svg"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding .json to this route as well? This route is used when the group doesn't match the artifact name (/org.clojure/clojure/latest-version.json, for example). It might be worthwhile to extract the cond out to a fn that you call from both routes.

@tobias tobias modified the milestones: 0.15.12, 0.15.13 Apr 13, 2015
@tobias tobias mentioned this pull request Apr 13, 2015
My motivation for creating this is to be able to retreive the latest
version of a given clojar as JSON in the format of:

  {"version": "x.y.z"}

I'd like to have that option so that I can use it with the options as
provided by http://shields.io/.
When the group is known but doesn't match the artifact name, so that it
can be viewed as JSON or SVG e.g.

  /:group-id/:artifact-id/latest-version.:file-format
@dotemacs
Copy link
Contributor Author

@tobias what do you think of this last change? Does it feel right to you?

Thanks

tobias added a commit that referenced this pull request Apr 14, 2015
Enable `latest-version.json' endpoint
@tobias tobias merged commit 5e20f40 into clojars:master Apr 14, 2015
@tobias
Copy link
Member

tobias commented Apr 14, 2015

Looks good, thanks!

@dotemacs dotemacs deleted the latest-version-in-json branch April 15, 2015 05:19
@tobias
Copy link
Member

tobias commented Apr 15, 2015

This is now in production.

@dotemacs
Copy link
Contributor Author

Thank you @tobias :)

@dotemacs
Copy link
Contributor Author

The change for this to be used by http://shields.io/ is now live. Which is great.

See how it looks:

pdfboxing

Should I change it so it looks more like:

"clojars.org" ?

Thanks

@tobias
Copy link
Member

tobias commented Apr 25, 2015

I think I prefer a combination of the two - I like showing the full coordinates in the badge, but prefer just "clojars", especially since the coordinates can be pretty long if a long group is included, and/or the version is long: [org.clojars.tcrawley/foo-bar "0.1.0-SNAPSHOT"].

@dotemacs
Copy link
Contributor Author

OK, so what I've done is keep the 'clojars' only, omitting the '.org' part.

But I'm leaving the full name & version, as I figure, that it would be practical to just cut & paste the name to be able to add it to project.clj.

Created a pull request: badges/shields#431

@tobias
Copy link
Member

tobias commented Apr 27, 2015

That sounds good to me. Thanks!

@brunchboy brunchboy mentioned this pull request Aug 12, 2015
zjhmale pushed a commit to zjhmale/clojars-web that referenced this pull request Oct 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants