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

Failing to restore resource.rels[:x].get after marshal_load #53

Open
dazza-codes opened this issue Feb 3, 2018 · 1 comment
Open

Failing to restore resource.rels[:x].get after marshal_load #53

dazza-codes opened this issue Feb 3, 2018 · 1 comment

Comments

@dazza-codes
Copy link

dazza-codes commented Feb 3, 2018

Finding it difficult to restore functionality after serializing/deserialzing a Sawyer::Resource.

For example, starting with the github Octokit gem

repo = Octokit.repo('kubernetes/kubernetes');
repo.class #=> Sawyer::Resource

users = repo.rels[:contributors].get.data;
users.class #=> Array

dumped = Marshal.dump( repo.marshal_dump );
dumped.class #=> String

agent = Sawyer::Agent.new('https://api.github.com/', links_parser: Sawyer::LinkParsers::Simple.new)
resource = Sawyer::Resource.new(agent)
resource.marshal_load(Marshal.restore(dumped))
resource.class #=> Sawyer::Resource
resource.rels.class #=> Sawyer::Relation::Map
resource.rels[:contributors]
#=> #<Sawyer::Relation: contributors: get #<Addressable::Template:0x000055be59bf7030>>

resource.rels[:contributors].get
NoMethodError: undefined method `get' for nil:NilClass
Did you mean?  gets
               gem
from {HOME}/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sawyer-0.8.1/lib/sawyer/agent.rb:94:in `call'
dazza-codes added a commit to dazza-codes/github_crawl that referenced this issue Feb 3, 2018
- it's working with in-memory representations
  - persistence is disabled
- Sqlite persistence is possible, but the serializers are not working yet
  - see lostisland/sawyer#53
dazza-codes added a commit to dazza-codes/github_crawl that referenced this issue Feb 3, 2018
- it's working with in-memory representations
  - persistence is disabled
- Sqlite persistence is possible
  - using fixture JSON data:
    - the user serializer works with JSON serialization
    - the repo serializer works with JSON serialization
  - the Marshal serializer is not working as expected
    - see lostisland/sawyer#53
@technoweenie
Copy link
Member

That specific error is because the Sawyer::Agent has no Faraday::Connection in @conn. I haven't done anything to make sure Ruby can problem marshal and unmarshal Sawyer objects.

Have you considered using a custom Faraday middleware like VCR to cache requests?

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

No branches or pull requests

2 participants