Class: GiantClient::AbstractAdapter
- Inherits:
-
Object
- Object
- GiantClient::AbstractAdapter
show all
- Defined in:
- lib/giant_client/abstract_adapter.rb
Instance Method Summary
collapse
Instance Method Details
#delete(opts) ⇒ Object
62
63
64
|
# File 'lib/giant_client/abstract_adapter.rb', line 62
def delete(opts)
request(:delete, opts)
end
|
#encode_query(query) ⇒ Object
18
19
20
21
22
|
# File 'lib/giant_client/abstract_adapter.rb', line 18
def encode_query(query)
query = stringify_query(query)
query = prepend_question_mark(query) unless query == ''
query
end
|
#get(opts) ⇒ Object
50
51
52
|
# File 'lib/giant_client/abstract_adapter.rb', line 50
def get(opts)
request(:get, opts)
end
|
#head(opts) ⇒ Object
66
67
68
|
# File 'lib/giant_client/abstract_adapter.rb', line 66
def head(opts)
request(:head, opts)
end
|
46
47
48
|
# File 'lib/giant_client/abstract_adapter.rb', line 46
def ()
.split('-').map{|h| h.capitalize}.join('-')
end
|
37
38
39
40
41
42
43
44
|
# File 'lib/giant_client/abstract_adapter.rb', line 37
def ()
= {}
.each do |, value|
normalized = ()
[normalized] = value
end
end
|
#post(opts) ⇒ Object
54
55
56
|
# File 'lib/giant_client/abstract_adapter.rb', line 54
def post(opts)
request(:post, opts)
end
|
#prepend_question_mark(str) ⇒ Object
33
34
35
|
# File 'lib/giant_client/abstract_adapter.rb', line 33
def prepend_question_mark(str)
"?#{str}"
end
|
#put(opts) ⇒ Object
58
59
60
|
# File 'lib/giant_client/abstract_adapter.rb', line 58
def put(opts)
request(:put, opts)
end
|
#stringify_query(query) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/giant_client/abstract_adapter.rb', line 24
def stringify_query(query)
if Hash === query
query = URI.encode_www_form(query)
elsif query.nil?
query = ''
end
query
end
|
#url_from_opts(opts) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/giant_client/abstract_adapter.rb', line 4
def url_from_opts(opts)
query = encode_query(opts[:query])
if opts[:ssl]
scheme = 'https://'
port = opts[:port] == 443 ? '' : ":#{opts[:port]}"
else
scheme = 'http://'
port = opts[:port] == 80 ? '' : ":#{opts[:port]}"
end
"#{scheme}#{opts[:host]}#{port}#{opts[:path]}#{query}"
end
|