Class: ClickSign::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/click_sign/service.rb

Defined Under Namespace

Classes: ErrorResponse, Response

Class Method Summary collapse

Class Method Details

.accept_headerObject

<CLASS METHODS>



64
65
66
# File 'lib/click_sign/service.rb', line 64

def self.accept_header
	{ Accept: 'application/json' }
end

.api_url(*path) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/click_sign/service.rb', line 72

def self.api_url(*path)
	url = [ClickSign::Configuration.sandbox ? ClickSign::Configuration.sandbox_url : ClickSign::Configuration.url]
	url += ['api']
	url += [ClickSign::Configuration.api_version]
	url += path
	url.join("/") + "?access_token=#{ClickSign::Configuration.access_token}"
end

.content_typeObject



68
69
70
# File 'lib/click_sign/service.rb', line 68

def self.content_type
	{ 'Content-Type': 'application/json'}
end

.delete(url: nil, payload: nil) ⇒ Object



92
93
94
# File 'lib/click_sign/service.rb', line 92

def self.delete url: nil, payload: nil
	request method: :delete, url: url, payload: payload
end

.get(url: nil, payload: nil) ⇒ Object



80
81
82
# File 'lib/click_sign/service.rb', line 80

def self.get url: nil, payload: nil
	request method: :get, url: url, payload: payload
end

.patch(url: nil, payload: nil) ⇒ Object



88
89
90
# File 'lib/click_sign/service.rb', line 88

def self.patch url: nil, payload: nil
	request method: :patch, url: url, payload: payload
end

.post(url: nil, payload: nil) ⇒ Object



84
85
86
# File 'lib/click_sign/service.rb', line 84

def self.post url: nil, payload: nil
	request method: :post, url: url, payload: payload
end

.request(method: nil, url: nil, payload: nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/click_sign/service.rb', line 96

def self.request method: nil, url: nil, payload: nil
	begin
		response = RestClient::Request.execute(
			method: method,
			url: api_url(url),
			payload: payload,
			headers: accept_header,
			content_type: content_type
     )
     ClickSign::Service::Response.new(status_code: response.code, body: response.body)
    rescue RestClient::ExceptionWithResponse => _e
    	ClickSign::Servive::ErrorResponse.new(status_code: _e.response.code, body: _e.response.body)
    rescue RestClient::ServerBrokeConnection => _e
    	ap _e
    rescue RestClient::SSLCertificateNotVerified => _e 
    	ap _e
    end
end