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

Return additional request information - mk2 #39

Closed

Conversation

hkraal
Copy link
Contributor

@hkraal hkraal commented Jul 27, 2016

After valuable feedback on #37 we have decided that we do not want to mix CREST data with other data such as response_codes, expiry dates etc. The call() and getattr() are reserved for CREST and thus we give access to the data using getitem().

There should be no impact on existing behavior

>>> eve = EVE()
>>> eve()
{'userCount_str': '26249', 'marketTypes': {'href': 'https://crest-tq.eveonline.com/market/types/'}, 'constellations': {'href': 'https://crest-tq.eveonline.com/constellations/'}, 'decode': {'href': 'https://crest-tq.eveonline.com/decode/'}, 'virtualGoodStore': {'href': 'https://vgs-tq.eveonline.com/'}, 'itemTypes': {'href': 'https://crest-tq.eveonline.com/inventory/types/'}, 'itemGroups': {'href': 'https://crest-tq.eveonline.com/inventory/groups/'}, 'tournaments': {'href': 'https://crest-tq.eveonline.com/tournaments/'}, 'serverVersion': 'EVE-TRANQUILITY 14.06.1058053.1058052', 'insurancePrices': {'href': 'https://crest-tq.eveonline.com/insuranceprices/'}, 'sovereignty': {'structures': {'href': 'https://crest-tq.eveonline.com/sovereignty/structures/'}, 'campaigns': {'href': 'https://crest-tq.eveonline.com/sovereignty/campaigns/'}}, 'regions': {'href': 'https://crest-tq.eveonline.com/regions/'}, 'userCount': 26249, 'corporations': {'href': 'https://crest-tq.eveonline.com/corporations/'}, 'industry': {'facilities': {'href': 'https://crest-tq.eveonline.com/industry/facilities/'}, 'systems': {'href': 'https://crest-tq.eveonline.com/industry/systems/'}}, 'dogma': {'attributes': {'href': 'https://crest-tq.eveonline.com/dogma/attributes/'}, 'effects': {'href': 'https://crest-tq.eveonline.com/dogma/effects/'}}, 'incursions': {'href': 'https://crest-tq.eveonline.com/incursions/'}, 'systems': {'href': 'https://crest-tq.eveonline.com/solarsystems/'}, 'races': {'href': 'https://crest-tq.eveonline.com/races/'}, 'opportunities': {'tasks': {'href': 'https://crest-tq.eveonline.com/opportunities/tasks/'}, 'groups': {'href': 'https://crest-tq.eveonline.com/opportunities/groups/'}}, 'alliances': {'href': 'https://crest-tq.eveonline.com/alliances/'}, 'authEndpoint': {'href': 'https://login-tq.eveonline.com/oauth/token/'}, 'time': {'href': 'https://crest-tq.eveonline.com/time/'}, 'serverName': 'TRANQUILITY', 'marketGroups': {'href': 'https://crest-tq.eveonline.com/market/groups/'}, 'itemCategories': {'href': 'https://crest-tq.eveonline.com/inventory/categories/'}, 'serviceStatus': 'online', 'bloodlines': {'href': 'https://crest-tq.eveonline.com/bloodlines/'}, 'marketPrices': {'href': 'https://crest-tq.eveonline.com/market/prices/'}, 'wars': {'href': 'https://crest-tq.eveonline.com/wars/'}, 'npcCorporations': {'href': 'https://crest-tq.eveonline.com/corporations/npccorps/'}}
>>> eve()['status_code']
200
>>> eve()['version']
'application/vnd.ccp.eve.Api-v5'
>>> eve()['expires_in']
20
>>> eve()['expires_at']
1469648871.1075354

@hkraal hkraal added this to the v0.1.0 milestone Jul 27, 2016
@coveralls
Copy link

coveralls commented Jul 27, 2016

Coverage Status

Coverage decreased (-1.02%) to 98.98% when pulling 248babc on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@wtfrank
Copy link
Contributor

wtfrank commented Jul 27, 2016

looks good - one piece of information I'd want from the cache is the time that the cached object was originally valid. I had a quick look at http headers and didn't notice that information. So if its not there, then the time it was cached would do.

Scenario (based on xml api calls...for now) - you fetch your corp assets at 16:00, they are cached until 22:00. However if a second person fetched the corp assets at 18:00, they would get the version that was cached by CCP at 16:00, and they would want to know that this is the assets from 2 hours ago.

@jonobrien jonobrien mentioned this pull request Jul 27, 2016
@coveralls
Copy link

coveralls commented Jul 27, 2016

Coverage Status

Coverage decreased (-0.3%) to 99.66% when pulling 124f3bd on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@coveralls
Copy link

coveralls commented Jul 27, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling f0b64a7 on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@jonobrien
Copy link
Contributor

Isn't the xml api out of scope since we are hitting the json endpoints here?

@hkraal
Copy link
Contributor Author

hkraal commented Jul 27, 2016

It's an example as we do get information about untill when the object is cached at CCP it's side. In short: you know when you are good to retry.

On CREST it's sadly a guessing game

@wtfrank
Copy link
Contributor

wtfrank commented Jul 27, 2016

I mentioned the xml api to give an example of why you'd want to know when the data was cached by CCP (separately to when it was cached by pycrest)

@Kyria
Copy link
Contributor

Kyria commented Jul 27, 2016

Sadly you only know in how much time you are sure to get new data with the CREST expire time and not when, the earliest, you can get new data. I think I saw many people that already requested it on the tweetfleet slack and the eve forum (but in vain atm... maybe one day) .

As for the header informations using getItem, it looks good to me too, and it's great to finally have a (correct) solution to retrieve these informations :D

@hkraal
Copy link
Contributor Author

hkraal commented Jul 28, 2016

Yeah, the lack of information when the cache in CREST is expiring is really just to bad. I hope they will implement it through the Cache-Control header which adjusts itself as time passes by, if that would happen we would pick it up and process it without any change.

@wtfrank
Copy link
Contributor

wtfrank commented Jul 28, 2016

oh god so CREST always gives the same validity period, and you don't even know when the data truly expires?

@hkraal
Copy link
Contributor Author

hkraal commented Jul 28, 2016

Uhuh, which makes the data for now worth very little but that should hopefully change in the future :)

@jonobrien
Copy link
Contributor

jonobrien commented Jul 28, 2016

@wtfrank about your response to my xml comment, seems fine, was just curious about use case/scope-creep 👍 no worries

it may be possible to jury-rig something together to know how long ccp caches for internally andthen only requery after certain intervals are met with regards to cache timers locally as well.

@coveralls
Copy link

coveralls commented Jul 29, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling a663e25 on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@wtfrank
Copy link
Contributor

wtfrank commented Jul 29, 2016

As far as I know, each endpoint has the same format mime type with just varying numbers. If that's true then I reckon we can return the entire version string but also try and parse out the version number and return that also, because its less hassle checking the version against a number, than having to look up the exact string to paste into your code.

@hkraal
Copy link
Contributor Author

hkraal commented Jul 29, 2016

Changed so you can reuse the string (in manipulated form) to request a specific version. As each endpoint has it's unique identifier just a number is not enough info:

>>> eve()['version']
5 # Before
'application/vnd.ccp.eve.Api-v5' # Now

What I'm getting at is this:

>>> eve()['version']
'application/vnd.ccp.eve.Api-v5'
>>> eve().time()['version']
'application/vnd.ccp.eve.Time-v1'
>>> eve().incursions()['version']
'application/vnd.ccp.eve.IncursionCollection-v1'

@wtfrank
Copy link
Contributor

wtfrank commented Jul 29, 2016

Ah ok that's a shame. It would still be parseable in this response part, but it wouldn't be easy to set it from a number in the request part, as it would require knowledge of each endpoint.

So I agree with that change :)

@jonobrien
Copy link
Contributor

ah I did not know the header string was actually different, unfortunate, but ok.

@wtfrank
Copy link
Contributor

wtfrank commented Jul 29, 2016

Do you think we should pass the meta info down the chain when navigating to a sub-section of the json?

>>> eve().regions().items[90]().constellations[0]()['version']
'application/vnd.ccp.eve.Constellation-v1'
>>> eve().regions().items[90]().constellations[0]().position['version']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pycrest/eve.py", line 478, in __getitem__
    raise AttributeError(item)
AttributeError: version

@jonobrien
Copy link
Contributor

jonobrien commented Jul 29, 2016

if you want specific info about the endpoint then it should be ok at the root, I don't see any uses for it to be needed when interacting with response data.

unless constellations is a different endpoint than regions? You should have it at every endpoint but not when you're doing the response items parsing, unless it really doesn't matter?

@coveralls
Copy link

coveralls commented Jul 29, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling da6680c on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@hkraal
Copy link
Contributor Author

hkraal commented Jul 29, 2016

Next stop would be for me to fix up the other methods like POST, PUT, DELETE. Not sure if those need adjusting but I would think they do.

@coveralls
Copy link

coveralls commented Jul 29, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling cead3b3 on hkraal:7-add-extra-request-information-attempt-2 into e8c86e2 on pycrest:master.

@wtfrank
Copy link
Contributor

wtfrank commented Jul 31, 2016

Regarding fixing up post/put/delete, they aren't returning any data so maybe they don't need anything doing? Or was it not the return data that you meant by fixing them up?

@hkraal
Copy link
Contributor Author

hkraal commented Aug 1, 2016

Well they do return a request.Response object and thus have a status_code for example. I was planning on treating each request equally; with the return of a APIResponse object.

@jonobrien
Copy link
Contributor

are we sure that response header is just telling you which endpoint you are reaching? it may just accept the single apiVxx headers from client requests.

@hkraal
Copy link
Contributor Author

hkraal commented Aug 2, 2016

No I'm not sure, maybe sending "v2" is enough and does work. This however doesn't mean we should take a shortcut which isn't documented. In the docs it states that it should be passed as a whole and thus that's the only correct thing to do.

Quote from the docs about Versioning

In order to ensure that you always receive this version, you simply need to add this header to your POST (ignore the charset for versioning):

Accept: application/vnd.ccp.eve.Api-v3+json

If you need version 2 of this resource, you can send this header instead:

Accept: application/vnd.ccp.eve.Api-v2+json

@Kyria
Copy link
Contributor

Kyria commented Aug 2, 2016

Actually, CREST will always accept "vnd.ccp.eve.Api-vXX+json" as it's the base version of all type. But instead of specifying "vnd.ccp.eve.Api-v5+json" you may also use "market-v1" (it's just for the example), but in the Content-Type, in the response, you'll have the "real" type (market-v1 and not api-v5) (so far it's what I observed, didn't find any doc about it).

In terms of response for POST/PUT call, it depends on which endpoint you are using. For example, if you use the contact endpoint, in the response you have the url for the newly added contact in the Location header. You may also have something in the other you can "put" (autopilot routes, fits). For DELETE, i don't really know..

@jonobrien
Copy link
Contributor

@Kyria thanks, makes sense.

@hkraal you would need the whole string but @Kyria clarified endpoints individually.

@wtfrank
Copy link
Contributor

wtfrank commented Aug 4, 2016

Regarding post/put/delete, according to https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html both put and delete are not cacheable, and post is not cacheable unless there is appropriate Cache-Control or Expires header fields. So a question arises: does it make sense to always expose 'expires' and the other cache related properties if its a response to one of those methods? And if it does, is the logic in the _get_expires() correct when it comes to the non-cacheable methods? (I'm thinking, what if there is a cache-control header on the response from put/delete?)

@hkraal
Copy link
Contributor Author

hkraal commented Aug 5, 2016

I'm not considering if for caching purposes (obviously) but for handling other properties like status_code or perhaps the requests.Response.elapsed property to see how long a request has taken. Another example would be when you add an new contact the URL to the new contact can be found in the response headers, data I think one would like to be accessible. The APIResponse object could allow access to this all

@wtfrank
Copy link
Contributor

wtfrank commented Aug 5, 2016

Do we need a subclass of the APIResponse object that contains caching properties, leaving the status_code and headers and stuff in the base class?

Or should expiry etc return AttributeError or something like that if its not a cached response?

Or is returning 0 or None for cache-related properties ok?

@jonobrien
Copy link
Contributor

I would say return a value or boolean for it not being cached, but that's just because I don't like try,catch in my code except for debugging. more communication is better I think.

@wtfrank
Copy link
Contributor

wtfrank commented Aug 17, 2016

Fair enough - throwing exceptions should probably be an exception, not the normal way you found out if something was cached or not!

subclass - might be a bit overengineering it.

so something like 0 or None is prob fine for the non-relevant methods !

@jonobrien
Copy link
Contributor

probably None so that 0 is not confused as a time or offset.

@hkraal hkraal force-pushed the 7-add-extra-request-information-attempt-2 branch from ee4ef74 to 86fdad4 Compare September 20, 2016 06:06
@coveralls
Copy link

coveralls commented Sep 20, 2016

Coverage Status

Coverage decreased (-1.2%) to 98.777% when pulling 86fdad4 on hkraal:7-add-extra-request-information-attempt-2 into 9b541ec on pycrest:master.

@hkraal hkraal closed this Aug 25, 2017
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.

5 participants