Class: Tire::HTTP::Client::RestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/searchbox-tire/client.rb

Constant Summary collapse

ConnectionExceptions =
[::RestClient::ServerBrokeConnection, ::RestClient::RequestTimeout]

Class Method Summary collapse

Class Method Details

.delete(url) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/searchbox-tire/client.rb', line 35

def self.delete(url)
  perform ::RestClient.delete(url, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
rescue *ConnectionExceptions
  raise
rescue ::RestClient::Exception => e
  Response.new e.http_body, e.http_code
end

.get(url, data = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/searchbox-tire/client.rb', line 10

def self.get(url, data=nil)

  perform ::RestClient::Request.new(:method => :get, :url => url, :payload => data, :headers => {Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY}).execute
rescue *ConnectionExceptions
  raise
rescue ::RestClient::Exception => e
  Response.new e.http_body, e.http_code
end

.head(url) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/searchbox-tire/client.rb', line 43

def self.head(url)
  perform ::RestClient.head(url, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
rescue *ConnectionExceptions
  raise
rescue ::RestClient::Exception => e
  Response.new e.http_body, e.http_code
end

.post(url, data) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/searchbox-tire/client.rb', line 19

def self.post(url, data)
  perform ::RestClient.post(url, data, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
rescue *ConnectionExceptions
  raise
rescue ::RestClient::Exception => e
  Response.new e.http_body, e.http_code
end

.put(url, data) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/searchbox-tire/client.rb', line 27

def self.put(url, data)
  perform ::RestClient.put(url, data, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
rescue *ConnectionExceptions
  raise
rescue ::RestClient::Exception => e
  Response.new e.http_body, e.http_code
end