Reputation: 81
I am calling the circle.so api using ruby on a rails on a code that I got from postman.
require "uri"
require "net/http"
url = URI("hub.atlas.fm/api/v1/community_members")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["Authorization"] = "phdbM12mVAiEyLF19UjoYdiU"
response = http.request(request)
puts response.read_body
While working perfectly in postman, It does not work on my app, with an error of
ArgumentError in TopicsController#index
not an HTTP URI
How do I solve this?
Upvotes: 0
Views: 2136
Reputation: 8646
You will need to specify http://
in your url string
url = URI("http://hub.atlas.fm/api/v1/community_members")
If you ommit the scheme (http://) part, then ruby does not know what specific URI type this is.
2.6.3 :005 > url = URI("hub.atlas.fm/api/v1/community_members")
=> #<URI::Generic hub.atlas.fm/api/v1/community_members>
But if you specify the scheme (http://) then you'll get
2.6.3 :003 > url = URI("http://hub.atlas.fm/api/v1/community_members")
=> #<URI::HTTP http://hub.atlas.fm/api/v1/community_members>
Note the different class (URI::Generic
vs. URI::HTTP
).
There are many other types of URI, e.g.:
2.6.3 :007 > url = URI("file://hub.atlas.fm/api/v1/community_members")
=> #<URI::File file://hub.atlas.fm/api/v1/community_members>
2.6.3 :008 > url = URI("ftp://hub.atlas.fm/api/v1/community_members")
=> #<URI::FTP ftp://hub.atlas.fm/api/v1/community_members>
You can find more here: https://ruby-doc.org/stdlib-2.7.2/libdoc/uri/rdoc/URI.html
Upvotes: 2