Module: RedHaze::Helpers::Resource

Included in:
Activity, Collection, Comment, Group, Playlist, Track, User
Defined in:
lib/red_haze/helpers/resource.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/red_haze/helpers/resource.rb', line 9

def id
  @id
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/red_haze/helpers/resource.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#delete_endpoint(endpoint, args = {}) ⇒ Object



34
35
36
# File 'lib/red_haze/helpers/resource.rb', line 34

def delete_endpoint(endpoint, args={})
  Request.delete(url + endpoint, args).parsed_response
end

#get_endpoint(endpoint, args = {}) ⇒ Object



24
25
26
# File 'lib/red_haze/helpers/resource.rb', line 24

def get_endpoint(endpoint, args={})
  self.class.import_from_response Request.get(url + endpoint, args)
end

#initialize(arg) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/red_haze/helpers/resource.rb', line 11

def initialize(arg)
  case arg
    when Fixnum then @id = arg
    when Hash then initialize_from_hash(arg)
    else raise "Not a valid Resource initialize arg: #{arg.inspect}"
  end
end

#put_endpoint(endpoint, args = {}) ⇒ Object



28
29
30
31
32
# File 'lib/red_haze/helpers/resource.rb', line 28

def put_endpoint(endpoint, args={})
  default_args = {headers: {'Content-Length' => "0"}}
  args.merge! default_args
  Request.put(url + endpoint, args).parsed_response
end

#syncObject



19
20
21
22
# File 'lib/red_haze/helpers/resource.rb', line 19

def sync
  initialize_from_hash Request.get(url)
  self
end

#urlObject



38
39
40
41
# File 'lib/red_haze/helpers/resource.rb', line 38

def url
  class_name = self.class.name.downcase.split('::')[-1]
  class_name == 'me' ? '/me' : "/#{class_name}s/#{id}"
end