Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

feat: query cookie by name #128

Closed

Conversation

criticalbh
Copy link
Contributor

Hello,

Here is the implementation of get cookie by name.

I know that in the API spec cookiesGet(name: string) should return Cookie | null but in different paths it is possible to have same name so I implemented it to return Cookie[] | null. However I would like to hear opinions from you and make changes on this PR.

Thanks,
Admir

Copy link
Contributor

@joelgriffith joelgriffith left a comment

Choose a reason for hiding this comment

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

Looks good!

Updated CHANGELOG.md with pull request reference.
Copy link
Collaborator

@adieuadieu adieuadieu left a comment

Choose a reason for hiding this comment

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

Hi @criticalbh Thank you for this PR! Small request: could you please also update the docs/api.md and API TOC in /README.md?

@joelgriffith @timsuchanek @schickling in this case, should we rename cookiesGet() to cookies()?

@criticalbh
Copy link
Contributor Author

criticalbh commented Aug 1, 2017

Yes, I will wait for decision if method should be renamed.

@joelgriffith
Copy link
Contributor

Yes, I agree on cookies acting as the "getter" by default

@@ -11,13 +11,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- CODE_OF_CONDUCT.md, CONTRIBUTING.md
- `getHtml()` and `setHtml()` APIs. [#112](https://github.com/graphcool/chromeless/pull/112), [#74](https://github.com/graphcool/chromeless/issues/74)
- `mousedown(selector: string): Chromeless<T>` and `mouseup(selector: string): Chromeless<T>` APIs [#118](https://github.com/graphcool/chromeless/pull/118) @criticalbh
- `cookiesGet(name: string)` [#128](https://github.com/graphcool/chromeless/pull/128) API @criticalbh
Copy link
Contributor

@joelgriffith joelgriffith Aug 2, 2017

Choose a reason for hiding this comment

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

Small change: method name is cookie it looks (and doesn't take any args)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as I could understand, if we want to take all cookies, we will use cookies getter, but if we are going to query via name or query object than we would use method cookiesGet(name | query)?

@@ -189,25 +189,28 @@ export default class Chromeless<T extends any> implements Promise<T> {
/**
* Get the cookies for the current url
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having a hard time understanding how this all works here (and even before). @timsuchanek or @adieuadieu I'd love to hear your feedback on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any update on this?

@adieuadieu adieuadieu added this to the v1.2 milestone Aug 3, 2017
@joelgriffith
Copy link
Contributor

So, thinking about this some more, I think this would makes sense:

chromeless.cookies() => returns all cookies for the URL
chromeless.cookies('_ga12345') => returns that specific cookie's value

@adieuadieu does that sound reasonable to you?

@@ -416,14 +416,14 @@ console.log(html) // <html><head></head><body><h1>Hello world!</h1></body></html

<a name="api-cookiesget" />

### cookiesGet(): Chromeless<Cookie[] | null>
### get cookies(): Chromeless<Cookie[] | null>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we don't need the word "get" here

@adieuadieu
Copy link
Collaborator

@joelgriffith yea that sounds good. So to reiterate, the various cookie methods become:

Cookies for the current URL:

  • cookiesGet(): Chromeless<Cookie[] | null> becomes cookies(): Chromeless<Cookie[] | null>
  • cookiesGet(name: string): Chromeless<Cookie | null> becomes cookies(name: string): Chromeless<Cookie | null>
  • cookiesGet(query: CookieQuery): Chromeless<Cookie[] | null> becomes cookies(query: CookieQuery): Chromeless<Cookie[] | null>

Also need to update this one:

All the cookies the browser has stored.
cookiesGetAll(): Chromeless<Cookie[]> becomes allCookies(): Chromeless<Cookie[]>

@criticalbh criticalbh closed this Aug 6, 2017
@criticalbh criticalbh deleted the feature/cookies-get-by-name branch August 6, 2017 13:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants