hbagdi / go-unsplash Goto Github PK
View Code? Open in Web Editor NEWGo Client for the Unsplash API
Home Page: https://unsplash.com
License: MIT License
Go Client for the Unsplash API
Home Page: https://unsplash.com
License: MIT License
*Response gives info about paging but there is no mechanism to traverse multi-page results.
Currently a few of the API methods don't have a return Response object which has rate limiting and pagination info.
This needs to be uniform across every API call.
If anyone is using the package, this would break all those.
Users have the following link relations:
photos API location of this user’s photos.
portfolio API location of this user’s external portfolio.
followers API location of this user’s followers.
following API location of users this user is following.
Need to expose methods for each of these.
More filters are introduced in the API
https://unsplash.com/documentation#get-a-random-photo
Get a random photo
Retrieve a single random photo, given optional filters.
GET /photos/random
Note: See the note on hotlinking.
Parameters
All parameters are optional, and can be combined to narrow the pool of photos from which a random one will be chosen.
param Description
collections Public collection ID(‘s) to filter selection. If multiple, comma-separated
featured Limit selection to featured photos.
username Limit selection to a single user.
query Limit selection to photos matching a search term.
w Image width in pixels.
h Image height in pixels.
orientation Filter search results by photo orientation. Valid values are landscape, portrait, and squarish.
count The number of photos to return. (Default: 1; max: 30)
Note: You can’t use the collections and query parameters in the same request
Note: When supplying a count parameter - and only then - the response will be an array of photos, even if the value of count is 1.
Current implementation drops the errors fields returned by the API whenever an API error occurs.
Explore the possibility of including this errors fields.
The current implementation has custom errors and signals those errors based on HTTP response codes.
This would require exploring what kind of errors the API returns.
These change quite often!
I think it would make sense to adopt a dependency management tool to allow reproducable builds and such. I have been bitten by this with another web service API, so at least trialling out 'dep' or something similar would be a good start.
The Unsplash API can return invalid URLs for the User.PortfolioURL
in the case I ran into the url contained a whitespace character at the end of the url. This causes parsing the entire response to fail.
Changing User.PortfolioURL
to *string
instead of *Url
should work and handle any invalid URLs there since it's not clear if Unsplash will verify that the url the user enters is valid. Otherwise updating Url.UnmarshalJSON
to trim whitespace before parsing should at least eliminate some of these errors. It could also be a good idea to more gracefully handle errors here so parsing the entire response doesn't fail due to a single malformed URL.
API now gives statistics for a user's download and view count.
Need to introduce structs for these now.
This is related to #9
There will two ways of doing the same thing.
Once via as a method on user struct and another directly on the UserService via a username.
Both will need a new opt struct to specify resolution and quantity.
Parameters
param Description
username The user’s username. Required.
resolution The frequency of the stats. (Optional; default: “days”)
quantity The amount of for each stat. (Optional; default: 30)
Currently, the only resolution param supported is “days”. The quantity param can be any number between 1 and 30.
Source : https://unsplash.com/documentation#version
It seems like the API might move to a v2 at some point.
Need to make a breaking change to the New() method to pass a config struct.
A solution for now would be setting the header in do() before every request.
The API could return 500 or 503 errors. Handle these properly.
The current code is returning AuthError even for a rate limiting case.
unsplash's API doesn't give a resume time header but since they do it per hour, upon hitting the rate limit, just don't send the request till the next hour begins. Needs much more though.
seems like the endpoint previously used to return int values but now one of them returns a string.
Probably because of overflow??
The change is to write a custom UnmarshalJSON for the GlobalStats struct.
When using ListOpt
to populate List Options, you need to specify all values for the options rather than each as you need them. For instance, I have to specify Page
, PerPage
and OrderBy
if I want it to work, otherwise it fails with opt provided is not valid
:
photos, resp, err := u.Photos.Curated(&unsplash.ListOpt{
OrderBy: unsplash.Popular,
})
Will create an error
Need to add a String() representation to user, photo, and, collection
Unsplash /search endpoints don't return a Link header for pagination support.
Their dev has acknowledged the bug and they are going to fix it soon.
There's nothing much to be done here except wait and test the code again.
Retrieve total number of downloads, views and likes of a single photo, as well as the historical breakdown of these stats in a specific timeframe (default is 30 days).
https://unsplash.com/documentation#get-a-photos-statistics
GET /photos/:id/statistics
Similar to #9
Since the API provides random or search endpoints, hardcoding test cases in not a good way to go.
Retrieve the consolidated number of downloads, views and likes of all user’s photos, as well as the historical breakdown and average of these stats in a specific timeframe (default is 30 days).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.