Class: Patreon::CampaignsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/patreon/resources/campaigns.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Patreon::Resource

Instance Method Details

#benefits(id:, fields: Benefit::DEFAULT_FIELDS) ⇒ Object



24
25
26
27
# File 'lib/patreon/resources/campaigns.rb', line 24

def benefits(id:, fields: Benefit::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}?include=benefits&fields[benefit]=#{fields}")
  Collection.from_response(response, type: Benefit, key: "included")
end

#creator(id:, fields: User::DEFAULT_FIELDS) ⇒ Object



19
20
21
22
# File 'lib/patreon/resources/campaigns.rb', line 19

def creator(id:, fields: User::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}?include=creator&fields[user]=#{fields}")
  User.new response.body.dig("included")[0]
end

#goals(id:, fields: Goal::DEFAULT_FIELDS) ⇒ Object



29
30
31
32
# File 'lib/patreon/resources/campaigns.rb', line 29

def goals(id:, fields: Goal::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}?include=goals&fields[goal]=#{fields}")
  Collection.from_response(response, type: Goal, key: "included")
end

#list(fields: Campaign::DEFAULT_FIELDS) ⇒ Object



4
5
6
7
# File 'lib/patreon/resources/campaigns.rb', line 4

def list(fields: Campaign::DEFAULT_FIELDS)
  response = get_request("campaigns?fields[campaign]=#{fields}")
  Collection.from_response(response, type: Campaign, key: "data")
end

#members(id:, member_fields: Member::DEFAULT_FIELDS, user_fields: User::DEFAULT_FIELDS, campaign_fields: Campaign::DEFAULT_FIELDS) ⇒ Object



34
35
36
37
# File 'lib/patreon/resources/campaigns.rb', line 34

def members(id:, member_fields: Member::DEFAULT_FIELDS, user_fields: User::DEFAULT_FIELDS, campaign_fields: Campaign::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}/members?include=user,campaign&fields[member]=#{member_fields}&fields[user]=#{user_fields}&fields[campaign]=#{campaign_fields}")
  Collection.from_response(response, type: Member, key: "data")
end

#retrieve(id:, fields: Campaign::DEFAULT_FIELDS) ⇒ Object



9
10
11
12
# File 'lib/patreon/resources/campaigns.rb', line 9

def retrieve(id:, fields: Campaign::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}?fields[campaign]=#{fields}")
  Campaign.new response.body.dig("data")
end

#tiers(id:, fields: Tier::DEFAULT_FIELDS) ⇒ Object



14
15
16
17
# File 'lib/patreon/resources/campaigns.rb', line 14

def tiers(id:, fields: Tier::DEFAULT_FIELDS)
  response = get_request("campaigns/#{id}?include=tiers&fields[tier]=#{fields}")
  Collection.from_response(response, type: Tier, key: "included")
end