Class: Insightly::ReadWrite
- Inherits:
-
Base
- Object
- Base
- Insightly::ReadWrite
show all
- Defined in:
- lib/insightly/read_write.rb
Instance Method Summary
collapse
Methods inherited from Base
#==, all, api_field, build, #build, #config, custom_fields, #get_collection, #initialize, #load, #process, #reload, #remote_data, #remote_id, #url_base
Instance Method Details
#post_collection(path, params, content_selector = :json) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/insightly/read_write.rb', line 20
def post_collection(path, params, content_selector = :json)
if content_selector == :xml_raw
content_type = :xml
else
content_type = content_selector
end
response = RestClient::Request.new(:method => :post,
:url => "#{config.endpoint}/#{path.to_s}",
:user => config.api_key,
:password => "",
:payload => params,
:headers => {:accept => content_type, :content_type => content_type}).execute
process(response, content_selector)
end
|
#put_collection(path, params, content_selector = :json) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/insightly/read_write.rb', line 35
def put_collection(path, params, content_selector = :json)
if content_selector == :xml_raw
content_type = :xml
else
content_type = content_selector
end
response = RestClient::Request.new(:method => :put,
:url => "#{config.endpoint}/#{path.to_s}",
:user => config.api_key,
:password => "",
:payload => params,
:headers => {:accept => content_type, :content_type => content_type}).execute
process(response, content_selector)
end
|
#save ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/insightly/read_write.rb', line 9
def save
if !remote_id
update_data(post_collection("#{url_base}", self.to_json))
else
update_data(put_collection("#{url_base}/#{remote_id}", self.to_json))
end
end
|
#to_json ⇒ Object
3
4
5
|
# File 'lib/insightly/read_write.rb', line 3
def to_json
@data.to_json
end
|
#update_data(data) ⇒ Object
6
7
8
|
# File 'lib/insightly/read_write.rb', line 6
def update_data(data)
@data = data
end
|