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

Fix example in docs #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix example in docs #132

wants to merge 1 commit into from

Conversation

optix2000
Copy link

The docs give this snippet of code as an example of how to use the library.

require 'net/http/persistent'

uri = URI 'http://example.com/awesome/web/service'

http = Net::HTTP::Persistent.new

# perform a GET
response = http.request uri

# or

get = Net::HTTP::Get.new uri.request_uri
response = http.request get

# create a POST
post_uri = uri + 'create'
post = Net::HTTP::Post.new post_uri.path
post.set_form_data 'some' => 'cool data'

# perform the POST, the URI is always required
response http.request post_uri, post

However this code doesn't actually run.

Shortening the example to just the problem area:

require 'net/http/persistent'

uri = URI 'http://example.com/awesome/web/service'

http = Net::HTTP::Persistent.new

get = Net::HTTP::Get.new uri.request_uri
response = http.request get

gives

Traceback (most recent call last):
        2: from test.rb:8:in `<main>'
        1: from /foo/vendor/bundle/ruby/2.7.0/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:881:in `request'
/usr/lib/ruby/2.7.0/uri/common.rb:739:in `URI': bad argument (expected URI object or URI string) (ArgumentError)

As the example doesn't pass the URI as the first argument.

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.

1 participant