Module: Devcenter::Helpers

Included in:
Client, Commands::Base
Defined in:
lib/devcenter/helpers.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


33
34
35
36
# 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\/.+/)
end


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_urlObject



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_tokenObject



55
56
57
58
59
60
# File 'lib/devcenter/helpers.rb', line 55

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



47
48
49
# File 'lib/devcenter/helpers.rb', line 47

def html_file_path(slug)
  File.expand_path("#{slug}.html")
end

#md_file_path(slug) ⇒ Object



43
44
45
# File 'lib/devcenter/helpers.rb', line 43

def md_file_path(slug)
  File.expand_path("#{slug}.md")
end

#netrc_pathObject



62
63
64
65
66
67
68
69
70
# File 'lib/devcenter/helpers.rb', line 62

def netrc_path
  default = Netrc.default_path
  encrypted = default + ".gpg"
  if File.exist?(encrypted)
    encrypted
  else
    default
  end
end

#search_api_pathObject



21
22
23
# File 'lib/devcenter/helpers.rb', line 21

def search_api_path
  "/api/v1/search.json"
end

#slug_from_article_url(url) ⇒ Object



38
39
40
41
# File 'lib/devcenter/helpers.rb', line 38

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



51
52
53
# File 'lib/devcenter/helpers.rb', line 51

def write_file(filename, content)
  File.open(filename, 'w'){ |f| f.write(content) }
end