Module: Kinja::Post

Included in:
Client
Defined in:
lib/kinja/post.rb

Instance Method Summary collapse

Instance Method Details

#create_post(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kinja/post.rb', line 8

def create_post(opts={})
  token = get_api_token()

  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: [],
      token: token
    }.to_json,
    headers: {
      'content-type' => 'application/json'
    }
end

#get_post(link_or_id) ⇒ Object



3
4
5
6
# File 'lib/kinja/post.rb', line 3

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

#update_post(link_or_id, opts) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kinja/post.rb', line 33

def update_post(link_or_id, opts)
  token = get_api_token()

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