hrbrmstr / curlconverter

:curly_loop: :arrow_right: :heavy_minus_sign: Translate cURL command lines into parameters for use with httr or actual httr calls (R)
http://rud.is/b/2016/02/10/craft-httr-calls-cleverly-with-curlconverter/
Other
91 stars 12 forks source link

Problem passing user_key header arg #4

Closed stephlocke closed 8 years ago

stephlocke commented 8 years ago

Heya Bob, Just giving this a whirl with a curl command that works (tested in commandline) but I'm getting an error when attempting to convert. If I remove the user_key component it doesn't error.

Code

library(curlconverter)
curlCMD<-"curl -v -X GET 'https://api.owler.com/v1/company/basicsearch?q=facebook&fields=name&format=json' -H 'user_key:XXXXX' -k"
res <- make_req(straighten(curlCMD))

Results on my machine

> library(curlconverter)
> 
> curlCMD<-"curl -v -X GET 'https://api.owler.com/v1/company/basicsearch?q=facebook&fields=name&format=json' -H 'user_key:XXXXX' -k"
> res <- make_req(straighten(curlCMD))
curl -v -X GET 'https://api.owler.com/v1/company/basicsearch?q=facebook&fields=name&format=json' -H 'user_key:XXXXX' -k
Error: TypeError: Object user_key:XXXXX has no method 'forEach'
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] curlconverter_0.6.6.9000

loaded via a namespace (and not attached):
 [1] clipr_0.2.0     httr_1.1.0      magrittr_1.5    R6_2.1.2        formatR_1.2.1   tools_3.2.3    
 [7] curl_0.9.5      Rcpp_0.12.3     V8_0.10         stringi_1.0-1   jsonlite_0.9.19 purrr_0.2.1 
hrbrmstr commented 8 years ago

awesome! (yes a bug like this is awesome) thx.

I came across another one yesterday, too (weird $ where I didn't think it was legal). This helps alot since I knew there'd be "edge" cases but hadn't run across many.

stephlocke commented 8 years ago

You can have faith in me when it comes to finding edge cases :+1:

Thanks for picking this up so quickly!

hrbrmstr commented 8 years ago

So, I'm guessing this wasn't a "Copy as cURL" URL (i.e. from a browser), but a regular cURL command line, correct?

I'll have to peek at the JS library I use with V8 to see why it's not liking it (it's a problem with that library, not the R side. ugh. javascript.

hrbrmstr commented 8 years ago

omgosh they made an assumption that there would always be more than one -H. This slightly modified cmdline works:

curlCMD <- "curl -v -X GET 'https://api.owler.com/v1/company/basicsearch?q=facebook&fields=name&format=json' -H 'Origin: https://www.owler.com'  -H 'user_key:XXXXX' -k"

this also means it'll be (prbly) be a quick fix.

stephlocke commented 8 years ago

Great - I also have a nice workaround then for the interim :-) Cheers

and for background - the owler docs allow you to test the api and it gives you a request url and a curl command https://developers.owler.com/docs#!/CompanyAPI/basicCompanySearch

hrbrmstr commented 8 years ago

Give it a go when you get a change. It worked on that test URL and I added that test URL to the test suite. Thx for this!

stephlocke commented 8 years ago

Works! Thank you for the package and the swift turnaround on this :-D