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

Feature/uri #11

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open

Feature/uri #11

wants to merge 17 commits into from

Conversation

brandonphelps
Copy link
Owner

@brandonphelps brandonphelps commented Jan 16, 2021

Goal here is to provide a center for all end points and a builder for end points.

Not all the end points are flushed out and some of the builder needs the ability to join end points together. however if far enough to be useful for some of the endpoints and I'll be looking to integrate the api key thing.

Copy link
Collaborator

@alexFickle alexFickle left a comment

Choose a reason for hiding this comment

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

In general things really need their intent documented.

src/uri.rs Outdated
// should be usize?

// todo: move this to some types thing?
pub struct ItemId(pub u128);
Copy link
Collaborator

Choose a reason for hiding this comment

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

u128 is really overkill for this. All of these will fit in a u32.

I'm working on a sqlite3 caching feature and it does not support u128 or (currently) u64 as keys.

Copy link
Owner Author

Choose a reason for hiding this comment

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

yeah i'm up for w/e the size should be, didn't really see anything on the wiki that specified an upper limit.
I doubt we'd need 128 sized items, but would be cool to have the caching support it imo

src/uri.rs Outdated
pub struct ApiKey(pub String);
pub struct AchievementId(pub u128);

#[allow(non_camel_case_types)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should remove this and fix the name of all enum variants that are triggering this warning. We should be following the default Rust style guides.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm, yeah initially I was hoping for some sort of macro solution that could work on the names of the enumed items. ie. account_materials would resolve to account/materials or something. using snake seemed easier to me to implement such a thing, granted the value in determining such a system might not be worth it.

}

#[derive(Deserialize, Debug)]
struct ItemDetails {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it has the additional item attributes that only armor has. Not all items will have this. ItemDetails should probably be a sum type based on the item type. Something like

enum ItemDetails {
    Armor(ArmorDetails),
    Weapons(WeaponDetails),
    // etc...
}

This does not seem needed for this feature anyway, so should probably be deleted. Even if we are going to be deserializing items to test the URI building we do not need to fully test the complicated data model.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think it should be deleted as that sounds like its throwing away work. These are here as a implementation for what the api could be.
I think at some point they'd be moved into a models.rs section that would contain the deserialized types from the api.

I do agree that the format should be better suited like you are indicating.

details: ItemDetails,
}

// should be usize?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using usize for values coming from a web API is iffy to me. Introduces different platforms treating the same data slightly differently for no real compelling reason.

Copy link
Owner Author

Choose a reason for hiding this comment

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

ah sure, this was here as a question of not really know what the range of values from the api would be returned as.

src/uri.rs Outdated
@@ -0,0 +1,261 @@
#![allow(dead_code)]

use reqwest;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Per the build output this import is not used. Delete.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Its currently used within the tests, so i'll move it there.


pub struct Requester {
version: ApiVersion,
api_key: Option<ApiKey>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This attribute is currently unused.

Also I have some use cases where I will be requesting data from many different users. Making a Requester per api key may be kinda odd. Really depends on the goal of this type.

If a publicly facing (Rust) API requires an API key I'd prefer that it explicitly takes it as a parameter (and also documents the permission requirements). An optional API key in a requester seems like we will be making requesters per request (which eliminates the potential value add of injecting the base_uri) or we will be sneaking a Option<ApiKey> through all of our code, potentially doing the wrong thing.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Could you expand on how have a Reqeuster per api key seems odd? That seem normal to me, as the binding of a Requester to the api key allows for building uris for that specific key.

I picture a sort of API builder that constructs apis based on conveniently provided input from the user, having to have the user specify their api key on each request sounds cumbersome to me, hence the key can be stored within the Requester type.

Its ment as optional due to not all the api end points require authentication and thus this is to allow for a user to request api end points that do not require authentication.

Sounds like you are suggesting to go towards a compile time check of api key and its permissions per end point? That sounds good me. Not certain what you mean by potentially doing the wrong thing though.

}
}

pub struct Requester {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This type is named Requester yet makes no requests. What is the goal of this type? It should be documented so it can be discussed.

Currently it seems that this type may not be needed. The only value of its state is specifying a different base url or API version. The base url may have some value, especially for testing. Although to me it makes more sense that the dependency injection happen at a much higher layer then uri building. The API version will never be changeable without huge changes to the library (assuming that a new version of the API ever happens).

If eventually it will be making requests then indicate so. There is a lot of design work to talk about in this area.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Could you elaborate on the dependency injection statement? What dependency are you talking about the base url? I'd picture that the version if accounted for in the beginning of the libraries design would mean that there would be little to zero library changes.

I do doubt they'll change the versions however.
The documentation is certainly needed along with the intents, no doubt bout that.


// these item structs should be namespaced into the v2 api.
#[derive(Deserialize, Debug)]
struct ItemAttribute {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of these Item types are not publicly accessible or used in non-test code. If these are intended for testing then they should be moved to the testing module. However, testing URI building does not really require fully testing the deserialization of the received data.

Copy link
Owner Author

@brandonphelps brandonphelps Jan 17, 2021

Choose a reason for hiding this comment

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

Yeah, I can see moving them into the testing section.
And yeah they aren't directly needed for testing uri building, but it certainly cooler, to actually see data be returned and deserialized, also helps with my understanding of how the libraries interact which each other. I picture the final tests for the building of uris will not be making requests from the server or need the server at all.

pub struct AchievementId(pub u128);

#[allow(non_camel_case_types)]
pub enum EndPoint {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documentation? What is the goal of this type. Is it to exactly model the gw2 API URIs? Is it to be the Requestor's request interface? Depending on the answer I'd recommend different design changes.

Copy link
Owner Author

@brandonphelps brandonphelps Jan 17, 2021

Choose a reason for hiding this comment

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

The basics is that its to capture all of the different end points of the gw2 api as well any helpeful information about each of the end points. note the functions for getting the uri strings as well as information like if authentication is required. With the additions of the various api keys i'd imagen it would also return out the required permissions per api end point or have a compiled time checked api for if a specific key is okay to be used for that end point. I'm also looking to have this provide utility functions for bundling batches of requests into a single request.
Such as
item1 = items/1, item2 = items/2 then if a request wants say [item1, item2] this is distilled into a single request to the server rather than 2, then the items are returned as expected maintain a 1 to 1 return.

src/uri.rs Outdated Show resolved Hide resolved
brandon phelps added 2 commits January 17, 2021 10:24
switched the enum types to rust type format standards
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