Class: Hurley::Client
- Inherits:
-
Object
- Object
- Hurley::Client
- Extended by:
- Forwardable
- Defined in:
- lib/hurley/client.rb
Instance Attribute Summary collapse
- #connection ⇒ Object
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#request_options ⇒ Object
readonly
Returns the value of attribute request_options.
-
#ssl_options ⇒ Object
readonly
Returns the value of attribute ssl_options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #after_call(name_or_callback = nil) ⇒ Object
- #after_callbacks ⇒ Object
- #before_call(name_or_callback = nil) ⇒ Object
- #before_callbacks ⇒ Object
- #call(request) ⇒ Object
- #delete(path, query = nil) {|req| ... } ⇒ Object
- #get(path, query = nil) {|req| ... } ⇒ Object
- #head(path, query = nil) {|req| ... } ⇒ Object
-
#initialize(endpoint = nil) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #options(path, query = nil) {|req| ... } ⇒ Object
- #patch(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
- #post(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
- #put(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
- #request(method, path) ⇒ Object
Constructor Details
#initialize(endpoint = nil) {|_self| ... } ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hurley/client.rb', line 13 def initialize(endpoint = nil) @before_callbacks = [] @after_callbacks = [] @url = Url.parse(endpoint) @header = Header.new :user_agent => Hurley::USER_AGENT @connection = nil @request_options = RequestOptions.new @ssl_options = SslOptions.new yield self if block_given? end |
Instance Attribute Details
#connection ⇒ Object
32 33 34 |
# File 'lib/hurley/client.rb', line 32 def connection @connection ||= Hurley.default_connection end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
8 9 10 |
# File 'lib/hurley/client.rb', line 8 def header @header end |
#request_options ⇒ Object (readonly)
Returns the value of attribute request_options.
10 11 12 |
# File 'lib/hurley/client.rb', line 10 def @request_options end |
#ssl_options ⇒ Object (readonly)
Returns the value of attribute ssl_options.
11 12 13 |
# File 'lib/hurley/client.rb', line 11 def @ssl_options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/hurley/client.rb', line 7 def url @url end |
Instance Method Details
#after_call(name_or_callback = nil) ⇒ Object
98 99 100 101 102 |
# File 'lib/hurley/client.rb', line 98 def after_call(name_or_callback = nil) @after_callbacks << (block_given? ? NamedCallback.for(name_or_callback , Proc.new) : NamedCallback.for(nil, name_or_callback)) end |
#after_callbacks ⇒ Object
108 109 110 |
# File 'lib/hurley/client.rb', line 108 def after_callbacks @after_callbacks.map(&:name) end |
#before_call(name_or_callback = nil) ⇒ Object
92 93 94 95 96 |
# File 'lib/hurley/client.rb', line 92 def before_call(name_or_callback = nil) @before_callbacks << (block_given? ? NamedCallback.for(name_or_callback, Proc.new) : NamedCallback.for(nil, name_or_callback)) end |
#before_callbacks ⇒ Object
104 105 106 |
# File 'lib/hurley/client.rb', line 104 def before_callbacks @before_callbacks.map(&:name) end |
#call(request) ⇒ Object
88 89 90 |
# File 'lib/hurley/client.rb', line 88 def call(request) call_with_redirects(request, []) end |
#delete(path, query = nil) {|req| ... } ⇒ Object
74 75 76 77 78 79 |
# File 'lib/hurley/client.rb', line 74 def delete(path, query = nil) req = request(:delete, path) req.query.update(query) if query yield req if block_given? call(req) end |
#get(path, query = nil) {|req| ... } ⇒ Object
43 44 45 46 47 48 |
# File 'lib/hurley/client.rb', line 43 def get(path, query = nil) req = request(:get, path) req.query.update(query) if query yield req if block_given? call(req) end |
#head(path, query = nil) {|req| ... } ⇒ Object
36 37 38 39 40 41 |
# File 'lib/hurley/client.rb', line 36 def head(path, query = nil) req = request(:head, path) req.query.update(query) if query yield req if block_given? call(req) end |
#options(path, query = nil) {|req| ... } ⇒ Object
81 82 83 84 85 86 |
# File 'lib/hurley/client.rb', line 81 def (path, query = nil) req = request(:options, path) req.query.update(query) if query yield req if block_given? call(req) end |
#patch(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/hurley/client.rb', line 50 def patch(path, body = nil, ctype = nil) req = request(:patch, path) req.body = body if body req.header[:content_type] = ctype if ctype yield req if block_given? call(req) end |
#post(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/hurley/client.rb', line 66 def post(path, body = nil, ctype = nil) req = request(:post, path) req.body = body if body req.header[:content_type] = ctype if ctype yield req if block_given? call(req) end |
#put(path, body = nil, ctype = nil) {|req| ... } ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/hurley/client.rb', line 58 def put(path, body = nil, ctype = nil) req = request(:put, path) req.body = body if body req.header[:content_type] = ctype if ctype yield req if block_given? call(req) end |