Class: Balloon::Http::Client
- Inherits:
-
Object
- Object
- Balloon::Http::Client
- Defined in:
- lib/balloon/http/client.rb
Instance Attribute Summary collapse
-
#conn_build ⇒ Object
Returns the value of attribute conn_build.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pass ⇒ Object
readonly
Returns the value of attribute pass.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #basic_auth(login, pass) ⇒ Object
- #builder(&block) ⇒ Object
- #delete(uri, &block) ⇒ Object
- #get(uri, query = {}, &block) ⇒ Object
-
#initialize(uri = nil, options = nil) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #post(uri, query = {}, size = nil, &block) ⇒ Object
- #put(uri, query = {}, size = nil, &block) ⇒ Object
- #request(verb, uri, query = {}, size = nil) ⇒ Object
- #token_auth(klass, token) ⇒ Object
Constructor Details
#initialize(uri = nil, options = nil) {|_self| ... } ⇒ Client
Returns a new instance of Client.
21 22 23 24 |
# File 'lib/balloon/http/client.rb', line 21 def initialize(uri = nil, = nil, &block) @url = uri yield self if block_given? end |
Instance Attribute Details
#conn_build ⇒ Object
Returns the value of attribute conn_build.
19 20 21 |
# File 'lib/balloon/http/client.rb', line 19 def conn_build @conn_build end |
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/balloon/http/client.rb', line 17 def connection @connection end |
#headers ⇒ Object
Returns the value of attribute headers.
13 14 15 |
# File 'lib/balloon/http/client.rb', line 13 def headers @headers end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
11 12 13 |
# File 'lib/balloon/http/client.rb', line 11 def klass @klass end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
9 10 11 |
# File 'lib/balloon/http/client.rb', line 9 def login @login end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/balloon/http/client.rb', line 15 def @options end |
#pass ⇒ Object (readonly)
Returns the value of attribute pass.
9 10 11 |
# File 'lib/balloon/http/client.rb', line 9 def pass @pass end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
11 12 13 |
# File 'lib/balloon/http/client.rb', line 11 def token @token end |
#url ⇒ Object
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(login, pass) @login = 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 |