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
# 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)
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



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

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

#json_indexObject



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

def json_index
  get("/#{endpoint}", limit: :all)[resource_name]
end

#json_show(id) ⇒ Object



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

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

#show_head(id) ⇒ Object



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

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

#update(id, changes) ⇒ Object



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

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