Class: Namely::ResourceGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/namely/resource_gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ResourceGateway

Returns a new instance of ResourceGateway.



5
6
7
8
9
10
# File 'lib/namely/resource_gateway.rb', line 5

def initialize(options)
  @access_token = options.fetch(:access_token)
  @endpoint = options.fetch(:endpoint)
  @subdomain = options.fetch(:subdomain)
  @paged = options.fetch(:paged, false)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



3
4
5
# File 'lib/namely/resource_gateway.rb', line 3

def endpoint
  @endpoint
end

Instance Method Details

#create(attributes) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/namely/resource_gateway.rb', line 24

def create(attributes)
  response = post(
    "/#{endpoint}",
    endpoint => [attributes]
  )
  extract_id(response)
end

#json_indexObject



12
13
14
# File 'lib/namely/resource_gateway.rb', line 12

def json_index
  paged ? json_index_paged : json_index_all
end

#json_show(id) ⇒ Object



16
17
18
# File 'lib/namely/resource_gateway.rb', line 16

def json_show(id)
  get("/#{endpoint}/#{id}")[resource_name].first
end

#show_head(id) ⇒ Object



20
21
22
# File 'lib/namely/resource_gateway.rb', line 20

def show_head(id)
  head("/#{endpoint}/#{id}")
end

#update(id, changes) ⇒ Object



32
33
34
# File 'lib/namely/resource_gateway.rb', line 32

def update(id, changes)
  put("/#{endpoint}/#{id}", endpoint => [changes])
end