Module: Fresh::Auth::Api

Defined in:
lib/fresh/auth/api.rb

Instance Method Summary collapse

Instance Method Details

#GenerateXml(klass, method, &block) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/fresh/auth/api.rb', line 11

def GenerateXml klass, method, &block
  xml = Builder::XmlMarkup.new( :indent => 2 )
  xml.instruct! :xml, :encoding => "utf-8"
  xml.request :method => "#{klass}.#{method}" do |req|
    yield xml
  end
end

#PostToFreshbooksApi(xml) ⇒ Object


19
20
21
22
23
# File 'lib/fresh/auth/api.rb', line 19

def PostToFreshbooksApi xml
  root = Nokogiri::XML(RestClient.post Fresh::Auth.configuration.url.api, xml, HttpHeaders()).root
  raise "Request to Freshbooks API failed:\n#{root}" if "ok" != root.attributes["status"].to_s
  root
end