Class: Tender::Discussion

Inherits:
Object
  • Object
show all
Defined in:
lib/tender/discussion.rb

Class Method Summary collapse

Class Method Details

.create(cat_id, options = {}) ⇒ Object

Raises:

  • (::RuntimeError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tender/discussion.rb', line 3

def self.create(cat_id, options = {})
  raise ::RuntimeError, ":body is a required option" if options[:body].blank?
  raise ::RuntimeError, "Currently only token authorization is supported. An auth token is required." if Tender.auth_token.blank?
  headers = { 
    'X-Tender-Auth' => Tender.auth_token, 
    'Accept' => 'application/json'
  }  
  url = 'https://api.tenderapp.com/zipzoomauto/'

  resp = HTTParty.post(url + "categories/#{cat_id}/discussions", 
    :headers => headers, 
    :body => {
      :title        => "",
      :skip_spam    => true,
      :public       => false,
      :body         => "",
      :author_email => "[email protected]",
      :author_name  => "Support API"
    }.merge(options),
    :format => :json
  )

  if resp.code == 201
    resps = class << resp; self; end
    resps.send(:define_method, :queue) do |id|
      Queue.add(resp['queue_href'], id)
    end
    resp
  else
    raise TenderError, "#{resp.flatten.join(" ")}"
  end
end