Class: Resizor::ResizorConnection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ResizorConnection

Returns a new instance of ResizorConnection.



6
7
8
9
10
11
12
# File 'lib/resizor/connection.rb', line 6

def initialize(options={})
  @api_host = options[:api_host] || options['api_host'] || 'resizor.com'
  @api_port = options[:api_port] || options['api_port'] || 80
  @api_key  = options[:api_key] || options['api_key']
  @use_ssl  = options[:use_ssl] || options['use_ssl'] || true
  @cdn_host  = options[:cdn_host] || options['cdn_host']
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



4
5
6
# File 'lib/resizor/connection.rb', line 4

def api_host
  @api_host
end

#api_keyObject

Returns the value of attribute api_key.



4
5
6
# File 'lib/resizor/connection.rb', line 4

def api_key
  @api_key
end

#api_portObject

Returns the value of attribute api_port.



4
5
6
# File 'lib/resizor/connection.rb', line 4

def api_port
  @api_port
end

#cdn_hostObject

Returns the value of attribute cdn_host.



4
5
6
# File 'lib/resizor/connection.rb', line 4

def cdn_host
  @cdn_host
end

#use_sslObject

Returns the value of attribute use_ssl.



4
5
6
# File 'lib/resizor/connection.rb', line 4

def use_ssl
  @use_ssl
end

Instance Method Details

#api_url(force_http = false) ⇒ Object



37
38
39
# File 'lib/resizor/connection.rb', line 37

def api_url(force_http = false)
  "#{(@use_ssl == true && force_http == false) ? 'https' : 'http'}://#{@api_host}:#{(@use_ssl == true && force_http == false) ? '443' : @api_port}"
end

#delete(request_uri, params = {}, append_api_key = true) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/resizor/connection.rb', line 29

def delete(request_uri, params={}, append_api_key=true)
  params[:api_key] = @api_key if append_api_key
  query = make_query(params)
  do_request do
    make_response_for resource[request_uri + '?' + query].delete
  end
end

#get(request_uri, params = {}, append_api_key = true) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/resizor/connection.rb', line 14

def get(request_uri, params={}, append_api_key=true)
  params[:api_key] = @api_key if append_api_key
  query = make_query(params)
  do_request do
    make_response_for resource[request_uri + '?' + query].get
  end
end

#post(request_uri, params = {}, append_api_key = true) ⇒ Object



22
23
24
25
26
27
# File 'lib/resizor/connection.rb', line 22

def post(request_uri, params={}, append_api_key=true)
  params[:api_key] = @api_key if append_api_key
  do_request do
    make_response_for resource[request_uri].post params
  end
end