Class: ZenPush::Runner

Inherits:
Boson::Runner
  • Object
show all
Defined in:
lib/zenpush/runner.rb

Instance Method Summary collapse

Instance Method Details

#categories(options = {}) ⇒ Object



9
10
11
# File 'lib/zenpush/runner.rb', line 9

def categories(options = {})
  ap ZenPush.z.categories
end

#exists?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/zenpush/runner.rb', line 26

def exists?(options = {})
  category_name, forum_name, topic_title = ZenPush.file_to_category_forum_topic(options[:file])
  topic = ZenPush.z.find_topic(category_name, forum_name, topic_title)
  ap !!topic
end

#forums(options = {}) ⇒ Object



14
15
16
# File 'lib/zenpush/runner.rb', line 14

def forums(options = {})
  ap ZenPush.z.forums
end

#push(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zenpush/runner.rb', line 35

def push(options = {})
  category_name, forum_name, topic_title = ZenPush.file_to_category_forum_topic(options[:file])

  topic_body =
    if options[:file].end_with?('.md') || options[:file].end_with?('.markdown')
      ZenPush::Markdown.to_zendesk_html(options[:file], options[:flavor])
    else
      File.read(options[:file])
    end

  topic = ZenPush.z.find_topic(category_name, forum_name, topic_title)
  if topic
    # UPDATE THE TOPIC
    ap ZenPush.z.put_topic(topic['id'], topic_body)
  else
    forum = ZenPush.z.find_or_create_forum(category_name, forum_name)
    if forum
      # CREATE THE TOPIC
      ap ZenPush.z.post_topic(forum['id'], topic_title, topic_body)
    else
      ap "Could not find a forum named '#{forum_name}' in the category '#{category_name}'"
      exit(-1)
    end
  end
end

#topics(options = {}) ⇒ Object



20
21
22
# File 'lib/zenpush/runner.rb', line 20

def topics(options = {})
  ap ZenPush.z.topics(options[:forum_id])
end