Class: Oauth2Provider::OauthAccess

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/oauth2_provider/oauth_access.rb

Instance Method Summary collapse

Instance Method Details

#accessed!Object

Increment the daily accesses



39
40
41
# File 'app/models/oauth2_provider/oauth_access.rb', line 39

def accessed!
  daily_requests.increment!
end

#block!Object

Block the resource owner delegation to a specific client



20
21
22
23
24
25
# File 'app/models/oauth2_provider/oauth_access.rb', line 20

def block!
  self.blocked = Time.now
  self.save
  OauthToken.block_access!(client_uri, resource_owner_uri)
  OauthAuthorization.block_access!(client_uri, resource_owner_uri)
end

#blocked?Boolean

Check if the status is or is not blocked

Returns:

  • (Boolean)


34
35
36
# File 'app/models/oauth2_provider/oauth_access.rb', line 34

def blocked?
  !self.blocked.nil?
end

#chart_daysObject

Give back the last days in a friendly format.It is used to generate graph for statistics



53
54
55
56
57
# File 'app/models/oauth2_provider/oauth_access.rb', line 53

def chart_days
  daily_requests = self.oauth_daily_requests.limit(10)
  days = daily_requests.map(&:created_at)
  days.map { |d| d.strftime("%b %e") }
end

#chart_timesObject

Give the number of accesses for the last days. It is used to generate graph for statistics



61
62
63
64
# File 'app/models/oauth2_provider/oauth_access.rb', line 61

def chart_times
  access_times = self.oauth_daily_requests.limit(10)
  access_times.map(&:times)
end

#daily_requests(time = Time.now) ⇒ Object

A daily requests record (there is one per day)

@params [String] time we want to find the requests record
@return [OauthDailyRequest] requests record


47
48
49
# File 'app/models/oauth2_provider/oauth_access.rb', line 47

def daily_requests(time = Time.now)
  find_or_create_daily_requests(time)
end

#unblock!Object

Unblock the resource owner delegation to a specific client



28
29
30
31
# File 'app/models/oauth2_provider/oauth_access.rb', line 28

def unblock!
  self.blocked = nil
  self.save
end