Class: ScrumNinja::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/scrum_ninja/session.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Session

Returns a new instance of Session.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/scrum_ninja/session.rb', line 7

def initialize(opts={})
  @options = opts_maybe_with_defaults_from_config_files(opts)

  @api_key    = options[:api_key   ]
  @project_id = options[:project_id]
  @user_id    = options[:user_id   ]

  raise ArgumentError.new("Your ScrumNinja API key could not be determined!") if @api_key.blank?
end

Class Attribute Details

.read_config_from_filesystemObject

Returns the value of attribute read_config_from_filesystem.



19
20
21
# File 'lib/scrum_ninja/session.rb', line 19

def read_config_from_filesystem
  @read_config_from_filesystem
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/scrum_ninja/session.rb', line 5

def api_key
  @api_key
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/scrum_ninja/session.rb', line 5

def options
  @options
end

#project_idObject (readonly)

Returns the value of attribute project_id.



5
6
7
# File 'lib/scrum_ninja/session.rb', line 5

def project_id
  @project_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



5
6
7
# File 'lib/scrum_ninja/session.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#get_storiesObject



40
41
42
43
44
# File 'lib/scrum_ninja/session.rb', line 40

def get_stories
  xml = Server.get_stories(api_key, project_id)
  h = XmlSimple.xml_in(xml)
  h['story'].map { |hh| story_from_xml_hash(hh) } #rescue raise h.inspect
end

#get_story(story_id) ⇒ Object



50
51
52
53
54
# File 'lib/scrum_ninja/session.rb', line 50

def get_story(story_id)
  xml = get_story_xml(story_id)
  h = XmlSimple.xml_in(xml)
  story_from_xml_hash(h)
end

#get_story_xml(story_id) ⇒ Object



46
47
48
# File 'lib/scrum_ninja/session.rb', line 46

def get_story_xml(story_id)
  Server.get_story(api_key, project_id, story_id)
end

#update_ownership(story_id, new_owner_id = nil, opts = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/scrum_ninja/session.rb', line 65

def update_ownership(story_id, new_owner_id = nil, opts={})
  return if opts[:abort_if_already_owned] && get_story(story_id).has_owner?
  new_owner_id ||= user_id
  Server.update_story api_key, project_id, story_id, <<-XML
    <story>
      <owner-user-id type="integer">#{new_owner_id}</owner-user-id>
    </story>
  XML
end

#update_status(story_id, new_status) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/scrum_ninja/session.rb', line 75

def update_status(story_id, new_status)
  allowed_statuses = ['in process', 'delivered', 'accepted', 'deployed']
  unless allowed_statuses.include?(new_status)
    raise ArgumentError.new("Allowed statuses are #{allowed_statuses.join(', ')}")
  end
  Server.update_story api_key, project_id, story_id, <<-XML
    <story>
      <status>#{new_status}</status>
    </story>
  XML
end