Class: Balloon::Http::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/balloon/http/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil, options = nil) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
# File 'lib/balloon/http/client.rb', line 21

def initialize(uri = nil, options = nil, &block)
  @url = uri
  yield self if block_given?
end

Instance Attribute Details

#conn_buildObject

Returns the value of attribute conn_build.



19
20
21
# File 'lib/balloon/http/client.rb', line 19

def conn_build
  @conn_build
end

#connectionObject

Returns the value of attribute connection.



17
18
19
# File 'lib/balloon/http/client.rb', line 17

def connection
  @connection
end

#headersObject

Returns the value of attribute headers.



13
14
15
# File 'lib/balloon/http/client.rb', line 13

def headers
  @headers
end

#klassObject (readonly)

Returns the value of attribute klass.



11
12
13
# File 'lib/balloon/http/client.rb', line 11

def klass
  @klass
end

#loginObject (readonly)

Returns the value of attribute login.



9
10
11
# File 'lib/balloon/http/client.rb', line 9

def 
  @login
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/balloon/http/client.rb', line 15

def options
  @options
end

#passObject (readonly)

Returns the value of attribute pass.



9
10
11
# File 'lib/balloon/http/client.rb', line 9

def pass
  @pass
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/balloon/http/client.rb', line 11

def token
  @token
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/balloon/http/client.rb', line 7

def url
  @url
end

Instance Method Details

#basic_auth(login, pass) ⇒ Object



35
36
37
38
# File 'lib/balloon/http/client.rb', line 35

def basic_auth(, pass)
  @login = 
  @pass = pass
end

#builder(&block) ⇒ Object



26
27
28
# File 'lib/balloon/http/client.rb', line 26

def builder(&block)
  @conn_build = block
end

#delete(uri, &block) ⇒ Object



86
87
88
# File 'lib/balloon/http/client.rb', line 86

def delete(uri, &block)
  request(:delete, uri, nil, 0, &block)
end

#get(uri, query = {}, &block) ⇒ Object



72
73
74
# File 'lib/balloon/http/client.rb', line 72

def get(uri, query = {}, &block) 
  request(:get, uri, query, 0, &block)
end

#post(uri, query = {}, size = nil, &block) ⇒ Object



76
77
78
79
# File 'lib/balloon/http/client.rb', line 76

def post(uri, query = {}, size = nil, &block)
  size = size || 0
  request(:post, uri, query, size,&block)
end

#put(uri, query = {}, size = nil, &block) ⇒ Object



81
82
83
84
# File 'lib/balloon/http/client.rb', line 81

def put(uri, query  = {}, size = nil, &block)
  size = size || 0
  request(:put, uri, query, size, &block)
end

#request(verb, uri, query = {}, size = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/balloon/http/client.rb', line 56

def request(verb, uri, query={}, size = nil)
  headers['Authorization'] = klass.instance_eval(token.call(verb.to_s.upcase, uri, size, headers['Date'])) if token
  verb == :get ? query_get = query : query_post = query
  uri = connection.build_url(uri, query_get)
  response = connection.run_request(verb, uri, query_post, headers) do |request|
    yield request if block_given?
  end
  response = Response.new(response)
  case response.status
  when 301, 302, 303, 307
    request(verb, response.headers['location'], query)
  when 200..299, 300..399
    response
  end
end

#token_auth(klass, token) ⇒ Object



40
41
42
43
# File 'lib/balloon/http/client.rb', line 40

def token_auth(klass, token)
  @klass = klass
  @token = token
end