Class: GeniusReferrals::AdvocatesResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/genius_referrals/resources/advocates.rb

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from GeniusReferrals::Resource

Instance Method Details

#create(account_slug, advocate) ⇒ Object

Create an advocate using the accepted advocate wrapper.



19
20
21
# File 'lib/genius_referrals/resources/advocates.rb', line 19

def create(, advocate)
  request('POST', "/accounts/#{esc()}/advocates", json: wrapped('advocate', advocate))
end

#create_payment_method(account_slug, advocate_token, payment_method) ⇒ Object

Create an advocate payment method.



66
67
68
69
70
# File 'lib/genius_referrals/resources/advocates.rb', line 66

def create_payment_method(, advocate_token, payment_method)
  request('POST',
          "/accounts/#{esc()}/advocates/#{esc(advocate_token)}/payment-methods",
          json: wrapped('advocate_payment_method', payment_method))
end

#delete(account_slug, advocate_token) ⇒ Object

Delete one advocate.



41
42
43
# File 'lib/genius_referrals/resources/advocates.rb', line 41

def delete(, advocate_token)
  request('DELETE', "/accounts/#{esc()}/advocates/#{esc(advocate_token)}")
end

#delete_all(account_slug, advocates: nil) ⇒ Object

Delete all advocates for an account, or a scoped comma-separated token set.



46
47
48
49
50
51
# File 'lib/genius_referrals/resources/advocates.rb', line 46

def delete_all(, advocates: nil)
  query_value = advocates.is_a?(Array) ? advocates.join(',') : advocates
  request('DELETE',
          "/accounts/#{esc()}/advocates",
          params: compact(advocates: query_value))
end

#each(account_slug, page_number: 1, limit: 100, **filters, &block) ⇒ Object

Iterate advocates across all available pages.



10
11
12
13
14
15
16
# File 'lib/genius_referrals/resources/advocates.rb', line 10

def each(, page_number: 1, limit: 100, **filters, &block)
  each_page("/accounts/#{esc()}/advocates",
            page_number: page_number,
            limit: limit,
            params: filters,
            &block)
end

#list(account_slug, page: 1, limit: 10, filter: nil, sort: nil, **filters) ⇒ Object

List advocates for an account.



4
5
6
7
# File 'lib/genius_referrals/resources/advocates.rb', line 4

def list(, page: 1, limit: 10, filter: nil, sort: nil, **filters)
  params = compact({ page: page, limit: limit, filter: filter, sort: sort }.merge(filters))
  page('GET', "/accounts/#{esc()}/advocates", params: params)
end

#patch(account_slug, advocate_token, **fields) ⇒ Object

Patch an advocate with unwrapped partial fields.



36
37
38
# File 'lib/genius_referrals/resources/advocates.rb', line 36

def patch(, advocate_token, **fields)
  request('PATCH', "/accounts/#{esc()}/advocates/#{esc(advocate_token)}", json: fields)
end

#payment_methods(account_slug, advocate_token, page: 1, limit: 10) ⇒ Object

List payment methods for one advocate.



59
60
61
62
63
# File 'lib/genius_referrals/resources/advocates.rb', line 59

def payment_methods(, advocate_token, page: 1, limit: 10)
  page('GET',
       "/accounts/#{esc()}/advocates/#{esc(advocate_token)}/payment-methods",
       params: { page: page, limit: limit })
end

#retrieve(account_slug, advocate_token) ⇒ Object

Retrieve one advocate by token.



24
25
26
# File 'lib/genius_referrals/resources/advocates.rb', line 24

def retrieve(, advocate_token)
  request('GET', "/accounts/#{esc()}/advocates/#{esc(advocate_token)}")
end

#retrieve_payment_method(account_slug, advocate_token, payment_method_id) ⇒ Object

Retrieve one advocate payment method.



73
74
75
76
# File 'lib/genius_referrals/resources/advocates.rb', line 73

def retrieve_payment_method(, advocate_token, payment_method_id)
  request('GET',
          "/accounts/#{esc()}/advocates/#{esc(advocate_token)}/payment-methods/#{esc(payment_method_id)}")
end

Return share links for one advocate.



54
55
56
# File 'lib/genius_referrals/resources/advocates.rb', line 54

def share_links(, advocate_token)
  request('GET', "/accounts/#{esc()}/advocates/#{esc(advocate_token)}/share-links")
end

#update(account_slug, advocate_token, advocate) ⇒ Object

Replace an advocate using the accepted advocate wrapper.



29
30
31
32
33
# File 'lib/genius_referrals/resources/advocates.rb', line 29

def update(, advocate_token, advocate)
  request('PUT',
          "/accounts/#{esc()}/advocates/#{esc(advocate_token)}",
          json: wrapped('advocate', advocate))
end

#update_payment_method(account_slug, advocate_token, payment_method_id, payment_method) ⇒ Object

Replace one advocate payment method.



79
80
81
82
83
# File 'lib/genius_referrals/resources/advocates.rb', line 79

def update_payment_method(, advocate_token, payment_method_id, payment_method)
  request('PUT',
          "/accounts/#{esc()}/advocates/#{esc(advocate_token)}/payment-methods/#{esc(payment_method_id)}",
          json: wrapped('advocate_payment_method', payment_method))
end