Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

About the etag in fetchUserEvents #3

Open
Tangdixi opened this issue Jul 6, 2016 · 2 comments
Open

About the etag in fetchUserEvents #3

Tangdixi opened this issue Jul 6, 2016 · 2 comments

Comments

@Tangdixi
Copy link

Tangdixi commented Jul 6, 2016

Sorry to bother you again @onmyway133 馃槗
This method is return an Observable<[Events]> (transform from Observable<Response>)

  public func fetchUserEvents(etag: String? = nil,
                              offset: Int = 0, perPage: Int = Constant.defaultPerPage) -> Observable<[Event]> {
    if !isAuthenticated {
      return Observable<[Event]>.error(Error.authenticationRequiredError())
    }

    let requestDescriptor: RequestDescriptor = construct {
      $0.path = "users/\(user?.login ?? "")/received_events"
      $0.offset = offset
      $0.perPage = perPage
      $0.etag = etag
    }

    return enqueue(requestDescriptor).map {
      return Parser.all($0)
    }
  }

So how can I fetch the etag .....

@onmyway133
Copy link
Owner

@Tangdixi Hi, no problem. I'm here to help 馃槃

What do you mean by "fetch the etag"?

@Tangdixi
Copy link
Author

Tangdixi commented Jul 7, 2016

Just like this scene:
I perform a fetchUserEvents request when I run my App at the first time.
Here, I suppose I need to store the etag from the Response and use it in fetchUserEvents next time, right?
I dig deep into the source code, found the etag is defined in Response.swift:

public class Response {

  // .....

  // The etag uniquely identifying this response data.
  public var etag: String {
    return urlResponse.allHeaderFields["ETag"] as? String ?? ""
  }

  // .....
}

But the fetchUserEvents method is return a Observable<[Event]>, not a Observable<Response>. So I can't find a way to get the etag ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants