Module: Planbox

Includes:
HTTParty
Defined in:
lib/planbox.rb

Class Method Summary collapse

Class Method Details

.check_environmentObject



10
11
12
13
14
15
# File 'lib/planbox.rb', line 10

def self.check_environment
  if PLANBOX_EMAIL == nil || PLANBOX_TOKEN == nil
    raise "environment variables not set. Please check that you have the following set...\
    \nPLANBOX_EMAIL\nPLANBOX_TOKEN"
  end
end

.format(stories) ⇒ Object

formats the output of stories



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/planbox.rb', line 64

def self.format(stories)
  result_string = ""
  stories.each do |story|
    result_string += "#{story['id']}:"
    result_string += "#{story['status']}: "
    result_string += "#{story['name']}"
    result_string += "\n"
  end

  # clean up any troublesome chars
  result_string.gsub!('`', ' ') || result_string
end

.get_release_notes(pb_story_ids) ⇒ Object



17
18
19
20
# File 'lib/planbox.rb', line 17

def self.get_release_notes pb_story_ids
  stories = get_release_notes_array pb_story_ids
  result_string = format stories
end

.get_release_notes_array(pb_story_ids) ⇒ Object



22
23
24
25
# File 'lib/planbox.rb', line 22

def self.get_release_notes_array pb_story_ids
  check_environment
  stories = get_stories pb_story_ids
end

.get_stories(array_of_pb_ids) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/planbox.rb', line 53

def self.get_stories(array_of_pb_ids)
  
  stories = []
  return [] unless array_of_pb_ids
  array_of_pb_ids.each do |id|
    stories<< get_story(id)
  end
  stories
end

.get_story(story_id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/planbox.rb', line 32

def self.get_story(story_id)
  story_response = self.post("#{PLANBOX_BASE_URL}/get_story", { :body => { :story_id => story_id}})

  if story_response.parsed_response.nil? || story_response.parsed_response["code"] == "error"
    return {"id" => story_id, "name" => "story not found in planbox"}
  end

  story = story_response.parsed_response["content"]
  project_response = self.post("#{PLANBOX_BASE_URL}/get_project", { :body => { :project_id => story['project_id'], :product_id => story['product_id']}})
  project = project_response.parsed_response["content"]
  project_alias = project["alias"]
  project_name = project["name"]

  story = story.merge({"project_name" => project_name})
  story = story.merge({"project_alias" => project_alias})
  story = story.merge(
    {"pb_url" => "https://www.planbox.com/initiatives/#{story['product_id']}#story_id=#{story['id']}"})

  story
end

.has_planbox?(object) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
# File 'lib/planbox.rb', line 77

def self.has_planbox? object
  if object.is_a?(Hash)
    return !object['name'].nil?
  elsif object.is_a?(Array)
    object.each do |story|
      return true if !story['name'].nil?
    end
    return false
  end
end

.loginObject



27
28
29
30
# File 'lib/planbox.rb', line 27

def self.
  response = self.post("#{PLANBOX_BASE_URL}/auth", { :body => {:email => PLANBOX_EMAIL, :password => PLANBOX_TOKEN}})
  self.basic_auth response['content']['access_token'], ""
end