Class: ApiClient::Resource::Scope

Inherits:
Scope
  • Object
show all
Defined in:
lib/api_client/resource/scope.rb

Instance Attribute Summary

Attributes inherited from Scope

#scopeable

Instance Method Summary collapse

Methods inherited from Scope

#clone_only_headers, #connection, #delete, #fetch, #get, #headers, #initialize, #method_missing, #options, #params, #patch, #post, #put, #raw, #raw?, #raw_body, #request

Methods included from Mixins::Configuration

#dsl_accessor

Methods included from Mixins::Delegation

#delegate

Constructor Details

This class inherits a constructor from ApiClient::Scope

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ApiClient::Scope

Instance Method Details

#append_format(path) ⇒ Object



14
15
16
# File 'lib/api_client/resource/scope.rb', line 14

def append_format(path)
  format ? [path, format].join('.') : path
end

#create(params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/api_client/resource/scope.rb', line 35

def create(params = {})
  path = append_format(@path)
  hash = if @scopeable.namespace
    { @scopeable.namespace => params }
  else
    params
  end
  response = post(path, hash)
  scoped(self) do
    raw? ? response : @scopeable.build(response)
  end
end

#destroy(id) ⇒ Object



62
63
64
65
66
67
# File 'lib/api_client/resource/scope.rb', line 62

def destroy(id)
  path = [@path, id].join('/')
  path = append_format(path)
  delete(path)
  true
end

#find(id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/api_client/resource/scope.rb', line 18

def find(id)
  path     = [@path, id].join('/')
  path     = append_format(path)
  response = get(path)
  scoped(self) do
    raw? ? response : @scopeable.build(response)
  end
end

#find_all(params = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/api_client/resource/scope.rb', line 27

def find_all(params = {})
  path     = append_format(@path)
  response = get(path, params)
  scoped(self) do
    raw? ? response : @scopeable.build(response)
  end
end

#formatObject



10
11
12
# File 'lib/api_client/resource/scope.rb', line 10

def format
  @scopeable.format
end

#update(id, params = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/api_client/resource/scope.rb', line 48

def update(id, params = {})
  path = [@path, id].join('/')
  path = append_format(path)
  hash = if @scopeable.namespace
    { @scopeable.namespace => params }
  else
    params
  end
  response = put(path, hash)
  scoped(self) do
    raw? ? response : @scopeable.build(response)
  end
end