Class: Adzerk::ApiEndpoint

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/adzerk/api_endpoint.rb

Direct Known Subclasses

Advertiser, Creative, Flight, Priority, Publisher

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#camelize_data, #parse_response, #uncamelize_data

Constructor Details

#initialize(args = {}) ⇒ ApiEndpoint

Returns a new instance of ApiEndpoint.



8
9
10
11
12
13
# File 'lib/adzerk/api_endpoint.rb', line 8

def initialize(args= {})
  @client = args[:client]
  @endpoint = args[:endpoint]
  @subendpoint = args[:subendpoint]
  @datakey = args[:datakey] ? args[:datakey] : args[:endpoint]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/adzerk/api_endpoint.rb', line 6

def client
  @client
end

#datakeyObject (readonly)

Returns the value of attribute datakey.



6
7
8
# File 'lib/adzerk/api_endpoint.rb', line 6

def datakey
  @datakey
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/adzerk/api_endpoint.rb', line 6

def endpoint
  @endpoint
end

#subendpointObject (readonly)

Returns the value of attribute subendpoint.



6
7
8
# File 'lib/adzerk/api_endpoint.rb', line 6

def subendpoint
  @subendpoint
end

Instance Method Details

#create(opts = {}, subid = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/adzerk/api_endpoint.rb', line 15

def create(opts={}, subid=nil)
  e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
  data = { datakey => camelize_data(opts).to_json }
  response = @client.post_request(e, data)
  parse_response(response)
end

#delete(id, subid = nil) ⇒ Object



40
41
42
43
44
# File 'lib/adzerk/api_endpoint.rb', line 40

def delete(id, subid=nil)
  e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
  url = "#{e}/#{id}/delete"
  @client.get_request(url)
end

#get(id) ⇒ Object



22
23
24
25
# File 'lib/adzerk/api_endpoint.rb', line 22

def get(id)
  response = @client.get_request("#{endpoint}/#{id}")
  parse_response(response)
end

#list(subid = nil) ⇒ Object



27
28
29
30
31
# File 'lib/adzerk/api_endpoint.rb', line 27

def list(subid=nil)
  e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
  response = @client.get_request(e)
  parse_response(response)
end

#update(opts = {}) ⇒ Object



33
34
35
36
37
38
# File 'lib/adzerk/api_endpoint.rb', line 33

def update(opts={})
  id = opts[:id].to_s
  data = { datakey => camelize_data(opts).to_json }
  response = @client.put_request("#{endpoint}/#{id}", data)
  parse_response(response)
end