Skip to content

Instantly share code, notes, and snippets.

@mmcdaris
Last active February 4, 2016 21:38
Show Gist options
  • Save mmcdaris/65775619531724ef8e05 to your computer and use it in GitHub Desktop.
Save mmcdaris/65775619531724ef8e05 to your computer and use it in GitHub Desktop.
Export all your tender docs as markdown
# Exports tender knowledge base as markdown files in the current directory
# Usage
# TenderKnowledgeBase.new(app_name, tender_token).markdown_export
#
class TenderKnowledgeBase
attr_accessor :api, :docs, :page
def initialize(tender_app, tender_token)
@api = RestClient::Resource.new("https://api.tenderapp.com/#{tender_app}",
headers: {
'Accept' => 'application/vnd.tender-v1+json',
'X-Tender-Auth' => tender_token
}
)
end
def markdown_export
@docs = []
page = 1
resp = docs_at_page(page)
total_pages = resp['total'] / 30
while page <= total_pages
docs_at_page(page)
page += 1
end
end
def docs_at_page(page)
resp = JSON.parse(@api['faqs'].get(params: {page: page}))
@docs += resp['faqs'].map {|doc| TenderDoc.new(doc).write_markdown_file }
resp
end
end
class TenderDoc
attr_accessor :title, :filename, :body, :raw
def initialize(doc)
@raw = doc
@title = @raw['title']
@body = @raw['body']
@filename = "#{@raw['permalink']}.markdown"
end
def write_markdown_file
puts "creating #{@filename}"
File.open(@filename, 'w') { |f| f.write @body }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment