├── .gitignore
├── .idea
├── .name
├── .rakeTasks
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── cssxfire.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── scopes
│ └── scope_settings.xml
└── vcs.xml
├── .ruby-version
├── LICENSE
├── README.md
├── Rakefile
├── alfred-transmit-workflow.iml
├── alfred-transmit.alfredworkflow
├── config.yml
├── screenshots
└── search.png
└── workflow
├── Gemfile
├── Gemfile.lock
├── feedback.rb
├── icon.png
├── info.plist
├── rebuild.rb
└── transmit.rb
/.gitignore:
--------------------------------------------------------------------------------
1 | workflow/.bundle
2 | workflow/bundle
3 | .idea/workspace.xml
4 | .idea/tasks.xml
5 |
6 | # projectwise
7 | workflow/favorites.json
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | alfred-transmit-workflow
--------------------------------------------------------------------------------
/.idea/.rakeTasks:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/cssxfire.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.0.0-p353
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Ramiro Araujo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Transmit 4 Workflow for Alfred app
2 |
3 | Workflow for searching and opening Favorites in Transmit 4 App. It's really _fast_, because it reads the SQLite Database or XML datasource in latests releases of Transmit 4.
4 |
5 | There are already at least 2 Transmit workflows, but one is incompatible with latests Transmit 4 and the other, although very good, uses AppleScript to do the searching, and thus you need to wait for Transmit to open to get feedback. This is particulary slow on non SSD machines.
6 |
7 | ## Usage
8 | Type the keyword (default _ftp_) and start typing the name of the favorite to search; dead simple.
9 |
10 | 
11 |
12 | ## Installation
13 | For OS X 10.9 Mavericks, Download the [alfred-transmit.alfredworkflow](https://github.com/ramiroaraujo/alfred-transmit-workflow/raw/master/alfred-transmit.alfredworkflow) and import to Alfred 2.
14 |
15 | For Previous OS X Versions, Download the [alfred-transmit.alfredworkflow](https://github.com/ramiroaraujo/alfred-transmit-workflow/raw/pre-mavericks/alfred-transmit.alfredworkflow) and import to Alfred 2.
16 |
17 | ## Changelog
18 | * _2013-12-16_ - Released
19 | * _2014-01-02_ - Added support for previous OS versions, using System Ruby 1.8, tested up to Lion
20 | * _2014-01-03_ - Search in both Favorite name and host
21 | * _2014-01-20_ - Added support for Favorites.xml
22 | * _2014-01-30_ - Rebuilt XML search to use different Ruby xml parser
23 | * _2014-03-14_ - Corrected bug that prevented listing of anonymous ftp accounts
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
2 |
3 | require 'yaml'
4 | require 'plist'
5 |
6 | config_file = 'config.yml'
7 |
8 | workflow_home = File.expand_path("~/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows")
9 |
10 | $config = YAML.load_file(config_file)
11 | $config["bundleid"] = "#{$config["domain"]}.#{$config["id"]}"
12 | $config["plist"] = File.join($config["path"], "info.plist")
13 | $config["workflow_dbx"] = File.join(File.expand_path($config["dropbox"]), "/Alfred.alfredpreferences/workflows")
14 |
15 | # import sub-rakefiles
16 | FileList['*/Rakefile'].each { |file|
17 | import file
18 | }
19 |
20 | desc "Update config"
21 | task :config do
22 | modified = false
23 |
24 | info = Plist::parse_xml($config["plist"])
25 |
26 | if info['bundleid'] != $config["bundleid"]
27 | info['bundleid'] = $config["bundleid"]
28 | modified = true
29 | end
30 | if info['createdby'] != $config["created_by"]
31 | info['createdby'] = $config["created_by"]
32 | modified = true
33 | end
34 | if info['description'] != $config["description"]
35 | info['description'] = $config["description"]
36 | modified = true
37 | end
38 | if info['name'] != $config["name"]
39 | info['name'] = $config["name"]
40 | modified = true
41 | end
42 | if info['webaddress'] != $config["website"]
43 | info['webaddress'] = $config["website"]
44 | modified = true
45 | end
46 | if info['readme'] != $config["readme"]
47 | info['readme'] = $config["readme"]
48 | modified = true
49 | end
50 |
51 | if modified == true
52 | File.open($config["plist"], "wb") { |file| file.write(info.to_plist) }
53 | end
54 | end
55 |
56 | task :chdir => [:config] do
57 | chdir $config['path']
58 | end
59 |
60 | desc "Install Gems"
61 | task "bundle:install" => [:chdir] do
62 | sh %Q{bundle install --standalone --clean} do |ok, res|
63 | if !ok
64 | puts "fail to install gems (status = #{res.exitstatus})"
65 | end
66 | end
67 | end
68 |
69 | desc "Update Gems"
70 | task "bundle:update" => [:chdir] do
71 | sh %Q{bundle update && bundle install --standalone --clean} do |ok, res|
72 | if !ok
73 | puts "fail to update gems (status = #{res.exitstatus})"
74 | end
75 | end
76 | end
77 |
78 | desc "Install to Alfred"
79 | task :install => [:config] do
80 | ln_sf File.expand_path($config["path"]), File.join(workflow_home, $config["bundleid"])
81 | end
82 |
83 | desc "Unlink from Alfred"
84 | task :uninstall => [:config] do
85 | rm File.join(workflow_home, $config["bundleid"])
86 | end
87 |
88 | desc "Install to Dropbox"
89 | task :dbxinstall => [:config] do
90 | ln_sf File.expand_path($config["path"]), File.join($config["workflow_dbx"], $config["bundleid"])
91 | end
92 |
93 | desc "Unlink from Dropbox"
94 | task :dbxuninstall => [:config] do
95 | rm File.join($config["workflow_dbx"], $config["bundleid"])
96 | end
97 |
98 | desc "Clean up all the extras"
99 | task :clean => [:config] do
100 | end
101 |
102 | desc "Remove any generated file"
103 | task :clobber => [:clean] do
104 | rmtree File.join($config["path"], ".bundle")
105 | rmtree File.join($config["path"], "bundle")
106 | end
107 |
108 | desc "Create packed Workflow"
109 | task :export => [:config] do
110 | ruby_version = RbConfig::CONFIG["ruby_version"]
111 |
112 | filename = "#{$config['id'].chomp '-workflow'}.alfredworkflow"
113 | output = 'output'
114 |
115 | FileUtils.rm filename if File.exists? filename
116 | FileUtils.rmtree output if File.exists? output
117 |
118 | FileUtils.cp_r $config['path'], output
119 | chdir output
120 |
121 | # clean up workflow files for export
122 | Dir.foreach('.') do |file|
123 | FileUtils.rmtree file if %w(Gemfile Gemfile.lock .bundle favorites.json).include? file
124 | end
125 | Dir.chdir('bundle/ruby') do
126 | Dir.foreach('.') do |dir|
127 | next if dir == '.' || dir == '..'
128 | FileUtils.rmtree dir if dir != ruby_version
129 | end
130 | end
131 | Dir.chdir("bundle/ruby/#{ruby_version}") do
132 | Dir.foreach('.') do |dir|
133 | FileUtils.rmtree dir if %w(build_info cache doc specifications).include? dir
134 | end
135 | Dir.chdir('gems') do
136 | Dir.foreach('.') do |dir|
137 | next if dir == '.' || dir == '..'
138 | Dir.chdir(dir) do
139 | Dir.foreach('.') do |subdir|
140 | next if subdir == '.' || subdir == '..'
141 | FileUtils.rmtree subdir if !(%w(. .. lib).include? subdir)
142 | end
143 | end
144 | end
145 | end
146 | end
147 |
148 | `/usr/bin/zip -r ../#{filename} *`
149 |
150 | chdir('..')
151 | FileUtils.rmtree output
152 |
153 | puts 'Workflow exported to project directory'
154 | end
--------------------------------------------------------------------------------
/alfred-transmit-workflow.iml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/alfred-transmit.alfredworkflow:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ramiroaraujo/alfred-transmit-workflow/9f2defa2b817547c99bba843a68a9c43e4d73ffc/alfred-transmit.alfredworkflow
--------------------------------------------------------------------------------
/config.yml:
--------------------------------------------------------------------------------
1 | ## workflow build config
2 |
3 | # id and name for the workflow (bundle id = domain.id)
4 | id: alfred-transmit-workflow
5 |
6 | # base domain
7 | domain: com.tumblr.ramiroaraujo
8 |
9 | name: Transmit
10 | description: Connect to Transmit Favorites
11 | created_by: Ramiro Araujo
12 | website: https://github.com/ramiroaraujo/alfred-transmit-workflow
13 | readme: readme
14 |
15 | ## development config
16 |
17 | # path is the relative path to the workflow in the project root
18 | path: workflow
19 |
20 | # If you are using Alfred's advanced Dropbox sync, indicate the path shown in
21 | # Alfred Preferences > Advanced > Syncing:
22 | dropbox: ~/Dropbox
--------------------------------------------------------------------------------
/screenshots/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ramiroaraujo/alfred-transmit-workflow/9f2defa2b817547c99bba843a68a9c43e4d73ffc/screenshots/search.png
--------------------------------------------------------------------------------
/workflow/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'plist'
4 | gem 'alfred-workflow'
5 | gem 'sqlite3'
6 | gem 'xml-simple'
7 | gem 'json'
--------------------------------------------------------------------------------
/workflow/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | alfred-workflow (2.0.5)
5 | fuzzy_match (>= 2.0.4)
6 | gyoku (>= 1.1.0)
7 | moneta (>= 0.7.19)
8 | nori (>= 2.3.0)
9 | plist (>= 3.1.0)
10 | terminal-notifier (>= 1.5.0)
11 | builder (3.2.2)
12 | fuzzy_match (2.0.4)
13 | gyoku (1.1.1)
14 | builder (>= 2.1.2)
15 | json (1.8.1)
16 | moneta (0.7.20)
17 | nori (2.3.0)
18 | plist (3.1.0)
19 | sqlite3 (1.3.8)
20 | terminal-notifier (1.5.1)
21 | xml-simple (1.1.3)
22 |
23 | PLATFORMS
24 | ruby
25 |
26 | DEPENDENCIES
27 | alfred-workflow
28 | json
29 | plist
30 | sqlite3
31 | xml-simple
32 |
--------------------------------------------------------------------------------
/workflow/feedback.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # encoding: utf-8
3 |
4 | require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
5 | require_relative 'bundle/bundler/setup'
6 | require 'alfred'
7 | require_relative 'transmit'
8 |
9 | query = ARGV[0]
10 | query = query.downcase if query
11 |
12 |
13 | Alfred.with_friendly_error do |alfred|
14 |
15 | fb = alfred.feedback
16 | transmit = Transmit.new
17 |
18 | db_type = nil
19 |
20 | # check if xml favorites exist first
21 | if !transmit.check_database
22 | fb.add_item({
23 | :uid => '',
24 | :title => 'No Transmit Database found!',
25 | :arg => '',
26 | :valid => 'no',
27 | :icon => {
28 | :type => "default",
29 | :name => "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
30 | }
31 | })
32 |
33 | puts fb.to_xml()
34 | exit
35 | end
36 |
37 | transmit.search(query).each do |fav|
38 | fb.add_item({
39 | :uid => fav['uuid'],
40 | :title => fav['name'],
41 | :subtitle => "#{fav['username']}@#{fav['server']}",
42 | :arg => fav['uuid'],
43 | :valid => 'yes',
44 | })
45 | end
46 |
47 |
48 | # sends "no result" message
49 | if fb.to_xml().to_s == ''
50 | fb.add_item({
51 | :uid => '',
52 | :title => 'No results for your search',
53 | :subtitle => 'Try rebuilding the Favorites cache (ftprebuild) if needed',
54 | :arg => '',
55 | :valid => 'no',
56 | })
57 |
58 | end
59 |
60 | puts fb.to_xml()
61 | end
62 |
--------------------------------------------------------------------------------
/workflow/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ramiroaraujo/alfred-transmit-workflow/9f2defa2b817547c99bba843a68a9c43e4d73ffc/workflow/icon.png
--------------------------------------------------------------------------------
/workflow/info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | bundleid
6 | com.tumblr.ramiroaraujo.alfred-transmit-workflow
7 | connections
8 |
9 | 1772844A-8F30-4D06-9A88-7665028E51B0
10 |
11 |
12 | destinationuid
13 | 185E3A4B-9F86-42F2-B4A5-74E6B986C28D
14 | modifiers
15 | 0
16 | modifiersubtext
17 |
18 |
19 |
20 | 185E3A4B-9F86-42F2-B4A5-74E6B986C28D
21 |
22 |
23 | destinationuid
24 | 44F15B00-84CC-4B1B-9B79-1BB5091AEDB5
25 | modifiers
26 | 0
27 | modifiersubtext
28 |
29 |
30 |
31 | 21557827-8003-42B7-A042-16D4C9278FEC
32 |
33 |
34 | destinationuid
35 | 75EBE37F-17A0-4A01-9C1C-829760FD7DEB
36 | modifiers
37 | 0
38 | modifiersubtext
39 |
40 |
41 |
42 | destinationuid
43 | 8CBBCE70-6523-462F-BFF5-A629A7B1081D
44 | modifiers
45 | 0
46 | modifiersubtext
47 |
48 |
49 |
50 |
51 | createdby
52 | Ramiro Araujo
53 | description
54 | Connect to Transmit Favorites
55 | disabled
56 |
57 | name
58 | Transmit
59 | objects
60 |
61 |
62 | config
63 |
64 | lastpathcomponent
65 |
66 | onlyshowifquerypopulated
67 |
68 | output
69 | 0
70 | removeextension
71 |
72 | sticky
73 |
74 | title
75 | Connecting to Favorite
76 |
77 | type
78 | alfred.workflow.output.notification
79 | uid
80 | 75EBE37F-17A0-4A01-9C1C-829760FD7DEB
81 | version
82 | 0
83 |
84 |
85 | config
86 |
87 | argumenttype
88 | 1
89 | escaping
90 | 62
91 | keyword
92 | ftp
93 | runningsubtext
94 | working...
95 | script
96 | /usr/bin/ruby ./feedback.rb {query}
97 | subtext
98 | Search for a Favorite
99 | title
100 | Connect to Transmit Favorites
101 | type
102 | 0
103 | withspace
104 |
105 |
106 | type
107 | alfred.workflow.input.scriptfilter
108 | uid
109 | 21557827-8003-42B7-A042-16D4C9278FEC
110 | version
111 | 0
112 |
113 |
114 | config
115 |
116 | applescript
117 | on alfred_script(query)
118 | tell application "Transmit"
119 | activate
120 | set fav to item 1 of (favorites whose identifier is query)
121 | if document 1 exists then
122 | if remote browser of current tab of document 1 exists then
123 | set current tab of document 1 to (make new tab at end of document 1)
124 | tell current tab of document 1
125 | connect to fav
126 | end tell
127 | else
128 | tell current tab of document 1
129 | connect to fav
130 | end tell
131 | end if
132 | else
133 | tell current tab of (make new document at end)
134 | connect to fav
135 | end tell
136 | end if
137 | activate
138 | end tell
139 | end alfred_script
140 | cachescript
141 |
142 |
143 | type
144 | alfred.workflow.action.applescript
145 | uid
146 | 8CBBCE70-6523-462F-BFF5-A629A7B1081D
147 | version
148 | 0
149 |
150 |
151 | config
152 |
153 | escaping
154 | 0
155 | script
156 | /usr/bin/ruby ./rebuild.rb
157 | type
158 | 0
159 |
160 | type
161 | alfred.workflow.action.script
162 | uid
163 | 185E3A4B-9F86-42F2-B4A5-74E6B986C28D
164 | version
165 | 0
166 |
167 |
168 | config
169 |
170 | argumenttype
171 | 2
172 | keyword
173 | ftprebuild
174 | subtext
175 | Cache is rebuilt once per day, rebuild it manually if necesary
176 | text
177 | Rebuild Transmit Favorites cache
178 | withspace
179 |
180 |
181 | type
182 | alfred.workflow.input.keyword
183 | uid
184 | 1772844A-8F30-4D06-9A88-7665028E51B0
185 | version
186 | 0
187 |
188 |
189 | config
190 |
191 | lastpathcomponent
192 |
193 | onlyshowifquerypopulated
194 |
195 | output
196 | 0
197 | removeextension
198 |
199 | sticky
200 |
201 | title
202 | Favorites cache Rebuilt
203 |
204 | type
205 | alfred.workflow.output.notification
206 | uid
207 | 44F15B00-84CC-4B1B-9B79-1BB5091AEDB5
208 | version
209 | 0
210 |
211 |
212 | readme
213 | readme
214 | uidata
215 |
216 | 1772844A-8F30-4D06-9A88-7665028E51B0
217 |
218 | ypos
219 | 200
220 |
221 | 185E3A4B-9F86-42F2-B4A5-74E6B986C28D
222 |
223 | ypos
224 | 200
225 |
226 | 21557827-8003-42B7-A042-16D4C9278FEC
227 |
228 | ypos
229 | 10
230 |
231 | 44F15B00-84CC-4B1B-9B79-1BB5091AEDB5
232 |
233 | ypos
234 | 200
235 |
236 | 75EBE37F-17A0-4A01-9C1C-829760FD7DEB
237 |
238 | ypos
239 | 10
240 |
241 | 8CBBCE70-6523-462F-BFF5-A629A7B1081D
242 |
243 | ypos
244 | 80
245 |
246 |
247 | webaddress
248 | https://github.com/ramiroaraujo/alfred-transmit-workflow
249 |
250 |
251 |
--------------------------------------------------------------------------------
/workflow/rebuild.rb:
--------------------------------------------------------------------------------
1 | require_relative 'transmit'
2 |
3 | transmit = Transmit.new
4 | transmit.rebuild_cache
5 | puts 'Favorites cache rebuilt'
--------------------------------------------------------------------------------
/workflow/transmit.rb:
--------------------------------------------------------------------------------
1 | require_relative 'bundle/bundler/setup'
2 | require 'xmlsimple'
3 | require 'sqlite3'
4 | require 'json'
5 |
6 | class Transmit
7 |
8 | def initialize
9 | @favorites_folder = '~/Library/Application Support/Transmit/Favorites/'
10 | @favorites_sqlite = 'Favorites.sqlite'
11 | @favorites_xml = 'Favorites.xml'
12 |
13 | @type = nil
14 | end
15 |
16 | def check_database
17 | if File.exists? File.expand_path @favorites_folder + @favorites_xml
18 | @type = 'xml'
19 | return true
20 | elsif File.exists? File.expand_path @favorites_folder + @favorites_sqlite
21 | @type = 'sqlite'
22 | return true
23 | else
24 | return false
25 | end
26 | end
27 |
28 | def search query
29 | cached = File.exists? 'favorites.json'
30 | if cached
31 | favorites = JSON.load IO.read 'favorites.json'
32 | time = favorites['time']
33 | totaltime = time + 10
34 | cached = false if (favorites['time'] + 86400) < Time.now.to_i
35 | end
36 | if !cached
37 | favorites = @type == 'xml' ? cache_xml : cache_sqlite
38 | end
39 | result = favorites['list'].select do |fav|
40 | fav['name'].downcase =~ /#{query}/ || fav['server'].downcase =~ /#{query}/
41 | end
42 | result
43 | end
44 |
45 | def rebuild_cache
46 | return if !check_database
47 | if @type == 'xml'
48 | cache_xml
49 | elsif @type == 'sqlite'
50 | cache_sqlite
51 | end
52 | end
53 |
54 | def cache_xml
55 | data = XmlSimple.xml_in(File.open File.expand_path @favorites_folder + @favorites_xml)['object'].select do |obj|
56 | obj['type'] == 'FAVORITE' && obj['relationship'][0]['name'] == 'collection' && obj['relationship'][0]['idrefs'] != 'z103'
57 | end
58 |
59 | favorites = {
60 | 'list' => data.map do |fav|
61 |
62 | username = fav['attribute'].detect { |attr| attr['name'] == 'username' }
63 | username = username ? username['content'] : 'anonymous'
64 | {
65 | 'uuid' => fav['attribute'].detect { |attr| attr['name'] == 'uuidstring' }['content'],
66 | 'name' => fav['attribute'].detect { |attr| attr['name'] == 'nickname' }['content'],
67 | 'server' => fav['attribute'].detect { |attr| attr['name'] == 'server' }['content'],
68 | 'username' => username,
69 | }
70 | end
71 | }
72 |
73 | favorites['time'] = Time.now.to_i
74 | File.open('favorites.json', 'w') { |file| file.write(JSON.generate favorites) }
75 | favorites
76 | end
77 |
78 | def cache_sqlite
79 | favorites = {
80 | 'time' => Time.now.to_i,
81 | 'list' => []
82 | }
83 | db = SQLite3::Database.open File.expand_path @favorites_folder + @favorites_sqlite
84 | db.execute("select ZUUIDSTRING, ZNICKNAME, ZSERVER, ZUSERNAME from ZOBJECT where Z2_COLLECTION = 2") do |row|
85 | favorites['list'] << {
86 | 'uuid' => row[0],
87 | 'name' => row[1],
88 | 'server' => row[2],
89 | 'username' => row[3],
90 | }
91 | end
92 | File.open('favorites.json', 'w') { |file| file.write(JSON.generate favorites) }
93 | favorites
94 | end
95 | end
--------------------------------------------------------------------------------