2
6 Comments

Are my Ruby and Python code samples ok?

Hello Indie Hackers!

Not being a ruby or python developer, I was wondering you could confirm if my code samples are ok?

Thank you in advance!

https://docamatic.com/documentation#quick-start

on January 4, 2020
  1. 2

    I only checked Ruby but I think it would be better to use the standard library rather than making developers install a 3rd party http gem. Something like:

    require 'net/https'
    require 'uri'
    require 'json'
    
    uri = URI('https://docamatic.com/api/v1/pdf')
    response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
      request = Net::HTTP::Post.new(uri)
      request.content_type = 'application/json'
      request['Authorization'] = "Bearer #{ENV['DOCAMATIC_API_KEY']}"
      request.body = JSON.generate(
        'source': 'https://news.ycombinator.com',
        'format': 'A4',
        'media': 'print'
      )
    
      http.request(request)
    end
    
    puts response.body
    
    1. 1

      Hey thanks so much for taking the time to put this together. I have used your code sample! cheers

  2. 1

    in python, i suggest f-strings

    f"Bearer {os.getenv('DOCAMATIC_API_KEY')}"
    
    1. 1

      This comment was deleted 6 years ago

      1. 2

        no it won't but python 2.7 aint supported anymore lol

  3. 1

    I would like to look at your Python code but I didn't find any at the page you gave :-\

  4. 2

    This comment was deleted 6 years ago

    1. 1

      Awesome thanks!