-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.rb
71 lines (57 loc) · 1.31 KB
/
db.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
require "mongo_mapper"
class EntryPost
include MongoMapper::Document
key :guid, String, :required => true
key :url, String
timestamps! # created_at, updated_at を定義する
connection Mongo::Connection.new('localhost')
set_database_name 'hatena'
end
class AccessToken
include MongoMapper::Document
key :access_token, String, :required => true
timestamps!
connection Mongo::Connection.new('localhost')
set_database_name 'evernote'
end
class Token
def access_token?
time = Time.now.to_i
token = AccessToken.first
if token == nil || time - token.updated_at.to_i > 24*60*60
return true
else
return nil
end
end
def get_token
AccessToken.first[:access_token]
end
def update_token(token)
puts "update_token #{token}"
ac = AccessToken.first
ac = AccessToken.new if ac == nil
ac[:access_token] = token
ac.save
end
end
class Entries
def exist?(guid)
#guid is note.guid given by evernote
entry = EntryPost.all(:guid => guid)
#puts guid
#p entry
return nil if entry == []
return true
end
def add(content)
#content ={
# :guid => note.guid,
# :url
# }
entry = EntryPost.new(content)
puts entry[:content]
entry.save
end
end