Class: QiitaExport::Comment
- Inherits:
-
Object
- Object
- QiitaExport::Comment
- Defined in:
- lib/qiita-export/comment.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #filename ⇒ Object
- #find_comments ⇒ Object
-
#initialize(url) ⇒ Comment
constructor
A new instance of Comment.
- #request_header ⇒ Object
- #save(path) ⇒ Object
Constructor Details
#initialize(url) ⇒ Comment
Returns a new instance of Comment.
9 10 11 12 |
# File 'lib/qiita-export/comment.rb', line 9 def initialize(url) @endpoint = Fetcher::ApiEndPoint.instance(:comment) @url = url end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/qiita-export/comment.rb', line 7 def key @key end |
Instance Method Details
#filename ⇒ Object
18 19 20 |
# File 'lib/qiita-export/comment.rb', line 18 def filename "comments.json" end |
#find_comments ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/qiita-export/comment.rb', line 32 def find_comments url = @endpoint.url(article_url: @url) open(url, request_header) do |io| io.read end rescue => e $stderr.puts "#{e} : #{url}" raise end |
#request_header ⇒ Object
14 15 16 |
# File 'lib/qiita-export/comment.rb', line 14 def request_header Config.has_api_token? ? Config.auth_header : Config.default_header end |
#save(path) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/qiita-export/comment.rb', line 22 def save(path) comments = find_comments return if comments =~ /^\[\]$/i file_path = File.join(File.(path), filename) open(file_path, 'wb') do |out| out.write(comments) end end |