Class: Blockr::Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Connection

Returns a new instance of Connection.



5
6
7
# File 'lib/blockr/connection.rb', line 5

def initialize(url=nil)
  @url = url
end

Instance Method Details

#get(path, payload = {}) ⇒ Object



9
10
11
# File 'lib/blockr/connection.rb', line 9

def get(path, payload={})
  query :get, path, payload
end

#post(path, payload = {}) ⇒ Object



13
14
15
# File 'lib/blockr/connection.rb', line 13

def post(path, payload={})
  query :post, path, payload
end

#query(method, path, payload = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/blockr/connection.rb', line 17

def query(method, path, payload={})
  uri = endpoint_uri(path)
  begin
    response = RestClient::Request.execute(:method => method, :url => uri, :payload => payload, :ssl_version => 'SSLv23')
  rescue Exception => e
    response = e.response
  end
  JSON.parse response, :symbolize_names => true
end