Class: GdsApi::NeedApi

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/need_api.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list!, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#close(need_id, duplicate_of) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/gds_api/need_api.rb', line 28

def close(need_id, duplicate_of)
  # duplicate_of is a hash of the required fields for closing
  # a need as a duplicate: { "duplicate_of" => 100001,
  #                          "author" => { ... }
  #                        }
  put_json!("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}/closed", duplicate_of)
end

#create_need(need) ⇒ Object



15
16
17
# File 'lib/gds_api/need_api.rb', line 15

def create_need(need)
  post_json!("#{endpoint}/needs", need)
end

#need(need_id) ⇒ Object



11
12
13
# File 'lib/gds_api/need_api.rb', line 11

def need(need_id)
  get_json("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}")
end

#needs(options = {}) ⇒ Object



5
6
7
8
9
# File 'lib/gds_api/need_api.rb', line 5

def needs(options = {})
  query = query_string(options)

  get_list!("#{endpoint}/needs#{query}")
end

#organisationsObject



24
25
26
# File 'lib/gds_api/need_api.rb', line 24

def organisations
  get_json!("#{endpoint}/organisations")["organisations"]
end

#reopen(need_id, author) ⇒ Object



36
37
38
39
# File 'lib/gds_api/need_api.rb', line 36

def reopen(need_id, author)
  # author params: { "author" => { ... } }"
  delete_json!("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}/closed", author)
end

#update_need(need_id, need_update) ⇒ Object



19
20
21
22
# File 'lib/gds_api/need_api.rb', line 19

def update_need(need_id, need_update)
  # `need_update` can be a hash of updated fields or a complete need
  put_json!("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}", need_update)
end