Module: Mingle4r::API::Card::InstanceMethods
- Defined in:
- lib/mingle4r/api/card.rb
Instance Method Summary collapse
- #add_comment(str) ⇒ Object
- #attachments ⇒ Object
- #comments ⇒ Object
-
#custom_properties ⇒ Object
Gets the custom properties in the form of an array of hashes with the property names as keys and property values as the value.
- #encode(options = {}) ⇒ Object
- #execute_transition(args) ⇒ Object
- #murmurs ⇒ Object
-
#property_value(name, val = nil) ⇒ Object
Gets and sets the value of a property.
- #transitions ⇒ Object
- #type ⇒ Object
- #type=(type) ⇒ Object
- #upload_attachment(file_path) ⇒ Object
-
#version(version_no) ⇒ Object
returns back the version of the card given.
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 |
#attachments ⇒ Object
32 33 34 35 |
# File 'lib/mingle4r/api/card.rb', line 32 def set_attributes_for(Attachment) unless @attachments = Attachment.find(:all) end |
#comments ⇒ Object
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_properties ⇒ Object
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( = {}) .merge! :root => 'card' self.class.format.encode(attributes, ) 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 |
#murmurs ⇒ Object
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 |
#transitions ⇒ Object
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 |
#type ⇒ Object
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 (file_path) = URI.parse(File.join(self.class.site.to_s, "cards/#{self.number()}/attachments.xml")) http = Net::HTTP.new(.host, .port) http.use_ssl = .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(.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 |