Sha256: 73434a3a83758b4ddc044f94521495bf0fd9aa65ac95e7c9bfb5539d1ed07471

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

require 'rest-client'

module Gram
  module Blog
    class << self

      def run(*args)
        file = args.first
        raise "File #{file} does not exist." unless File.exists?(file)
        puts "Gram::Blog posting..."
        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

      private

      def get_token
        if File.exists?(File.join(File.expand_path('~'), '.gramrc'))
          YAML.load(File.read(File.join(File.expand_path('~'), '.gramrc')))["token"]
        else
          puts "Can't get Gram token. Please create a ~/.gramrc YAML file with a token key."
          exit(1)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gram-0.0.1 lib/gram/blog.rb