Class: AppnexusApi::Service
- Inherits:
-
Object
- Object
- AppnexusApi::Service
show all
- Defined in:
- lib/appnexusapi/service.rb
Direct Known Subclasses
AdServerService, BidderInstanceService, BidderService, BrowserService, CategoryService, ContentCategoryService, CreativeService, DomainListService, InventoryAttributeService, InventorySourceService, LanguageService, MemberService, OperatingSystemService, PlatformMemberService, SegmentService, TinyTagService, UserService
Instance Method Summary
collapse
Constructor Details
#initialize(connection) ⇒ Service
Returns a new instance of Service.
3
4
5
|
# File 'lib/appnexusapi/service.rb', line 3
def initialize(connection)
@connection = connection
end
|
Instance Method Details
#create(attributes = {}) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/appnexusapi/service.rb', line 40
def create(attributes={})
raise(AppnexusApi::NotImplemented, "Service is read-only.") if @read_only
attributes = { name => attributes }
response = @connection.post(uri_suffix, attributes)
get("id" => response["id"]).first
end
|
#delete(id) ⇒ Object
54
55
56
57
|
# File 'lib/appnexusapi/service.rb', line 54
def delete(id)
raise(AppnexusApi::NotImplemented, "Service is read-only.") if @read_only
@connection.delete([uri_suffix, id].join('/'))
end
|
#get(params = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/appnexusapi/service.rb', line 25
def get(params={})
params = {
"num_elements" => 100,
"start_element" => 0
}.merge(params)
response = @connection.get(uri_suffix, params)
if response.has_key?(plural_name)
response[plural_name].map do |json|
resource_class.new(json, self)
end
elsif response.has_key?(name)
[resource_class.new(response[name], self)]
end
end
|
#name ⇒ Object
7
8
9
10
|
# File 'lib/appnexusapi/service.rb', line 7
def name
str = self.class.name.split("::").last.gsub("Service", "")
str.gsub(/(.)([A-Z])/, '\1_\2').downcase
end
|
#plural_name ⇒ Object
12
13
14
|
# File 'lib/appnexusapi/service.rb', line 12
def plural_name
name + 's'
end
|
#resource_class ⇒ Object
16
17
18
19
|
# File 'lib/appnexusapi/service.rb', line 16
def resource_class
resource_name = name.capitalize.gsub(/(_(.))/) { |c| $2.upcase }
AppnexusApi.const_get(resource_name + "Resource")
end
|
#update(id, attributes = {}) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/appnexusapi/service.rb', line 47
def update(id, attributes={})
raise(AppnexusApi::NotImplemented, "Service is read-only.") if @read_only
attributes = { name => attributes }
response = @connection.put([uri_suffix, id].join('/'), attributes)
get("id" => response["id"]).first
end
|
#uri_suffix ⇒ Object
21
22
23
|
# File 'lib/appnexusapi/service.rb', line 21
def uri_suffix
name.gsub('_', '-')
end
|