Class: MingleAPI::Card

Inherits:
Base
  • Object
show all
Defined in:
lib/mingle/mingle-api.rb

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#card_typeObject



199
200
201
# File 'lib/mingle/mingle-api.rb', line 199

def card_type
  @attributes['card_type']
end

#createObject



166
167
168
169
170
171
# File 'lib/mingle/mingle-api.rb', line 166

def create
  connection.post(collection_path + '?' + encode, nil, self.class.headers).tap do |response|
    self.number = id_from_response(response)
    load_attributes_from_response(response)
  end
end

#created_onObject



187
188
189
# File 'lib/mingle/mingle-api.rb', line 187

def created_on
  @attributes['created_on']
end

#descriptionObject



195
196
197
# File 'lib/mingle/mingle-api.rb', line 195

def description
  @attributes['description']
end

#element_path(options = nil) ⇒ Object

begin monkey patches



132
133
134
# File 'lib/mingle/mingle-api.rb', line 132

def element_path(options = nil)
  self.class.element_path(self.number, options)
end

#encode(options = {}) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/mingle/mingle-api.rb', line 136

def encode(options={})
  val = []
  attributes.each_pair do |key, value|
    unless value.nil?
      case key 
      when 'card_type'
        if value.is_a? Hash
          name = value[:name]
        else
          name = value.name
        end
        val << "card[card_type_name]=#{URI.escape name}"
      when 'properties' 
        value.each {|property| 
          val << "card[properties][][name]=#{URI.escape property[0]}
                  &card[properties][][value]=#{URI.escape property[1]}"} rescue NoMethodError
      else
        val << "card[#{URI.escape key.to_s}]=#{URI.escape value.to_s}" rescue nil
      end
    end
  end
  val.join('&')
end

#idObject



179
180
181
# File 'lib/mingle/mingle-api.rb', line 179

def id
  @attributes['id']
end

#modified_onObject



191
192
193
# File 'lib/mingle/mingle-api.rb', line 191

def modified_on
  @attributes['modified_on']
end

#nameObject



183
184
185
# File 'lib/mingle/mingle-api.rb', line 183

def name
  @attributes['name']
end

#numberObject

end monkey patches



175
176
177
# File 'lib/mingle/mingle-api.rb', line 175

def number
  @attributes['number']
end

#propertiesObject



203
204
205
# File 'lib/mingle/mingle-api.rb', line 203

def properties
  @attributes['properties']
end

#updateObject



160
161
162
163
164
# File 'lib/mingle/mingle-api.rb', line 160

def update
  connection.put(element_path(prefix_options) + '?' + encode, nil, self.class.headers).tap do |response|
    load_attributes_from_response(response)
  end
end