Class: TeamboxAPI::Project

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited

Class Method Details

.collection_path(organization_path, prefix_options = {}, query_options = nil) ⇒ Object



90
91
92
93
# File 'lib/teambox/teambox-api.rb', line 90

def self.collection_path(organization_path, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{organization_path}#{collection_name}.#{format.extension}#{query_string(query_options)}"
end

.find_every(options) ⇒ Object



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

def self.find_every(options)
  #add :count => 0 in order to retrieve objects with no limits. Default is 20 objects per request.
  options.merge!(:params => {:count => 0})
  begin
    case from = options[:from]
    when Symbol
      self.instantiate_collection(get(from, options[:params]))
    when String
      path = "#{from}#{query_string(options[:params])}"
      self.instantiate_collection(connection.get(path, headers) || [])
    else
      prefix_options, query_options = split_options(options[:params])
      path = self.collection_path(nil, prefix_options, query_options)
      self.instantiate_collection( (connection.get(path, headers) || []), prefix_options )
    end
  rescue ActiveResource::ResourceNotFound
    # Swallowing ResourceNotFound exceptions and return nil - as per
    # ActiveRecord.
    nil
  end
end

.instantiate_collection(collection, prefix_options = {}) ⇒ Object



100
101
102
103
# File 'lib/teambox/teambox-api.rb', line 100

def self.instantiate_collection(collection, prefix_options = {})
  objects = collection["objects"]
  objects.collect! { |record| instantiate_record(record, prefix_options) }
end

Instance Method Details

#collection_path(options = nil) ⇒ Object



95
96
97
98
# File 'lib/teambox/teambox-api.rb', line 95

def collection_path(options = nil)
  organization_path = "organizations/#{attributes[:organization_id].to_s}/"
  self.class.collection_path(organization_path, options || prefix_options)
end

#createObject



127
128
129
130
131
132
# File 'lib/teambox/teambox-api.rb', line 127

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

#encode(options = {}) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/teambox/teambox-api.rb', line 113

def encode(options={})
  val = []
  attributes.each_pair do |key, value|
    val << "#{URI.escape key}=#{URI.escape value}" rescue nil
  end
  val.join('&')
end

#organization_idObject



134
135
136
# File 'lib/teambox/teambox-api.rb', line 134

def organization_id
  attributes[:organization_id]
end

#project_idObject



109
110
111
# File 'lib/teambox/teambox-api.rb', line 109

def project_id
  self[:id]
end

#tickets(options = {}) ⇒ Object



105
106
107
# File 'lib/teambox/teambox-api.rb', line 105

def tickets(options = {})
  Task.find(:all, :params => options.update(:project_id => project_id))
end

#updateObject



121
122
123
124
125
# File 'lib/teambox/teambox-api.rb', line 121

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