Module: Mingle4r::API::Card::InstanceMethods

Defined in:
lib/mingle4r/api/card.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(str) ⇒ Object



79
80
81
82
83
# File 'lib/mingle4r/api/card.rb', line 79

def add_comment(str)
  set_attributes_for(Comment)
  comment = Comment.new(:content => str.to_s)
  comment.save
end

#attachmentsObject



32
33
34
35
# File 'lib/mingle4r/api/card.rb', line 32

def attachments
  set_attributes_for(Attachment) unless attachment_class_set
  @attachments = Attachment.find(:all)
end

#commentsObject



37
38
39
40
# File 'lib/mingle4r/api/card.rb', line 37

def comments
  set_attributes_for(Comment) unless comment_class_set
  Comment.find(:all)
end

#custom_propertiesObject

Gets the custom properties in the form of an array of hashes with the property names as keys and property values as the value



116
117
118
# File 'lib/mingle4r/api/card.rb', line 116

def custom_properties
  properties.map { |p| {p.name => p.value} }
end

#encode(options = {}) ⇒ Object



120
121
122
123
# File 'lib/mingle4r/api/card.rb', line 120

def encode(options = {})
  options.merge! :root => 'card'
  self.class.format.encode(attributes, options)
end

#execute_transition(args) ⇒ Object



85
86
87
88
89
# File 'lib/mingle4r/api/card.rb', line 85

def execute_transition(args)
  trans_name = args.symbolize_keys[:name]
  transition = transitions.detect { |t| t.name ==  trans_name}
  transition.execute(args)
end

#murmursObject



47
48
49
50
# File 'lib/mingle4r/api/card.rb', line 47

def murmurs
  set_attributes_for(Murmur) unless murmur_class_set
  @murmurs = Murmur.find(:all)
end

#property_value(name, val = nil) ⇒ Object

Gets and sets the value of a property. The property name given should be the same as the mingle property name. the value is optional



108
109
110
111
112
# File 'lib/mingle4r/api/card.rb', line 108

def property_value(name, val = nil)
  property = properties.detect { |p| p.name == name }
  val ? set_prop_val(property, val) : ( property ? property.value : nil )
  # val ? property.value = val : property.value
end

#transitionsObject



42
43
44
45
# File 'lib/mingle4r/api/card.rb', line 42

def transitions
  set_attributes_for(Transition) unless transition_class_set
  @transitions = Transition.find(:all)
end

#typeObject



24
25
26
# File 'lib/mingle4r/api/card.rb', line 24

def type
  attributes['card_type_name']
end

#type=(type) ⇒ Object



28
29
30
# File 'lib/mingle4r/api/card.rb', line 28

def type=(type)
  attributes['card_type_name'] = type
end

#upload_attachment(file_path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mingle4r/api/card.rb', line 52

def upload_attachment(file_path)
  attachment_uri   = URI.parse(File.join(self.class.site.to_s, "cards/#{self.number()}/attachments.xml"))
  http             = Net::HTTP.new(attachment_uri.host, attachment_uri.port)
  http.use_ssl     = attachment_uri.is_a?(URI::HTTPS)
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
  basic_encode     = 'Basic ' + ["#{self.class.user}:#{self.class.password}"].pack('m').delete("\r\n")

  post_headers = {
    'Authorization' => basic_encode,
    'Content-Type'  => 'multipart/form-data; boundary=----------XnJLe9ZIbbGUYtzPQJ16u1'
  }

  file_content = IO.read(file_path)

  post_body = <<EOS
------------XnJLe9ZIbbGUYtzPQJ16u1\r
Content-Disposition: form-data; name="file"; filename="#{File.basename(file_path)}"\r
Content-Type: application/octet-stream\r
Content-Length: #{file_content.size}\r
\r
#{file_content}\r
------------XnJLe9ZIbbGUYtzPQJ16u1--\r
EOS
      
  http.post(attachment_uri.path, post_body, post_headers)
end

#version(version_no) ⇒ Object

returns back the version of the card given. If an invalid version is given, the latest version is returned, takes a number or :next or :before



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mingle4r/api/card.rb', line 93

def version(version_no)
  version_2_find = 0
  case version_no
  when :previous
    version_2_find = self.version.to_i - 1
  when :next
    version_2_find = self.version.to_i + 1
  else
    version_2_find = version_no.to_i
  end
  self.class.find(self.number, :params => {:version => version_2_find})
end