Module: FuelSDK::Rest
Instance Attribute Summary
Attributes included from Targeting
#auth_token, #endpoint
Instance Method Summary
collapse
Methods included from Targeting
#determine_stack, #refresh
Instance Method Details
#complete_url(url, url_properties) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/fuelsdk/rest.rb', line 30
def complete_url url, url_properties
normalize_keys(url_properties)
url = url % url_properties if url_properties
url.end_with?('/') ? url.chop : url
rescue KeyError => ex
raise "#{ex.message} to complete #{url}"
end
|
#get_url_properties(url, properties) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/fuelsdk/rest.rb', line 19
def get_url_properties url, properties
url_property_names = url.scan(/(%{(.+?)})/).collect{|frmt, name| name}
url_properties = {}
properties.keys.each do |k|
if url_property_names.include? k
url_properties[k] = properties.delete(k)
end
end
url_properties
end
|
#normalize_keys(obj) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/fuelsdk/rest.rb', line 10
def normalize_keys obj
if obj and obj.is_a? Hash
obj.keys.each do |k|
obj[(k.to_sym rescue k) || k] = obj.delete(k)
end
end
obj
end
|
#parse_properties(url, properties) ⇒ Object
38
39
40
41
42
|
# File 'lib/fuelsdk/rest.rb', line 38
def parse_properties url, properties
url_properties = get_url_properties url, properties
url = complete_url url, url_properties
[url, properties]
end
|
#rest_client ⇒ Object
6
7
8
|
# File 'lib/fuelsdk/rest.rb', line 6
def rest_client
self
end
|
#rest_delete(url, properties = {}) ⇒ Object
49
50
51
52
|
# File 'lib/fuelsdk/rest.rb', line 49
def rest_delete url, properties={}
url, properties = parse_properties url, properties
rest_request :delete, url
end
|
#rest_get(url, properties = {}) ⇒ Object
44
45
46
47
|
# File 'lib/fuelsdk/rest.rb', line 44
def rest_get url, properties={}
url, properties = parse_properties url, properties
rest_request :get, url, {'params' => properties}
end
|
#rest_patch(url, properties = {}) ⇒ Object
54
55
56
57
58
|
# File 'lib/fuelsdk/rest.rb', line 54
def rest_patch url, properties={}
url, payload = parse_properties url, properties
rest_request :patch, url, {'data' => payload,
'content_type' => 'application/json'}
end
|
#rest_post(url, properties = {}) ⇒ Object
60
61
62
63
64
|
# File 'lib/fuelsdk/rest.rb', line 60
def rest_post url, properties={}
url, payload = parse_properties url, properties
rest_request :post, url, {'data' => payload,
'content_type' => 'application/json'}
end
|