Sha256: 3f083e9186602d756e5e508b1a1b9d4eb1e988a303c54825233d57e7f0460a1f

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

require "net/https"
require "json"
require "open-uri"
require "io/console"
require "colorize"
require "qiita_org/set_config.rb"
require "qiita_org/error_message.rb"
require "qiita_org/access_qiita.rb"

class GetFileUrl
  def initialize(id, file, mode)
    @id = id
    @file = file
    @mode = (mode == "qiita" || mode == "open")? "public" : mode
    @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
    if @mode == "teams"
      ErrorMessage.new().teams_url_error(@teams_url)
    end
  end

  def get_file_url()
    qiita = (@mode == "teams")? @teams_url : "https://qiita.com/"
    path = "api/v2/items/#{@id}"

    items = AccessQiita.new(@access_token, qiita, path).access_qiita()

    file_url = items["body"].match(/\!\[#{@file}\]\(((.+))\)/)[2]
    return file_url

    #File.write("url_text.md", items["body"])
  end

=begin
  def access_qiita(access_token, qiita, path)
    uri = URI.parse(qiita + path)

    headers = { "Authorization" => "Bearer #{access_token}",
                "Content-Type" => "application/json" }

    response = URI.open(
      "# {uri}",
      "Authorization" => "# {headers["Authorization"]}",
    )
    items = JSON.parse(response.read)
    return items
  end
=end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
qiita_org-0.2.2 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.2.1 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.41 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.40 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.39 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.38 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.37 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.35 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.34 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.33 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.32 lib/qiita_org/old_programs/get_file_url.rb
qiita_org-0.1.31 lib/qiita_org/get_file_url.rb
qiita_org-0.1.30 lib/qiita_org/get_file_url.rb
qiita_org-0.1.29 lib/qiita_org/get_file_url.rb
qiita_org-0.1.28 lib/qiita_org/get_file_url.rb