Class: Patreon::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/patreon/objects/member.rb

Constant Summary collapse

DEFAULT_FIELDS =
"campaign_lifetime_support_cents,currently_entitled_amount_cents,email,full_name,is_follower,last_charge_date,last_charge_status,lifetime_support_cents,next_charge_date,note,patron_status,pledge_cadence,pledge_relationship_start,will_pay_amount_cents"

Instance Method Summary collapse

Methods inherited from Object

#to_ostruct

Constructor Details

#initialize(options = {}) ⇒ Member

Returns a new instance of Member.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/patreon/objects/member.rb', line 6

def initialize(options = {})
  super options

  if options["data"] && options["data"]["id"]
    self.id = options["data"]["id"]
  end

  if options["id"]
    self.id = options["id"]
  end        

  if options["relationships"] && options["relationships"]["currently_entitled_tiers"]
    self.currently_entitled_tiers = options["relationships"]["currently_entitled_tiers"]["data"]
  end

  if options["relationships"]
    self.relationships = options["relationships"].map {|r| { r[0] => r[1]['data']['id'] } }

    options["relationships"].each do |rel|
      rel_type = rel[1]["data"]["type"]
      rel_id   = rel[1]["data"]["id"]

      case rel_type
      when "user"
        self.user_id = rel_id
      when "campaign"
        self.campaign_id = rel_id
      end
    end
  end

  if options["included"]
    case options["included"][0]["type"]
    when "tier"
      self.tier_id = options["included"][0]["id"]
      self.tier = options["included"][0]["attributes"]
    end
  end

end