enop 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e989593e40d999366ab21adfd8f54f05f9ab50b
4
- data.tar.gz: b33826e9c971b7c93bc05d4c0401f89413e4842f
3
+ metadata.gz: 1fa944930a75dae78c4a3c7555fdc0ddec16bc02
4
+ data.tar.gz: ba1657c161e1ef665034808cf59de98c9a40a6c2
5
5
  SHA512:
6
- metadata.gz: 8e15eda394a9a51d48dfead71776f3ed6a03d220bdd70295cdb187fc56f55a61c8933b5c9dd08dae5895c1017110039be35d548bfb3c02a2cede454a9456b738
7
- data.tar.gz: b6b17fe1ef6a4c92434db4cdaeb38d59b48838978d999cd081d00e39883f810186635ba8d0c2e3ad3aa265a281a09970a86bce637bd8cb35c739f9cf3ec94165
6
+ metadata.gz: 2ed7565163dfe70302e7ba820e317380f8c7787a3ff7f9f8ba75bfd3de1b8b538e3c43c4d3b6583f00adf40fe97d72f5e6d2d70593c391e97aea91b58bba8e69
7
+ data.tar.gz: c0d2b09c2d36844b9a428db743aac9640c7271cd357493bf0b8438c81e840ccb0bebabf1cf49380b563f82d59a3a296deb73510b7c6b26e1608fac4183ac0c95
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
data/exe/enop CHANGED
@@ -1,9 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'arxutils'
3
4
  require "enop"
4
5
 
5
- authToken = "S=s18:U=1f38cb:E=15110796cd9:C=149b8c83d38:P=1cd:A=en-devtoken:V=2:H=970049a2b990ad5e0f58252a626539b0"
6
+ dbconfig = Arxutils::Dbutil::DBCONFIG_MYSQL
7
+ dbconfig = Arxutils::Dbutil::DBCONFIG_SQLITE3
6
8
 
7
- enop = Enop::Enop.new(Arxutils::DB_DIR, Arxutils::MIGRATE_DIR , Arxutils::CONFIG_DIR , Arxutils::DBCONFIG , Arxutils::DATABASELOG , authToken)
9
+ token = ARGV[0]
10
+ hs = {
11
+ "db_dir" => Arxutils::Dbutil::DB_DIR,
12
+ "migrate_dir" => Arxutils::Dbutil::MIGRATE_DIR,
13
+ "config_dir" => Arxutils::Dbutil::CONFIG_DIR,
14
+ "dbconfig" => dbconfig,
15
+ "log_fname" => Arxutils::Dbutil::DATABASELOG,
16
+ }
17
+
18
+
19
+ enop = Enop::Enop.new(
20
+ token,
21
+ :db,
22
+ hs
23
+ )
8
24
  enop.connect
9
25
  enop.list_notebooks
data/exe/makemigrate CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require 'dbinit'
5
- require 'migrate'
4
+ require 'arxutils'
6
5
  require 'enop'
7
6
 
8
7
  data_ary = [
@@ -42,9 +41,14 @@ data_ary = [
42
41
  },
43
42
  ]
44
43
 
44
+ dbconfig = Arxutils::Dbutil::DBCONFIG_MYSQL
45
+ dbconfig = Arxutils::Dbutil::DBCONFIG_SQLITE3
46
+
45
47
  forced = true
46
- mig = Arxutils::Migrate.new(Arxutils::DB_DIR, Arxutils::MIGRATE_DIR , Arxutils::CONFIG_DIR , Arxutils::DBCONFIG, Arxutils::DATABASELOG , forced )
47
- data_ary.reduce(0) do |next_num , x|
48
- mig.make( next_num , x )
49
- end
50
- mig.migrate
48
+ Arxutils::Migrate.migrate(
49
+ data_ary,
50
+ 0,
51
+ dbconfig,
52
+ forced
53
+ )
54
+
data/lib/enop.rb CHANGED
@@ -1,144 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
-
2
+ require "arxutils"
3
3
  require "enop/version"
4
-
5
- require 'evernote-thrift'
6
- require 'csv'
7
- require 'pp'
8
-
9
- require 'forwardable'
10
- require 'dbutil_base'
11
- require 'dbutil_enop'
4
+ require "enop/enop"
5
+ require "enop/dbutil"
6
+ #require "enop/dbutil/dbmgr"
7
+ #require "enop/dbutil/enopmgr"
12
8
 
13
9
  module Enop
14
- class Enop
15
- extend Forwardable
16
-
17
- def_delegator( :@dbmgr , :add , :db_add)
18
-
19
- def initialize( db_dir , migrate_dir , config_dir, dbconfig , log_fname , authToken)
20
-
21
- @stack_hs = {}
22
- @nbinfos = {}
23
- @notebookinfo = Struct.new("NotebookInfo", :name, :stack, :defaultNotebook, :count , :tags )
24
-
25
- @authToken = authToken
26
-
27
- register_time = Arxutils::Dbutil::DbMgr.init( db_dir , migrate_dir , config_dir, dbconfig , log_fname )
28
-
29
- @dbmgr = Dbutil::DbMgr.new( register_time )
30
-
31
- evernoteHost = "www.evernote.com"
32
- userStoreUrl = "https://#{evernoteHost}/edam/user"
33
- userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
34
- userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
35
- @userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
36
-
37
- versionOK = @userStore.checkVersion("Evernote EDAMTest (Ruby)",
38
- Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
39
- Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
40
- puts "Is my Evernote API version up to date? #{versionOK}"
41
- puts
42
- exit(1) unless versionOK
43
-
44
- set_output_dest( get_output_filename_base )
45
- end
46
-
47
- def set_output_dest( fname )
48
- if fname
49
- fname_txt = fname + ".txt"
50
- fname_csv = fname + ".csv"
51
- @output = File.open( fname_txt , "w" , { :encoding => 'UTF-8' } )
52
- @output_csv = CSV.open( fname_csv , "w" , { :encoding => 'UTF-8' } )
53
- else
54
- @output = STDOUT
55
- end
56
- end
57
-
58
- def get_output_filename_base
59
- Time.now.strftime("ennblist-%Y-%m-%d-%H-%M-%S")
60
- end
61
-
62
- def putsx( str )
63
- @output.puts( str )
64
- end
65
-
66
- def connect
67
- # Get the URL used to interact with the contents of the user's account
68
- # When your application authenticates using OAuth, the NoteStore URL will
69
- # be returned along with the auth token in the final OAuth request.
70
- # In that case, you don't need to make this call.
71
- #noteStoreUrl = userStore.getNoteStoreUrl(authToken)
72
- noteStoreUrl = "https://www.evernote.com/shard/s18/notestore"
73
-
74
- noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
75
- noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
76
- @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
77
- end
78
-
79
- def list_notebooks
80
- # List all of the notebooks in the user's account
81
- filter = Evernote::EDAM::NoteStore::NoteFilter.new
82
-
83
- begin
84
- notebooks = @noteStore.listNotebooks(@authToken)
85
- rescue => ex
86
- puts "Can't call listNotebooks"
87
- exit
88
- end
89
-
90
- puts "Found #{notebooks.size} notebooks:"
91
- memo = notebooks.inject({:defaultNotebook => nil , :nbinfo => []}) do |memo , notebook|
92
- notebook_name = ( notebook.name == nil ? "" : notebook.name )
93
- stack_name = ( notebook.stack == nil ? "" : notebook.stack )
94
-
95
- filter.notebookGuid = notebook.guid
96
-
97
- ret = nil
98
- begin
99
- ret = @noteStore.findNoteCounts(@authToken , filter , false )
100
- rescue => ex
101
- puts "Can't call findNoteCounts with #{notebook_name}"
102
- end
103
-
104
- if ret
105
- if ret.notebookCounts
106
- notebookCounts = ret.notebookCounts[notebook.guid]
107
- else
108
- notebookCounts = 0
109
- end
110
- tagcount = 0
111
- if ret.tagCounts
112
- tagcount = ret.tagCounts.size
113
- end
114
- nbinfo = @notebookinfo.new( notebook_name , stack_name , notebook.defaultNotebook , notebookCounts , tagcount )
115
- # CSVファイルへ追加(自動的に出力)
116
- register_notebook( nbinfo.stack , nbinfo )
117
- # dbへの登録
118
- db_add( nbinfo.stack , nbinfo.name , nbinfo.count , nbinfo.tags.size )
119
-
120
- # p notebook
121
- memo[:defaultNotebook] = nbinfo if nbinfo.defaultNotebook
122
- memo[:nbinfo] << nbinfo
123
- end
124
-
125
- memo
126
- end
127
-
128
- @stack_hs.keys.sort.each do |k|
129
- # TXTファイルに出力
130
- putsx "#{k},#{@stack_hs[k]}"
131
- end
132
-
133
- pp memo[:defaultNotebook]
134
- end
135
-
136
- def register_notebook( stack , nbinfo )
137
- @stack_hs[stack] ||= []
138
- @stack_hs[stack] << nbinfo
139
- @nbinfos[nbinfo.name] = nbinfo
140
-
141
- @output_csv << [ stack , nbinfo.name , nbinfo.count ]
142
- end
143
- end
144
10
  end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'enop/dbutil/dbmgr'
4
+ require 'enop/dbutil/enopmgr'
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'enop/dbutil/enopmgr'
3
+ require 'forwardable'
4
+ require 'pp'
5
+
6
+ module Enop
7
+ module Dbutil
8
+ class DbMgr
9
+ extend Forwardable
10
+
11
+ def_delegator( :@ennblistmgr , :add, :add)
12
+
13
+ def initialize( register_time )
14
+ @ennblistmgr = EnopMgr.new( register_time )
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'active_record'
2
3
  require 'forwardable'
3
4
  require 'pp'
4
5
 
@@ -20,21 +21,9 @@ module Enop
20
21
  class Countdatetime < ActiveRecord::Base
21
22
  end
22
23
 
23
- class DbMgr
24
- extend Forwardable
25
-
26
- def_delegator( :@ennblistmgr , :add, :add)
27
-
28
- def initialize( register_time )
29
- @ennblistmgr = EnopMgr.new( register_time )
30
- end
31
-
32
- end
33
-
34
24
  class EnopMgr
35
-
36
25
  extend Forwardable
37
-
26
+
38
27
  def initialize(register_time)
39
28
  @register_time = register_time
40
29
  @ct = Countdatetime.create( countdatetime: @register_time )
@@ -79,7 +68,7 @@ module Enop
79
68
  end
80
69
  ennblist
81
70
  end
82
-
71
+
83
72
  def post_process( dir_id )
84
73
  h_ids = Currentennblist.pluck(:org_id)
85
74
  t_ids = @hs_by_id.keys
@@ -93,3 +82,5 @@ module Enop
93
82
  end
94
83
  end
95
84
  end
85
+
86
+
data/lib/enop/enop.rb ADDED
@@ -0,0 +1,140 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'evernote-thrift'
3
+ require 'csv'
4
+ require 'pp'
5
+
6
+ require 'forwardable'
7
+
8
+ module Enop
9
+ class Enop
10
+ extend Forwardable
11
+
12
+ def_delegator( :@dbmgr , :add , :db_add)
13
+
14
+ def initialize( authToken , kind, hs )
15
+
16
+ @stack_hs = {}
17
+ @nbinfos = {}
18
+ @notebookinfo = Struct.new("NotebookInfo", :name, :stack, :defaultNotebook, :count , :tags )
19
+
20
+ @authToken = authToken
21
+
22
+ @dbmgr = Arxutils::Store.init(kind , hs ){ | register_time |
23
+ Dbutil::DbMgr.new( register_time )
24
+ }
25
+
26
+ evernoteHost = "www.evernote.com"
27
+ userStoreUrl = "https://#{evernoteHost}/edam/user"
28
+ userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
29
+ userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
30
+ @userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
31
+
32
+ versionOK = @userStore.checkVersion("Evernote EDAMTest (Ruby)",
33
+ Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
34
+ Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
35
+ puts "Is my Evernote API version up to date? #{versionOK}"
36
+ puts
37
+ exit(1) unless versionOK
38
+
39
+ set_output_dest( get_output_filename_base )
40
+ end
41
+
42
+ def set_output_dest( fname )
43
+ if fname
44
+ fname_txt = fname + ".txt"
45
+ fname_csv = fname + ".csv"
46
+ @output = File.open( fname_txt , "w" , { :encoding => 'UTF-8' } )
47
+ @output_csv = CSV.open( fname_csv , "w" , { :encoding => 'UTF-8' } )
48
+ else
49
+ @output = STDOUT
50
+ end
51
+ end
52
+
53
+ def get_output_filename_base
54
+ Time.now.strftime("ennblist-%Y-%m-%d-%H-%M-%S")
55
+ end
56
+
57
+ def putsx( str )
58
+ @output.puts( str )
59
+ end
60
+
61
+ def connect
62
+ # Get the URL used to interact with the contents of the user's account
63
+ # When your application authenticates using OAuth, the NoteStore URL will
64
+ # be returned along with the auth token in the final OAuth request.
65
+ # In that case, you don't need to make this call.
66
+ #noteStoreUrl = userStore.getNoteStoreUrl(authToken)
67
+ noteStoreUrl = "https://www.evernote.com/shard/s18/notestore"
68
+
69
+ noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
70
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
71
+ @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
72
+ end
73
+
74
+ def list_notebooks
75
+ # List all of the notebooks in the user's account
76
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
77
+
78
+ begin
79
+ notebooks = @noteStore.listNotebooks(@authToken)
80
+ rescue => ex
81
+ puts "Can't call listNotebooks"
82
+ exit
83
+ end
84
+
85
+ puts "Found #{notebooks.size} notebooks:"
86
+ memo = notebooks.inject({:defaultNotebook => nil , :nbinfo => []}) do |memo , notebook|
87
+ notebook_name = ( notebook.name == nil ? "" : notebook.name )
88
+ stack_name = ( notebook.stack == nil ? "" : notebook.stack )
89
+
90
+ filter.notebookGuid = notebook.guid
91
+
92
+ ret = nil
93
+ begin
94
+ ret = @noteStore.findNoteCounts(@authToken , filter , false )
95
+ rescue => ex
96
+ puts "Can't call findNoteCounts with #{notebook_name}"
97
+ end
98
+
99
+ if ret
100
+ if ret.notebookCounts
101
+ notebookCounts = ret.notebookCounts[notebook.guid]
102
+ else
103
+ notebookCounts = 0
104
+ end
105
+ tagcount = 0
106
+ if ret.tagCounts
107
+ tagcount = ret.tagCounts.size
108
+ end
109
+ nbinfo = @notebookinfo.new( notebook_name , stack_name , notebook.defaultNotebook , notebookCounts , tagcount )
110
+ # CSVファイルへ追加(自動的に出力)
111
+ register_notebook( nbinfo.stack , nbinfo )
112
+ # dbへの登録
113
+ db_add( nbinfo.stack , nbinfo.name , nbinfo.count , nbinfo.tags.size )
114
+
115
+ # p notebook
116
+ memo[:defaultNotebook] = nbinfo if nbinfo.defaultNotebook
117
+ memo[:nbinfo] << nbinfo
118
+ end
119
+
120
+ memo
121
+ end
122
+
123
+ @stack_hs.keys.sort.each do |k|
124
+ # TXTファイルに出力
125
+ putsx "#{k},#{@stack_hs[k]}"
126
+ end
127
+
128
+ pp memo[:defaultNotebook]
129
+ end
130
+
131
+ def register_notebook( stack , nbinfo )
132
+ @stack_hs[stack] ||= []
133
+ @stack_hs[stack] << nbinfo
134
+ @nbinfos[nbinfo.name] = nbinfo
135
+
136
+ @output_csv << [ stack , nbinfo.name , nbinfo.count ]
137
+ end
138
+ end
139
+ end
140
+
data/lib/enop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Enop
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evernote_oauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: arxutils
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.10'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '10.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '10.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: evernote operation.
@@ -117,9 +117,9 @@ executables:
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
- - .gitignore
121
- - .rspec
122
- - .travis.yml
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
123
  - Gemfile
124
124
  - README.md
125
125
  - Rakefile
@@ -128,10 +128,11 @@ files:
128
128
  - enop.gemspec
129
129
  - exe/enop
130
130
  - exe/makemigrate
131
- - lib/dbutil_enop.rb
132
- - lib/en_oauth.rb
133
- - lib/ennb.rb
134
131
  - lib/enop.rb
132
+ - lib/enop/dbutil.rb
133
+ - lib/enop/dbutil/dbmgr.rb
134
+ - lib/enop/dbutil/enopmgr.rb
135
+ - lib/enop/enop.rb
135
136
  - lib/enop/version.rb
136
137
  - lib/evernote_config.rb
137
138
  homepage: ''
@@ -143,12 +144,12 @@ require_paths:
143
144
  - lib
144
145
  required_ruby_version: !ruby/object:Gem::Requirement
145
146
  requirements:
146
- - - '>='
147
+ - - ">="
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  requirements:
151
- - - '>='
152
+ - - ">="
152
153
  - !ruby/object:Gem::Version
153
154
  version: '0'
154
155
  requirements: []
@@ -158,3 +159,4 @@ signing_key:
158
159
  specification_version: 4
159
160
  summary: evernote operation.
160
161
  test_files: []
162
+ has_rdoc:
data/lib/en_oauth.rb DELETED
@@ -1,314 +0,0 @@
1
- ##
2
- # Copyright 2012 Evernote Corporation. All rights reserved.
3
- ##
4
-
5
- require 'sinatra'
6
- require 'sinatra/reloader'
7
- enable :sessions
8
-
9
- # Load our dependencies and configuration settings
10
- $LOAD_PATH.push(File.expand_path(File.dirname(__FILE__)))
11
-
12
- #set :port, 4569
13
- set :port, 4570
14
-
15
- require "evernote_config.rb"
16
-
17
- ##
18
- # Verify that you have obtained an Evernote API key
19
- ##
20
- before do
21
- if OAUTH_CONSUMER_KEY.empty? || OAUTH_CONSUMER_SECRET.empty?
22
- halt '<span style="color:red">Before using this sample code you must edit evernote_config.rb and replace OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET with the values that you received from Evernote. If you do not have an API key, you can request one from <a href="http://dev.evernote.com/documentation/cloud/">dev.evernote.com/documentation/cloud/</a>.</span>'
23
- end
24
- end
25
-
26
- helpers do
27
- def auth_token
28
- session[:access_token].token if session[:access_token]
29
- end
30
-
31
- def client
32
- @client ||= EvernoteOAuth::Client.new(token: auth_token, consumer_key:OAUTH_CONSUMER_KEY, consumer_secret:OAUTH_CONSUMER_SECRET, sandbox: SANDBOX)
33
- end
34
-
35
- def user_store
36
- @user_store ||= client.user_store
37
- end
38
-
39
- def note_store
40
- @note_store ||= client.note_store
41
- end
42
-
43
- def en_user
44
- user_store.getUser(auth_token)
45
- end
46
-
47
- def notebooks
48
- @notebooks ||= note_store.listNotebooks(auth_token)
49
- end
50
-
51
- def total_note_count
52
- filter = Evernote::EDAM::NoteStore::NoteFilter.new
53
- counts = note_store.findNoteCounts(auth_token, filter, false)
54
- notebooks.inject(0) do |total_count, notebook|
55
- total_count + (counts.notebookCounts[notebook.guid] || 0)
56
- end
57
- end
58
-
59
- def notebooks_hash
60
- @notebooks_hash ||= {}
61
- if @notebooks_hash.size != notebooks.size
62
- notebooks.each do |x|
63
- @notebooks_hash[x.name] = x
64
- end
65
- end
66
- @notebooks_hash
67
- end
68
-
69
- def notes(guid)
70
- filter = Evernote::EDAM::NoteStore::NoteFilter.new
71
- # filter.notebookGuid = @notebook.guid
72
- filter.notebookGuid = guid
73
- @found_n = note_store.findNotes(auth_token, filter, 0 , 100 )
74
- # @found_notes = @found_n.notes
75
- @found_n.notes
76
- end
77
- end
78
-
79
- ##
80
- # Index page
81
- ##
82
- get '/' do
83
- erb :index
84
- end
85
-
86
- ##
87
- # Reset the session
88
- ##
89
- get '/reset' do
90
- session.clear
91
- redirect '/'
92
- end
93
-
94
- ##
95
- # Obtain temporary credentials
96
- ##
97
- get '/requesttoken' do
98
- callback_url = request.url.chomp("requesttoken").concat("callback")
99
- begin
100
- session[:request_token] = client.request_token(:oauth_callback => callback_url)
101
- redirect '/authorize'
102
- rescue => e
103
- @last_error = "3 Error obtaining temporary credentials: #{e.message}"
104
- erb :error
105
- end
106
- end
107
-
108
- ##
109
- # Redirect the user to Evernote for authoriation
110
- ##
111
- get '/authorize' do
112
- if session[:request_token]
113
- redirect session[:request_token].authorize_url
114
- else
115
- # You shouldn't be invoking this if you don't have a request token
116
- @last_error = "Request token not set."
117
- erb :error
118
- end
119
- end
120
-
121
- ##
122
- # Receive callback from the Evernote authorization page
123
- ##
124
- get '/callback' do
125
- unless params['oauth_verifier'] || session['request_token']
126
- @last_error = "Content owner did not authorize the temporary credentials"
127
- halt erb :error
128
- end
129
- session[:oauth_verifier] = params['oauth_verifier']
130
- begin
131
- session[:access_token] = session[:request_token].get_access_token(:oauth_verifier => session[:oauth_verifier])
132
- redirect '/list'
133
- rescue => e
134
- @last_error = '2 Error extracting access token'
135
- erb :error
136
- end
137
- end
138
-
139
-
140
- ##
141
- # Access the user's Evernote account and display account data
142
- ##
143
- get '/list' do
144
- begin
145
- # Get notebooks
146
- session[:notebooks] = notebooks.collect{ |notebook|
147
- [ notebook.name , notebook.guid ]
148
- }
149
- # session[:notebooks] = notebooks.map(&:name)
150
- # Get username
151
- session[:username] = en_user.username
152
- # Get total note count
153
- session[:total_notes] = total_note_count
154
- erb :index
155
- rescue => e
156
- # @last_error = "Error listing notebooks: #{e.message}"
157
- @last_error = "1 Error listing notebooks: #{e}"
158
- erb :error
159
- end
160
- end
161
-
162
- ##
163
- #
164
- ##
165
- get '/notebook/:name/:guid' do
166
- begin
167
- session[:notebook_name] = params[:name]
168
- session[:notebook_guid] = params[:guid]
169
-
170
- # @notebook = notebooks_hash[ params[:name] ]
171
- @found_notes = notes( params[:guid] )
172
-
173
- erb :notes
174
- rescue => e
175
- @last_error = "0 Error listing notebook: #{e.message}"
176
- erb :error
177
- end
178
- end
179
-
180
- get '/create_note/:name/:guid' do
181
- begin
182
- ENML_HEADER = <<HEADER
183
- <?xml version="1.0" encoding="UTF-8"?>
184
- <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
185
- HEADER
186
-
187
- note_content = <<CONTENT
188
- #{ENML_HEADER}
189
- <en-note>Hello, my Evernote (from Ruby)!</en-note>
190
- CONTENT
191
-
192
- note = Evernote::EDAM::Type::Note.new
193
- note.title = "Note Title"
194
- note.notebookGuid = params[:guid]
195
- note.content = note_content
196
- note_store.createNote( auth_token , note)
197
- @found_notes = notes(session[:notebook_guid])
198
-
199
- erb :notes
200
- rescue => e
201
- @last_error = "0 Error listing notebook: #{e.message}"
202
- erb :error
203
- end
204
- end
205
-
206
-
207
- __END__
208
-
209
- @@ index
210
- <html>
211
- <head>
212
- <title>Evernote Ruby Example App</title>
213
- </head>
214
- <body>
215
- <a href="/requesttoken">Click here</a> to authenticate this application using OAuth.
216
- <% if session[:notebooks] %>
217
- <hr />
218
- <h3>The current user is <%= session[:username] %> and there are <%= session[:total_notes] %> notes in their account</h3>
219
- <br />
220
- <h3>Here are the notebooks in this account:</h3>
221
- <ul>
222
- <% session[:notebooks].each do |notebook| %>
223
- <% p session[:notebooks] %>
224
- <li><a href="/notebook/<%= notebook[0] %>/<%= notebook[1] %>"><%= notebook[0] %></a></li>
225
- <% end %>
226
- </ul>
227
- <% end %>
228
- </body>
229
- </html>
230
-
231
- @@ error
232
- <html>
233
- <head>
234
- <title>Evernote Ruby Example App &mdash; Error</title>
235
- </head>
236
- <body>
237
- <p>An error occurred: <%= @last_error %></p>
238
- <p>Please <a href="/reset">start over</a>.</p>
239
- </body>
240
- </html>
241
-
242
- @@ notebook
243
- <html>
244
- <head>
245
- </head>
246
- <body>
247
- <table>
248
- <% @found_notes.collect do |x| %>
249
- <tr>
250
- <td>
251
- <%= x.guid %>
252
- </td>
253
- <td>
254
- <%= x.title %>
255
- </td>
256
- </tr>
257
- <% end %>
258
- </table>
259
- <form action="/create_note" method="get">
260
- <input type="text" name="val" value="1">
261
- <input type="submit" value="Create Note">
262
- </form>
263
- </body>
264
- </html>
265
-
266
- @@ notes
267
- <html>
268
- <head>
269
- </head>
270
- <body>
271
- <table>
272
- <% @found_notes.collect do |x| %>
273
- <tr>
274
- <td>
275
- <%= x.guid %>
276
- </td>
277
- <td>
278
- <%= x.title %>
279
- </td>
280
- </tr>
281
- <% end %>
282
- </table>
283
- <form action="/create_note/<%= session[:notebook_name] %>/<%= session[:notebook_guid] %>" method="get">
284
- <input type="text" name="val" value="1">
285
- <input type="submit" value="Create Note">
286
- </form>
287
- </body>
288
- </html>
289
-
290
- @@ notebook1
291
- <html>
292
- <head>
293
- </head>
294
- <body>
295
- Notebook<p>
296
- <%= p @notebook.class %><p>
297
- <%= p @found_n.class %><p>
298
- <%= p @found_notes.class %><p>
299
- <ul>
300
- <% p @found_notes; @found_notes.each do |note| %>
301
- <li><a href="/note/<%= note.name %>/<%= note.guid %>"><%= note.name %></li>
302
- <% end %>
303
- </ul>
304
- </body>
305
- </html>
306
-
307
- @@ note
308
- <html>
309
- <head>
310
- </head>
311
- <body>
312
-
313
- </body>
314
- </html>
data/lib/ennb.rb DELETED
@@ -1,149 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'evernote-thrift'
4
- require 'csv'
5
- require 'pp'
6
-
7
- require 'forwardable'
8
- require 'dbutil_base'
9
- require 'dbutil_ennblist'
10
-
11
- class Ennb
12
- extend Forwardable
13
-
14
- def_delegator( :@dbmgr , :add , :db_add)
15
-
16
- def initialize
17
- @sqlite3yaml = 'config/sqlite3.yaml'
18
- @databaselog = 'db/database.log'
19
-
20
- @stack_hs = {}
21
- @nbinfos = {}
22
- @notebookinfo = Struct.new("NotebookInfo", :name, :stack, :defaultNotebook, :count , :tags )
23
-
24
- @authToken = "S=s18:U=1f38cb:E=15110796cd9:C=149b8c83d38:P=1cd:A=en-devtoken:V=2:H=970049a2b990ad5e0f58252a626539b0"
25
-
26
- evernoteHost = "www.evernote.com"
27
- userStoreUrl = "https://#{evernoteHost}/edam/user"
28
- userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
29
- userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
30
- @userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
31
-
32
- versionOK = @userStore.checkVersion("Evernote EDAMTest (Ruby)",
33
- Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
34
- Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
35
- puts "Is my Evernote API version up to date? #{versionOK}"
36
- puts
37
- exit(1) unless versionOK
38
-
39
- set_output_dest( get_output_filename_base )
40
-
41
- dbx
42
- end
43
-
44
- def dbx
45
- @dbmgr = Dbutil::DbMgr.init( @sqlite3yaml , @databaselog )
46
- end
47
-
48
- def set_output_dest( fname )
49
- if fname
50
- fname_txt = fname + ".txt"
51
- fname_csv = fname + ".csv"
52
- @output = File.open( fname_txt , "w" , { :encoding => 'UTF-8' } )
53
- @output_csv = CSV.open( fname_csv , "w" , { :encoding => 'UTF-8' } )
54
- else
55
- @output = STDOUT
56
- end
57
- end
58
-
59
- def get_output_filename_base
60
- Time.now.strftime("ennblist-%Y-%m-%d-%H-%M-%S")
61
- end
62
-
63
- def putsx( str )
64
- @output.puts( str )
65
- end
66
-
67
- def connect
68
- # Get the URL used to interact with the contents of the user's account
69
- # When your application authenticates using OAuth, the NoteStore URL will
70
- # be returned along with the auth token in the final OAuth request.
71
- # In that case, you don't need to make this call.
72
- #noteStoreUrl = userStore.getNoteStoreUrl(authToken)
73
- noteStoreUrl = "https://www.evernote.com/shard/s18/notestore"
74
-
75
- noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
76
- noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
77
- @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
78
- end
79
-
80
- def list_notebooks
81
- # List all of the notebooks in the user's account
82
- filter = Evernote::EDAM::NoteStore::NoteFilter.new
83
-
84
- begin
85
- notebooks = @noteStore.listNotebooks(@authToken)
86
- rescue => ex
87
- puts "Can't call listNotebooks"
88
- exit
89
- end
90
-
91
- puts "Found #{notebooks.size} notebooks:"
92
- memo = notebooks.inject({:defaultNotebook => nil , :nbinfo => []}) do |memo , notebook|
93
- notebook_name = ( notebook.name == nil ? "" : notebook.name )
94
- stack_name = ( notebook.stack == nil ? "" : notebook.stack )
95
-
96
- filter.notebookGuid = notebook.guid
97
-
98
- ret = nil
99
- begin
100
- ret = @noteStore.findNoteCounts(@authToken , filter , false )
101
- rescue => ex
102
- puts "Can't call findNoteCounts with #{notebook_name}"
103
- end
104
-
105
- if ret
106
- if ret.notebookCounts
107
- notebookCounts = ret.notebookCounts[notebook.guid]
108
- else
109
- notebookCounts = 0
110
- end
111
- tagcount = 0
112
- if ret.tagCounts
113
- tagcount = ret.tagCounts.size
114
- end
115
- nbinfo = @notebookinfo.new( notebook_name , stack_name , notebook.defaultNotebook , notebookCounts , tagcount )
116
- # CSVファイルへ追加(自動的に出力)
117
- register_notebook( nbinfo.stack , nbinfo )
118
- # dbへの登録
119
- db_add( nbinfo.stack , nbinfo.name , nbinfo.count , nbinfo.tags.size )
120
-
121
- # p notebook
122
- memo[:defaultNotebook] = nbinfo if nbinfo.defaultNotebook
123
- memo[:nbinfo] << nbinfo
124
- end
125
-
126
- memo
127
- end
128
-
129
- @stack_hs.keys.sort.each do |k|
130
- # TXTファイルに出力
131
- putsx "#{k},#{@stack_hs[k]}"
132
- end
133
-
134
- pp memo[:defaultNotebook]
135
- end
136
-
137
- def register_notebook( stack , nbinfo )
138
- @stack_hs[stack] ||= []
139
- @stack_hs[stack] << nbinfo
140
- @nbinfos[nbinfo.name] = nbinfo
141
-
142
- @output_csv << [ stack , nbinfo.name , nbinfo.count ]
143
- end
144
- end
145
-
146
- ennb = Ennb.new
147
- ennb.connect
148
- ennb.list_notebooks
149
-