Module: Devcenter::Helpers
- Included in:
- Client, Commands::Base
- Defined in:
- lib/devcenter/helpers.rb
Instance Method Summary collapse
- #article_api_path(slug) ⇒ Object
- #article_path(slug) ⇒ Object
- #article_url?(url) ⇒ Boolean
- #broken_link_checks_path ⇒ Object
- #devcenter_base_url ⇒ Object
- #get_oauth_token ⇒ Object
- #html_file_path(slug) ⇒ Object
- #md_file_path(slug) ⇒ Object
- #netrc_path ⇒ Object
- #search_api_path ⇒ Object
- #slug_from_article_url(url) ⇒ Object
- #update_article_path(id) ⇒ Object
- #validate_article_path(id) ⇒ Object
- #write_file(filename, content) ⇒ Object
Instance Method Details
#article_api_path(slug) ⇒ Object
17 18 19 |
# File 'lib/devcenter/helpers.rb', line 17 def article_api_path(slug) "#{article_path(slug)}.json" end |
#article_path(slug) ⇒ Object
13 14 15 |
# File 'lib/devcenter/helpers.rb', line 13 def article_path(slug) "/articles/#{slug}" end |
#article_url?(url) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/devcenter/helpers.rb', line 33 def article_url?(url) escaped_base_url = devcenter_base_url.gsub('/','\\/') url.match(/\A#{escaped_base_url}\/articles\/.+/) true end |
#broken_link_checks_path ⇒ Object
9 10 11 |
# File 'lib/devcenter/helpers.rb', line 9 def broken_link_checks_path '/api/v1/private/broken-link-checks.json' end |
#devcenter_base_url ⇒ Object
5 6 7 |
# File 'lib/devcenter/helpers.rb', line 5 def devcenter_base_url ENV['DEVCENTER_BASE_URL'] || 'https://devcenter.heroku.com' end |
#get_oauth_token ⇒ Object
56 57 58 59 60 61 |
# File 'lib/devcenter/helpers.rb', line 56 def get_oauth_token netrc = Netrc.read(netrc_path) user, token = netrc['api.heroku.com'] abort 'Heroku credentials not found. Execute "heroku login" to create them.' unless token token end |
#html_file_path(slug) ⇒ Object
48 49 50 |
# File 'lib/devcenter/helpers.rb', line 48 def html_file_path(slug) File.("#{slug}.html") end |
#md_file_path(slug) ⇒ Object
44 45 46 |
# File 'lib/devcenter/helpers.rb', line 44 def md_file_path(slug) File.("#{slug}.md") end |
#netrc_path ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/devcenter/helpers.rb', line 63 def netrc_path default = Netrc.default_path encrypted = default + ".gpg" if File.exists?(encrypted) encrypted else default end end |
#search_api_path ⇒ Object
21 22 23 |
# File 'lib/devcenter/helpers.rb', line 21 def search_api_path "/articles.json" end |
#slug_from_article_url(url) ⇒ Object
39 40 41 42 |
# File 'lib/devcenter/helpers.rb', line 39 def slug_from_article_url(url) return nil unless url url.split('/articles/').last.split('?').first.split('#').first end |
#update_article_path(id) ⇒ Object
29 30 31 |
# File 'lib/devcenter/helpers.rb', line 29 def update_article_path(id) "/api/v1/private/articles/#{id}.json" end |
#validate_article_path(id) ⇒ Object
25 26 27 |
# File 'lib/devcenter/helpers.rb', line 25 def validate_article_path(id) "/api/v1/private/articles/#{id}/validate.json" end |
#write_file(filename, content) ⇒ Object
52 53 54 |
# File 'lib/devcenter/helpers.rb', line 52 def write_file(filename, content) File.open(filename, 'w'){ |f| f.write(content) } end |