Sha256: 8efd9beaefb43088e2beaf7565011681fb1f16d72e33045db32ed13ac668e1db

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Kinja
  module Post
    def get_post(link_or_id)
      id = get_post_id link_or_id
      HTTParty.get post_path(id)
    end

    def create_post(opts={})
      get_api_token(login)
      opts[:status] = opts[:status] || "DRAFT"
      opts[:replies] = opts[:replies] || false
      opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)

      puts opts
      HTTParty.post create_post_path,
        body: {
          headline: opts[:headline],
          body: opts[:body],
          defaultBlogId: opts[:defaultBlogId],
          status: opts[:status],
          allowReplies: opts[:replies],
          tags: []
        }.to_json,
        headers: {
          'content-type' => 'application/json',
          'token' => @api_token
        }
    end

    def update_post(link_or_id, opts)
      get_api_token(login)

      id = get_post_id link_or_id
      opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)
      HTTParty.post update_post_path(id),
        body: opts.to_json,
        headers: {
          'Content-Type' => 'application/json',
          'token' => @api_token
        }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kinja-0.0.21 lib/kinja/post.rb
kinja-0.0.20 lib/kinja/post.rb