Class: Bugly::APIResource

Inherits:
BuglyObject show all
Defined in:
lib/bugly.rb

Instance Attribute Summary

Attributes inherited from BuglyObject

#api_base, #api_key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BuglyObject

#[], #[]=, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Bugly::BuglyObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bugly::BuglyObject

Class Method Details

.retrieve(id, api_key = nil) ⇒ Object



314
315
316
317
318
# File 'lib/bugly.rb', line 314

def self.retrieve(id, api_key=nil)
  instance = self.new(id, api_key)
  instance.refresh
  instance
end

.urlObject



287
288
289
290
291
292
293
294
295
296
297
# File 'lib/bugly.rb', line 287

def self.url
  if self == APIResource
    raise NotImplementedError.new("APIResource is an abstract class. You should perform actions on its subclasses (Issue, Project, etc.)")
  end
  shortname = self.name.split('::')[-1]
  # HACK: Use a proper pluralize method instead of this terrible hack
  shortname = "Categorie" if shortname == "Category"
  shortname = "Prioritie" if shortname == "Priority"
  shortname = "Statuse" if shortname == "Status"
  "/#{CGI.escape(shortname.downcase)}s"
end

Instance Method Details

#refreshObject



308
309
310
311
312
# File 'lib/bugly.rb', line 308

def refresh
  response, api_key = Bugly.request(:get, url, @api_key)
  refresh_from(response, api_key)
  self
end

#urlObject Also known as: api_url



299
300
301
302
303
# File 'lib/bugly.rb', line 299

def url
  id = self['id'].to_s
  raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id') if not id or id == ""
  "#{self.class.url}/#{CGI.escape(id)}"
end