module Fresh::Auth::Api

Public Instance Methods

GenerateXml(klass, method) { |xml| ... } click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

HttpHeaders() click to toggle source
# File lib/fresh/auth/api.rb, line 25
def HttpHeaders
  _header = {
    :'OAuth realm' => "",
    Key::AUTH_TOKEN => session[Key::SESSION][Key::AUTH_TOKEN]
  }.merge Parameters.Common()
  _header[Key::SIGNATURE] += session[Key::SESSION][Key::AUTH_SECRET]
  val = ""
  _header.collect{ |k, v| val += "#{k}=\"#{v}\","}
  { :Authorization => val.chomp(",") }
end