Class: TeamboxAPI::Project
- Defined in:
- lib/teambox/teambox-api.rb
Class Method Summary collapse
- .collection_path(organization_path, prefix_options = {}, query_options = nil) ⇒ Object
- .find_every(options) ⇒ Object
- .instantiate_collection(collection, prefix_options = {}) ⇒ Object
Instance Method Summary collapse
- #collection_path(options = nil) ⇒ Object
- #create ⇒ Object
- #encode(options = {}) ⇒ Object
- #organization_id ⇒ Object
- #project_id ⇒ Object
- #tickets(options = {}) ⇒ Object
- #update ⇒ Object
Methods inherited from Base
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, = {}, = nil) , = () if .nil? "#{prefix()}#{organization_path}#{collection_name}.#{format.extension}#{query_string()}" 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() #add :count => 0 in order to retrieve objects with no limits. Default is 20 objects per request. .merge!(:params => {:count => 0}) begin case from = [:from] when Symbol self.instantiate_collection(get(from, [:params])) when String path = "#{from}#{query_string([:params])}" self.instantiate_collection(connection.get(path, headers) || []) else , = ([:params]) path = self.collection_path(nil, , ) self.instantiate_collection( (connection.get(path, headers) || []), ) 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, = {}) objects = collection["objects"] objects.collect! { |record| instantiate_record(record, ) } end |
Instance Method Details
#collection_path(options = nil) ⇒ Object
95 96 97 98 |
# File 'lib/teambox/teambox-api.rb', line 95 def collection_path( = nil) organization_path = "organizations/#{attributes[:organization_id].to_s}/" self.class.collection_path(organization_path, || ) end |
#create ⇒ Object
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(={}) val = [] attributes.each_pair do |key, value| val << "#{URI.escape key}=#{URI.escape value}" rescue nil end val.join('&') end |
#organization_id ⇒ Object
134 135 136 |
# File 'lib/teambox/teambox-api.rb', line 134 def organization_id attributes[:organization_id] end |
#project_id ⇒ Object
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( = {}) Task.find(:all, :params => .update(:project_id => project_id)) end |
#update ⇒ Object
121 122 123 124 125 |
# File 'lib/teambox/teambox-api.rb', line 121 def update connection.put(element_path() + '?' + encode, nil, self.class.headers).tap do |response| load_attributes_from_response(response) end end |