Class: ActionNetworkRest::Petitions

Inherits:
Base
  • Object
show all
Defined in:
lib/action_network_rest/petitions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get, #list

Constructor Details

#initialize(petition_id = nil, client:) ⇒ Petitions

Without a petition_id, this class is used for Petition creation/update endpoints. With a petition_id, this class is used to initialise the Signatures class, like client.petitions(123).signatures



8
9
10
# File 'lib/action_network_rest/petitions.rb', line 8

def initialize(petition_id=nil, client:)
  super(client: client, petition_id: petition_id)
end

Instance Attribute Details

#petition_idObject

Returns the value of attribute petition_id.



3
4
5
# File 'lib/action_network_rest/petitions.rb', line 3

def petition_id
  @petition_id
end

Instance Method Details

#base_pathObject



16
17
18
# File 'lib/action_network_rest/petitions.rb', line 16

def base_path
  'petitions/'
end

#create(petition_data, creator_person_id: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/action_network_rest/petitions.rb', line 20

def create(petition_data, creator_person_id: nil)
  post_body = petition_data
  if creator_person_id.present?
    creator_person_url = action_network_url("/people/#{url_escape(creator_person_id)}")
    post_body['_links'] = {'osdi:creator' => {href: creator_person_url}}
  end

  response = client.post_request base_path, post_body
  object_from_response(response)
end

#signaturesObject



12
13
14
# File 'lib/action_network_rest/petitions.rb', line 12

def signatures
  @_signatures ||= ActionNetworkRest::Signatures.new(client: client, petition_id: petition_id)
end

#update(id, petition_data) ⇒ Object



31
32
33
34
35
# File 'lib/action_network_rest/petitions.rb', line 31

def update(id, petition_data)
  petition_path = "#{base_path}#{url_escape(id)}"
  response = client.put_request petition_path, petition_data
  object_from_response(response)
end