Module: Gram::Blog
- Defined in:
- lib/gram/blog.rb,
lib/gram/blog/parser.rb
Defined Under Namespace
Modules: Parser
Constant Summary collapse
- ACTIONS =
{ upload: { description: "Uploads the markdown file with filename FILE", arguments: %w(FILE), }, download: { description: "Downloads all blog posts to the current folder.", arguments: %w(), } }
Class Method Summary collapse
Class Method Details
.banner ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gram/blog.rb', line 19 def out = "Available actions:\n" ACTIONS.each_pair do |action, | out << "\n\t#{action} #{[:arguments].join(' ')}\t\t#{[:description]}" end out end |
.download ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gram/blog.rb', line 38 def download posts = JSON.parse(RestClient.get("http://codegram.com/api/posts?token=#{get_token}")) posts.each do |post| post = post["post"] header = """ --- title: #{post["title"]} tagline: #{post["tagline"]} --- """.strip puts "Downloading #{post["cached_slug"]}.markdown..." File.open("#{post["cached_slug"]}.markdown", 'w') do |f| f.write header f.write "\n\n" f.write post["body"] f.write "\n" end end end |
.upload(file) ⇒ Object
ACTIONS
29 30 31 32 33 34 35 36 |
# File 'lib/gram/blog.rb', line 29 def upload(file) raise "File #{file} does not exist." unless File.exists?(file) puts "Gram::Blog uploading..." post = Parser.parse(file) response = RestClient.post("http://codegram.com/api/posts", token: get_token, post: post ) puts "Response Code: #{response.code}" puts "Response Body: #{response.body}" end |