Class: Kentaa::Api::Resources::Segment

Inherits:
Resource show all
Defined in:
lib/kentaa/api/resources/segment.rb

Instance Attribute Summary

Attributes inherited from Resource

#id

Attributes inherited from Base

#config, #endpoint_path, #options, #resource_class

Instance Method Summary collapse

Methods inherited from Resource

#create, #created_at, #delete, #initialize, #load, #save, #updated_at

Methods inherited from Base

attribute_key, #initialize, #load, #loaded?

Constructor Details

This class inherits a constructor from Kentaa::Api::Resources::Resource

Instance Method Details

#actionsObject



84
85
86
# File 'lib/kentaa/api/resources/segment.rb', line 84

def actions
  @actions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/segments/#{id}/actions")
end

#activitiesObject



108
109
110
# File 'lib/kentaa/api/resources/segment.rb', line 108

def activities
  @activities ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Activity, endpoint_path: "/segments/#{id}/activities")
end

#bannersObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kentaa/api/resources/segment.rb', line 66

def banners
  @banners ||= begin
    banners = []

    if data[:banners]
      data[:banners].each do |banner|
        banners << Kentaa::Api::Resources::Banner.new(banner)
      end
    end

    banners
  end
end

#descriptionObject



38
39
40
# File 'lib/kentaa/api/resources/segment.rb', line 38

def description
  data[:description]
end


62
63
64
# File 'lib/kentaa/api/resources/segment.rb', line 62

def donate_url
  data[:donate_url]
end

#donationsObject



96
97
98
# File 'lib/kentaa/api/resources/segment.rb', line 96

def donations
  @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/segments/#{id}/donations")
end

#end_dateObject



54
55
56
# File 'lib/kentaa/api/resources/segment.rb', line 54

def end_date
  Time.parse(data[:end_date]) if data[:end_date]
end

#external_referenceObject



80
81
82
# File 'lib/kentaa/api/resources/segment.rb', line 80

def external_reference
  data[:external_reference]
end

#manual_donationsObject



100
101
102
# File 'lib/kentaa/api/resources/segment.rb', line 100

def manual_donations
  @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/segments/#{id}/manual-donations")
end

#nameObject



30
31
32
# File 'lib/kentaa/api/resources/segment.rb', line 30

def name
  data[:name]
end

#newsletter_subscriptionsObject



104
105
106
# File 'lib/kentaa/api/resources/segment.rb', line 104

def newsletter_subscriptions
  @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/segments/#{id}/newsletter-subscriptions")
end

#object_keyObject



10
11
12
# File 'lib/kentaa/api/resources/segment.rb', line 10

def object_key
  "Segment_#{id}"
end

#parentObject



14
15
16
# File 'lib/kentaa/api/resources/segment.rb', line 14

def parent
  site
end

#projectsObject



92
93
94
# File 'lib/kentaa/api/resources/segment.rb', line 92

def projects
  @projects ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Project, endpoint_path: "/segments/#{id}/projects")
end

#siteObject



18
19
20
# File 'lib/kentaa/api/resources/segment.rb', line 18

def site
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end

#site_idObject



22
23
24
# File 'lib/kentaa/api/resources/segment.rb', line 22

def site_id
  data[:site_id]
end

#subdomainObject



26
27
28
# File 'lib/kentaa/api/resources/segment.rb', line 26

def subdomain
  data[:subdomain]
end

#target_amountObject



42
43
44
# File 'lib/kentaa/api/resources/segment.rb', line 42

def target_amount
  data[:target_amount]
end

#teamsObject



88
89
90
# File 'lib/kentaa/api/resources/segment.rb', line 88

def teams
  @teams ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Team, endpoint_path: "/segments/#{id}/teams")
end

#titleObject



34
35
36
# File 'lib/kentaa/api/resources/segment.rb', line 34

def title
  data[:title]
end

#total_amountObject



46
47
48
# File 'lib/kentaa/api/resources/segment.rb', line 46

def total_amount
  BigDecimal(data[:total_amount])
end

#total_donationsObject



50
51
52
# File 'lib/kentaa/api/resources/segment.rb', line 50

def total_donations
  data[:total_donations]
end

#urlObject



58
59
60
# File 'lib/kentaa/api/resources/segment.rb', line 58

def url
  data[:url]
end