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

Create script to fetch company data from stackshare api #1572

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

Conversation

Bhavika-Gianey
Copy link
Contributor

@Bhavika-Gianey Bhavika-Gianey commented Apr 28, 2021

Issue Description

In addition to the locally maintained lists, stackshare has a list of companies using OCaml
https://stackshare.io/ocaml
The issue is to generate a JSON file from the stackshare API.

Please include a summary of the issue.

Work in progress #1503

Changes Made

I tried to fetch data from the API but it is showing this error:

pp

Please describe the changes that you made.

  • Please check if the PR fulfills these requirements
  • PR is descriptively titled and links the original issue above
  • Before/after screenshots (if this is a layout change)
  • Details of which platforms the change was tested on (if this is a browser-specific change)
  • Context for what motivated the change (if this is a change to some content)

in
let uri = Uri.of_string uri in
let body =
`O [("query", `String query)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this piece of code doing?
and Why are we using Ezjsonm.to_string body if the above expression is already converting the query to string form.??

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this the json object is being constructed, so body is still an ezyjsonm type which is why you still need to convert body to a string type for sending the post request in line 38.

Also, if you do an opam install ocamlformat and run dune build @fmt --auto-promote . it will format the code so it's more legible. :)

@Bhavika-Gianey
Copy link
Contributor Author

Hii @patricoferris, can you please help me resolve this.

@patricoferris
Copy link
Contributor

As @gs0510 quite rightly mentioned Ezjsonm.to_string in converting our value to a JSON string, this can be transferred over the internet to the API.

I suggest having a play around with it in utop for example:

utop # Ezjsonm.to_string (`O ["hello", `String "world"]);;
- : string = "{\"hello\":\"world\"}"

Most GraphQL APIs (afaik) understand the body as a JSON object where they query is stored as a value associated with a key called query (there are other things you can add to like variables etc.) so that's what we're doing in that part of the code:

{
  "query": "query { ... }"
}

Also as a general rule it is pretty bad to commit API keys into any code. Other people could abuse it but the blame may come back to you since it is your API key. I don't think anyone here would do that of course, but just letting you know :)) You probably want to disable that API key and generate a new one.

@Bhavika-Gianey
Copy link
Contributor Author

Thanks, @gs0510, @patricoferris, I understood the use of Ezjsonm.to_string and I will generate a new API Key.
But I am still getting the error of no query string present.

pp. :((.

I think the error is caused due to the presence of arguments inside the query but I don't know how to resolve that. Plse kindly look into this and help me.

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.

3 participants