Class: Givepulse::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/givepulse/connection.rb

Constant Summary collapse

API_ROOT =
URI('https://api2.givepulse.com').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



12
13
14
15
16
# File 'lib/givepulse/connection.rb', line 12

def initialize
    @client = Net::HTTP.new(API_ROOT.host, API_ROOT.port)
    @client.use_ssl = true
    @custom_headers = nil
end

Instance Attribute Details

#authorization_token=(value) ⇒ Object (writeonly)

Sets the attribute authorization_token

Parameters:

  • value

    the value to set the attribute authorization_token to.



10
11
12
# File 'lib/givepulse/connection.rb', line 10

def authorization_token=(value)
  @authorization_token = value
end

Instance Method Details

#delete(path, options = nil) ⇒ Object



39
40
41
42
43
44
# File 'lib/givepulse/connection.rb', line 39

def delete(path, options = nil)
    query_string = options_to_query(options)
    full_path = "#{path}?#{query_string}"
    response = @client.delete(full_path, generate_headers(@custom_headers))
    JSON.parse(response.body)
end

#get(path, options = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/givepulse/connection.rb', line 18

def get(path, options = nil)
    query_string = options_to_query(options)
    full_path = "#{path}?#{query_string}"
    response = @client.get(full_path, generate_headers(@custom_headers))
    JSON.parse(response.body)
end

#post(path, data, options = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/givepulse/connection.rb', line 25

def post(path, data, options = nil)
    query_string = options_to_query(options)
    full_path = "#{path}?#{query_string}"
    response = @client.post(full_path, data, generate_headers(@custom_headers))
    JSON.parse(response.body)
end

#put(path, data, options = nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/givepulse/connection.rb', line 32

def put(path, data, options = nil)
    query_string = options_to_query(options)
    full_path = "#{path}?#{query_string}"
    response = @client.put(full_path, data, generate_headers(@custom_headers))
    JSON.parse(response.body)
end

#with_headers(headers) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



46
47
48
49
50
# File 'lib/givepulse/connection.rb', line 46

def with_headers(headers)
    @custom_headers = headers
    yield(self)
    @custom_headers = nil
end