Sha256: 451904295834c4bdafbb5f1935807cf6211bb7b08eac0ed71335fb355b8f00c6

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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={})
      token = get_api_token(login)

      puts "Trying to create post with token: #{token}"

      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' => token
        }
    end

    def update_post(link_or_id, opts)
      token = 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' => token
        }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kinja-0.0.22 lib/kinja/post.rb