Class: Oauth::Provider

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/oauth/provider.rb

Direct Known Subclasses

Qq, Weibo, Weixin

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.request(url, request_params, method = 'get', format = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oauth/provider.rb', line 36

def request(url, request_params, method = 'get', format = nil)
  uri = URI(url)
  begin
    if method == 'get'
      uri.query = (uri.query.nil? ? '' : (uri.query + "&")) + URI.encode_www_form(request_params)
      response = Net::HTTP.get_response(uri)
    else
      response = Net::HTTP.post_form(uri, request_params)
    end
  rescue Exception => e
    puts e.message
    return nil
  end
  if response.kind_of? Net::HTTPSuccess
    format == 'json' ? JSON.parse(response.body) : response.body
  else
    nil
  end
end

.typeObject



28
29
30
# File 'lib/oauth/provider.rb', line 28

def type
  self.to_s.split("::").last.downcase
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/oauth/provider.rb', line 23

def expired?
  created_at + expires_in < Time.now + 10
end

#fetch_info!Object



17
18
19
20
21
# File 'lib/oauth/provider.rb', line 17

def fetch_info!
  return nil if expired?
  info = fetch_info
  info && self.info = Oauth::Info.create(data: info)
end