Class: OmniAuth::Strategies::FreshBooks

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/freshbooks.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



59
60
61
62
# File 'lib/omniauth/strategies/freshbooks.rb', line 59

def callback_phase
  options.client_options.site = session["oauth"][name.to_s]["site"] if session["oauth"].present?
  super
end

#raw_infoObject



64
65
66
# File 'lib/omniauth/strategies/freshbooks.rb', line 64

def raw_info
  @raw_info ||= MultiXml.parse(access_token.post("/api/2.1/xml-in", '<?xml version="1.0" encoding="utf-8"?><request method="staff.current"></request>').body).fetch("response").fetch("staff")
end

#redirect(*args) ⇒ Object



36
37
38
39
40
41
# File 'lib/omniauth/strategies/freshbooks.rb', line 36

def redirect(*args)
  session["oauth"][name.to_s].merge!({
    "site" => options.client_options.site
  })
  super
end

#request_phaseObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/omniauth/strategies/freshbooks.rb', line 43

def request_phase
  options.client_options.site = options.site.presence || session["omniauth.params"]["site"].presence
  
  unless options.client_options.site
    OmniAuth::Form.build(title: (options.title.presence || "FreshBooks Authentication")) do |form|
      form.text_field "URL", "site"
    end.to_response
  else
    super
  end
rescue URI::InvalidURIError
  return fail!(:invalid_site)
rescue Net::HTTPRetriableError
  return fail!(:invalid_site)
end