Class: Givepulse::Connection
- Inherits:
-
Object
- Object
- Givepulse::Connection
- Defined in:
- lib/givepulse/connection.rb
Constant Summary collapse
- API_ROOT =
URI('https://api2.givepulse.com').freeze
Instance Attribute Summary collapse
-
#authorization_token ⇒ Object
writeonly
Sets the attribute authorization_token.
Instance Method Summary collapse
- #delete(path, options = nil) ⇒ Object
- #get(path, options = nil) ⇒ Object
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #post(path, data, options = nil) ⇒ Object
- #put(path, data, options = nil) ⇒ Object
- #with_headers(headers) {|_self| ... } ⇒ Object
Constructor Details
#initialize ⇒ Connection
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
10 11 12 |
# File 'lib/givepulse/connection.rb', line 10 def (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, = nil) query_string = () 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, = nil) query_string = () 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, = nil) query_string = () 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, = nil) query_string = () 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
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 |