Class: Contactually::Base
- Inherits:
-
Object
- Object
- Contactually::Base
show all
- Defined in:
- lib/contactually/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url:, interface:) ⇒ Base
Returns a new instance of Base.
13
14
15
16
|
# File 'lib/contactually/base.rb', line 13
def initialize(url:, interface:)
@url = url
@interface = interface
end
|
Instance Attribute Details
#interface ⇒ Object
Returns the value of attribute interface.
3
4
5
|
# File 'lib/contactually/base.rb', line 3
def interface
@interface
end
|
#url ⇒ Object
Returns the value of attribute url.
3
4
5
|
# File 'lib/contactually/base.rb', line 3
def url
@url
end
|
Class Method Details
.implement_list ⇒ Object
9
10
11
|
# File 'lib/contactually/base.rb', line 9
def self.implement_list
@implements
end
|
.implements(*method_list) ⇒ Object
5
6
7
|
# File 'lib/contactually/base.rb', line 5
def self.implements(*method_list)
@implements = method_list
end
|
Instance Method Details
#check_implementation(method) ⇒ Object
57
58
59
|
# File 'lib/contactually/base.rb', line 57
def check_implementation(method)
raise 'Error' unless self.class.implement_list.include?(method)
end
|
#create(body) ⇒ Object
37
38
39
40
|
# File 'lib/contactually/base.rb', line 37
def create(body)
check_implementation(:create)
Response.new(interface.post(build_fetch_url, body), self)
end
|
#destroy(id) ⇒ Object
52
53
54
55
|
# File 'lib/contactually/base.rb', line 52
def destroy(id)
check_implementation(:destroy)
interface.destroy(build_fetch_url(id))
end
|
#fetch(id, params = {}) ⇒ Object
42
43
44
45
|
# File 'lib/contactually/base.rb', line 42
def fetch(id, params = {})
check_implementation(:fetch)
Response.new(interface.get(build_fetch_url(id), params), self)
end
|
#list(params = {}) ⇒ Object
18
19
20
21
|
# File 'lib/contactually/base.rb', line 18
def list(params = {})
check_implementation(:list)
Response.new(interface.get(url, params), self)
end
|
#list_each(params = {}, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/contactually/base.rb', line 23
def list_each(params = {}, &block)
check_implementation(:list)
if block_given?
list_in_batches(params) do |items|
items.each do |item|
block.call(item)
end
end
else
enum_for :list_each, params
end
end
|
#model ⇒ Object
61
62
63
|
# File 'lib/contactually/base.rb', line 61
def model
OpenStruct
end
|
#update(id, body) ⇒ Object
47
48
49
50
|
# File 'lib/contactually/base.rb', line 47
def update(id, body)
check_implementation(:update)
Response.new(interface.patch(build_fetch_url(id), body), self)
end
|