Class: ActionNetworkRest::Client

Inherits:
Vertebrae::API
  • Object
show all
Defined in:
lib/action_network_rest/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/action_network_rest/client.rb', line 5

def initialize(options={}, &block)
  self.api_key = options[:api_key]
  super(options, &block)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

Instance Method Details

#default_optionsObject



10
11
12
13
14
15
16
17
18
# File 'lib/action_network_rest/client.rb', line 10

def default_options
  {
    host: 'actionnetwork.org',
    prefix: '/api/v2',
    content_type: 'application/json',
    additional_headers: {'OSDI-API-Token' => api_key},
    user_agent: 'ruby: ActionNetworkRest'
  }
end

#entry_pointObject

Helpers to let users do things like ‘an_client.people.create(params)`



26
27
28
# File 'lib/action_network_rest/client.rb', line 26

def entry_point
  @_entry_point ||= ActionNetworkRest::EntryPoint.new(client: self)
end

#extract_data_from_params(params) ⇒ Object



20
21
22
# File 'lib/action_network_rest/client.rb', line 20

def extract_data_from_params(params)
  params.to_json
end

#peopleObject



30
31
32
# File 'lib/action_network_rest/client.rb', line 30

def people
  @_people ||= ActionNetworkRest::People.new(client: self)
end

#petitions(petition_id = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/action_network_rest/client.rb', line 34

def petitions(petition_id=nil)
  if @_petitions&.send(:[], petition_id).nil?
    @_petitions = {} if @_petitions.nil?

    @_petitions[petition_id] = ActionNetworkRest::Petitions.new(petition_id, client: self)
  end

  @_petitions[petition_id]
end

#tags(tag_id = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/action_network_rest/client.rb', line 44

def tags(tag_id=nil)
  if @_tags&.send(:[], tag_id).nil?
    @_tags = {} if @_tags.nil?

    @_tags[tag_id] = ActionNetworkRest::Tags.new(tag_id, client: self)
  end

  @_tags[tag_id]
end