Class: ZendeskArticle
- Inherits:
-
Object
- Object
- ZendeskArticle
- Defined in:
- lib/zentool/zendesk_article.rb
Overview
Interface with zendesk to access articles
Instance Method Summary collapse
- #articles ⇒ Object
- #basic_auth ⇒ Object
- #categories ⇒ Object
- #check_auth ⇒ Object
- #export_columns ⇒ Object
-
#initialize(username, password, domain) ⇒ ZendeskArticle
constructor
A new instance of ZendeskArticle.
- #raw_articles ⇒ Object
- #raw_categories ⇒ Object
- #raw_sections ⇒ Object
- #sections ⇒ Object
Constructor Details
#initialize(username, password, domain) ⇒ ZendeskArticle
Returns a new instance of ZendeskArticle.
4 5 6 7 8 9 10 11 |
# File 'lib/zentool/zendesk_article.rb', line 4 def initialize(username, password, domain) @root_uri = "https://#{domain}.zendesk.com/api/v2/help_center/en-us/" @articles_uri = @root_uri + 'articles.json' @sections_uri = @root_uri + 'sections.json' @categories_uri = @root_uri + 'categories.json' @username, @password = username, password check_auth end |
Instance Method Details
#articles ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zentool/zendesk_article.rb', line 13 def articles @articles ||= begin = ProgressBar.create(title: "#{raw_articles['count']} Articles", starting_at: 1, format: '%a |%b>>%i| %p%% %t', total: raw_articles['page_count']) articles = raw_articles['articles'] (raw_articles['page_count'] - 1).times do |page| .increment articles += HTTParty.get("#{@articles_uri}?page=#{page + 2}", basic_auth)['articles'] end end articles end |
#basic_auth ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/zentool/zendesk_article.rb', line 68 def basic_auth { basic_auth: { username: @username, password: @password } } end |
#categories ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zentool/zendesk_article.rb', line 39 def categories @categories ||= begin = ProgressBar.create(title: "#{raw_categories['count']} Categories", starting_at: 1, format: '%a |%b>>%i| %p%% %t', total: raw_categories['page_count']) categories = raw_categories['categories'] (raw_categories['page_count'] - 1).times do |page| .increment categories += HTTParty.get("#{@categories_uri}?page=#{page + 2}", basic_auth)['categories'] end end categories end |
#check_auth ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/zentool/zendesk_article.rb', line 77 def check_auth response = HTTParty.get(@sections_uri, basic_auth) unless response.code == 200 puts "Error #{response.code}: #{response.}" abort end end |
#export_columns ⇒ Object
64 65 66 |
# File 'lib/zentool/zendesk_article.rb', line 64 def export_columns %w(id category section title word_count draft promoted outdated html_url created_at updated_at) end |
#raw_articles ⇒ Object
52 53 54 |
# File 'lib/zentool/zendesk_article.rb', line 52 def raw_articles @raw_articles ||= HTTParty.get(@articles_uri, basic_auth) end |
#raw_categories ⇒ Object
60 61 62 |
# File 'lib/zentool/zendesk_article.rb', line 60 def raw_categories @raw_sections ||= HTTParty.get(@categories_uri, basic_auth) end |
#raw_sections ⇒ Object
56 57 58 |
# File 'lib/zentool/zendesk_article.rb', line 56 def raw_sections @raw_sections ||= HTTParty.get(@sections_uri, basic_auth) end |
#sections ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zentool/zendesk_article.rb', line 26 def sections @sections ||= begin = ProgressBar.create(title: "#{raw_sections['count']} Sections", starting_at: 1, format: '%a |%b>>%i| %p%% %t', total: raw_sections['page_count']) sections = raw_sections['sections'] (raw_sections['page_count'] - 1).times do |page| .increment sections += HTTParty.get("#{@sections_uri}?page=#{page + 2}", basic_auth)['sections'] end end sections end |