Class: TunecoreDirect::Person

Inherits:
Base
  • Object
show all
Includes:
TunecoreDirect
Defined in:
lib/tunecore_direct/person.rb

Overview

Represents a individual TuneCore account

Required fields are:

  • email

  • name

  • phone_number

  • postal_code

  • country

  • password

Once you set these instance variables you can call Person#create to create the account at TuneCore. When the account is created the person_id will be set which you should use to track the user in your system.

If you don’t set these instance variables before calling Person#create the call will return false and the Person#errors accessor will be populated with a list of errors that you will need to fix.

Instance Attribute Summary collapse

Attributes inherited from Base

#log

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, #api_key, api_key=, tunecore_server, #tunecore_server, tunecore_server=

Constructor Details

#initialize(options = {}) ⇒ Person

Returns a new instance of Person.



23
24
25
26
27
# File 'lib/tunecore_direct/person.rb', line 23

def initialize(options = {})
  options.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def country
  @country
end

#emailObject

Returns the value of attribute email.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def email
  @email
end

#errorsObject

Returns the value of attribute errors.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def errors
  @errors
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def name
  @name
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def password
  @password
end

#person_idObject

Returns the value of attribute person_id.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def person_id
  @person_id
end

#phone_numberObject

Returns the value of attribute phone_number.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def phone_number
  @phone_number
end

#postal_codeObject

Returns the value of attribute postal_code.



21
22
23
# File 'lib/tunecore_direct/person.rb', line 21

def postal_code
  @postal_code
end

Class Method Details

.from_xml_element(person_element) ⇒ Object

takes an Rexml::Element and builds a person out of it



30
31
32
33
34
35
36
37
38
# File 'lib/tunecore_direct/person.rb', line 30

def self.from_xml_element(person_element)
  @xml_element = person_element
  person = self.new
  person.person_id = person_element.elements["id"].text
  person.email = person_element.elements["email"].text
  person.name = person_element.elements["name"].text
  person.phone_number = person_element.elements["phone_number"].text
  return person
end

.get(id) ⇒ Object

Get’s a person object from the TuneCore server. Id can be either a person_id or an email address



75
76
77
78
# File 'lib/tunecore_direct/person.rb', line 75

def self.get(id)
  req = Request.new
  req.get_person(id).object
end

.get_peopleObject

Returns an array of people associated with your account



69
70
71
72
# File 'lib/tunecore_direct/person.rb', line 69

def self.get_people
  req = Request.new
  req.get_people.object
end

Instance Method Details

#albumsObject

Returns an array of albums owned by this person



81
82
83
84
# File 'lib/tunecore_direct/person.rb', line 81

def albums
  req = Request.new
  req.get_albums(person_id).object
end

#createObject

Creates this person record in the Tunecore system



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tunecore_direct/person.rb', line 47

def create
  req = Request.new
  res = req.create_person(@email, @password, @name, @phone_number, @country, @postal_code)
  raise "Unexpected return type: #{res.type}" unless res.type == "person"
  if res.status == "complete"
    @person_id = res.object.person_id
    return true
  else
    @errors = res.errors
    return false
  end
end

#create_album(params = {}) ⇒ Object

Creates a new album for this Person



61
62
63
64
65
66
# File 'lib/tunecore_direct/person.rb', line 61

def create_album(params={})
  params[:person_id] = self.person_id
  album = TunecoreDirect::Album.new(params)
  album.create
  return album
end

#to_xmlObject

Returns the XML representation of this person



41
42
43
44
# File 'lib/tunecore_direct/person.rb', line 41

def to_xml
  return false if @xml_element.nil?
  @xml_element.text
end