Skip to content

Commit 3ccf87d

Browse files
committed
New feature: Search stocked items
1 parent f30e5d0 commit 3ccf87d

File tree

11 files changed

+310
-23
lines changed

11 files changed

+310
-23
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,45 @@
22

33
![alt tag](https://raw.github.com/oame/alfred-qiita-workflow/master/screenshots/qiita-workflow.png)
44

5+
# System Requirements
6+
7+
- OS X Mavericks(with Ruby 2.0.0)
8+
59
## Installation
610

711
Double-click `Qiita.alfredworkflow` to install Alfred workflow.
812

9-
## Development Installation
13+
## Commands
14+
15+
### Search items
16+
17+
```
18+
qiita search <query>
19+
```
20+
21+
### Fetch authentication token from Qiita
22+
23+
```
24+
qiita setup <name> <password>
25+
```
26+
27+
### Search stocked items from Qiita
28+
29+
```
30+
qiita stocks <query>
31+
```
32+
33+
## Contributing
34+
35+
### Fork project
36+
37+
1. Fork it
38+
2. Create your feature branch (`git checkout -b my-new-feature`)
39+
3. Commit your changes (`git commit -am 'Added some feature'`)
40+
4. Push to the branch (`git push origin my-new-feature`)
41+
5. Create new Pull Request
42+
43+
### Development Installation
1044

1145
```
1246
$ bundle install
File renamed without changes.

commands/setup.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
QUERY = ARGV[0].to_s.strip
2+
3+
require_relative "../lib/qiita"
4+
5+
credentials = QUERY.split(/\s/)
6+
7+
unless credentials.count == 2
8+
puts "RUN: qiita setup <NAME> <PASSWORD>"
9+
exit
10+
end
11+
12+
auth = Qiita::API.auth name: credentials.first, password: credentials.last
13+
14+
unless auth
15+
puts "ERROR: Authentication failed"
16+
exit
17+
end
18+
19+
config = Qiita::Config.new name: auth['url_name'], token: auth['token']
20+
config.save
21+
22+
puts "Setup complete"

commands/stocks.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
QUERY = ARGV[0].to_s.strip
2+
3+
require_relative "../lib/qiita"
4+
5+
begin
6+
config = Qiita::Config.new
7+
rescue Qiita::FileMissingError
8+
Qiita::Alfred.message "RUN: 'qiita setup' command first"
9+
exit
10+
end
11+
12+
unless config.token
13+
Qiita::Alfred.message "RUN: 'qiita setup' command first"
14+
exit
15+
end
16+
17+
data = Qiita::API.search(QUERY, token: config.token, stocked: 1)
18+
19+
results = []
20+
data.each do |q|
21+
subtitle = "Stocks: " + q['stock_count'].to_s + " LGTM:" + q['lgtm_count'].to_s + " Comments:" + q['comment_count'].to_s + " Create At:" + q['created_at']
22+
23+
item = {
24+
uid: q['id'],
25+
arg: q['url'],
26+
title: q['title'],
27+
subtitle: subtitle,
28+
icon: 'icon.png'
29+
}
30+
31+
results << item
32+
end
33+
34+
puts Qiita::Alfred.to_alfred(results)

info.plist

Lines changed: 153 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@
1717
<string></string>
1818
</dict>
1919
</array>
20+
<key>2310843B-B161-45E3-85DC-2E6012E5F32B</key>
21+
<array>
22+
<dict>
23+
<key>destinationuid</key>
24+
<string>CE609731-0A54-412A-A280-60EF147C38BD</string>
25+
<key>modifiers</key>
26+
<integer>0</integer>
27+
<key>modifiersubtext</key>
28+
<string></string>
29+
</dict>
30+
</array>
31+
<key>4C2D68C3-274B-4EF1-9B54-49425EA5B062</key>
32+
<array>
33+
<dict>
34+
<key>destinationuid</key>
35+
<string>69080009-C277-4E69-B3E0-4E7122F480FD</string>
36+
<key>modifiers</key>
37+
<integer>0</integer>
38+
<key>modifiersubtext</key>
39+
<string></string>
40+
</dict>
41+
</array>
42+
<key>A09B6C79-947F-42CE-91DD-0F3DFDC78C45</key>
43+
<array>
44+
<dict>
45+
<key>destinationuid</key>
46+
<string>2310843B-B161-45E3-85DC-2E6012E5F32B</string>
47+
<key>modifiers</key>
48+
<integer>0</integer>
49+
<key>modifiersubtext</key>
50+
<string></string>
51+
</dict>
52+
</array>
2053
</dict>
2154
<key>createdby</key>
2255
<string>o_ame</string>
@@ -28,6 +61,69 @@
2861
<string>Qiita</string>
2962
<key>objects</key>
3063
<array>
64+
<dict>
65+
<key>config</key>
66+
<dict>
67+
<key>escaping</key>
68+
<integer>0</integer>
69+
<key>script</key>
70+
<string>ruby ./commands/setup.rb "{query}"</string>
71+
<key>type</key>
72+
<integer>0</integer>
73+
</dict>
74+
<key>type</key>
75+
<string>alfred.workflow.action.script</string>
76+
<key>uid</key>
77+
<string>2310843B-B161-45E3-85DC-2E6012E5F32B</string>
78+
<key>version</key>
79+
<integer>0</integer>
80+
</dict>
81+
<dict>
82+
<key>config</key>
83+
<dict>
84+
<key>argumenttype</key>
85+
<integer>0</integer>
86+
<key>keyword</key>
87+
<string>qiita setup</string>
88+
<key>subtext</key>
89+
<string>RUN: qiita setup &lt;name&gt; &lt;password&gt;</string>
90+
<key>text</key>
91+
<string>Qiita Setup</string>
92+
<key>withspace</key>
93+
<true/>
94+
</dict>
95+
<key>type</key>
96+
<string>alfred.workflow.input.keyword</string>
97+
<key>uid</key>
98+
<string>A09B6C79-947F-42CE-91DD-0F3DFDC78C45</string>
99+
<key>version</key>
100+
<integer>0</integer>
101+
</dict>
102+
<dict>
103+
<key>config</key>
104+
<dict>
105+
<key>lastpathcomponent</key>
106+
<false/>
107+
<key>onlyshowifquerypopulated</key>
108+
<true/>
109+
<key>output</key>
110+
<integer>0</integer>
111+
<key>removeextension</key>
112+
<false/>
113+
<key>sticky</key>
114+
<false/>
115+
<key>text</key>
116+
<string>{query}</string>
117+
<key>title</key>
118+
<string>Qiita</string>
119+
</dict>
120+
<key>type</key>
121+
<string>alfred.workflow.output.notification</string>
122+
<key>uid</key>
123+
<string>CE609731-0A54-412A-A280-60EF147C38BD</string>
124+
<key>version</key>
125+
<integer>0</integer>
126+
</dict>
31127
<dict>
32128
<key>config</key>
33129
<dict>
@@ -36,13 +132,15 @@
36132
<key>escaping</key>
37133
<integer>0</integer>
38134
<key>keyword</key>
39-
<string>qiita</string>
135+
<string>qiita search</string>
40136
<key>runningsubtext</key>
41-
<string>Searching...</string>
137+
<string>Seaching for "{query}" ...</string>
42138
<key>script</key>
43-
<string>ruby ./commands/qiita.rb "{query}"</string>
139+
<string>ruby ./commands/search.rb "{query}"</string>
140+
<key>subtext</key>
141+
<string>Search Qiita for "{query}"</string>
44142
<key>title</key>
45-
<string>Qiita</string>
143+
<string>Seatch Qiita</string>
46144
<key>type</key>
47145
<integer>0</integer>
48146
<key>withspace</key>
@@ -72,6 +170,35 @@
72170
<key>version</key>
73171
<integer>0</integer>
74172
</dict>
173+
<dict>
174+
<key>config</key>
175+
<dict>
176+
<key>argumenttype</key>
177+
<integer>0</integer>
178+
<key>escaping</key>
179+
<integer>0</integer>
180+
<key>keyword</key>
181+
<string>qiita stocks</string>
182+
<key>runningsubtext</key>
183+
<string>Seaching for "{query}" ...</string>
184+
<key>script</key>
185+
<string>ruby ./commands/stocks.rb "{query}"</string>
186+
<key>subtext</key>
187+
<string>Search Qiita stocks for "{query}"</string>
188+
<key>title</key>
189+
<string>Search Qiita Stocks</string>
190+
<key>type</key>
191+
<integer>0</integer>
192+
<key>withspace</key>
193+
<true/>
194+
</dict>
195+
<key>type</key>
196+
<string>alfred.workflow.input.scriptfilter</string>
197+
<key>uid</key>
198+
<string>4C2D68C3-274B-4EF1-9B54-49425EA5B062</string>
199+
<key>version</key>
200+
<integer>0</integer>
201+
</dict>
75202
</array>
76203
<key>readme</key>
77204
<string></string>
@@ -80,12 +207,32 @@
80207
<key>21557827-8003-42B7-A042-16D4C9278FEC</key>
81208
<dict>
82209
<key>ypos</key>
83-
<real>140</real>
210+
<real>170</real>
211+
</dict>
212+
<key>2310843B-B161-45E3-85DC-2E6012E5F32B</key>
213+
<dict>
214+
<key>ypos</key>
215+
<real>40</real>
216+
</dict>
217+
<key>4C2D68C3-274B-4EF1-9B54-49425EA5B062</key>
218+
<dict>
219+
<key>ypos</key>
220+
<real>290</real>
84221
</dict>
85222
<key>69080009-C277-4E69-B3E0-4E7122F480FD</key>
86223
<dict>
87224
<key>ypos</key>
88-
<real>140</real>
225+
<real>170</real>
226+
</dict>
227+
<key>A09B6C79-947F-42CE-91DD-0F3DFDC78C45</key>
228+
<dict>
229+
<key>ypos</key>
230+
<real>40</real>
231+
</dict>
232+
<key>CE609731-0A54-412A-A280-60EF147C38BD</key>
233+
<dict>
234+
<key>ypos</key>
235+
<real>40</real>
89236
</dict>
90237
</dict>
91238
<key>webaddress</key>

lib/qiita.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module Qiita
2+
VERSION = '1.0'
23
BUNDLE_ID = 'co.randompaper.qiita.alfred'
34

45
CONFIG_FILE = File.expand_path("~/Library/Application Support/Alfred 2/Workflow Data/#{BUNDLE_ID}/config.json")
56
CACHE_DIR = File.expand_path("~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/#{BUNDLE_ID}")
7+
8+
class FileMissingError < StandardError; end
69
end
710

8-
require_relative 'qiita/version.rb'
911
require_relative 'qiita/object.rb'
1012
require_relative 'qiita/config.rb'
1113
require_relative 'qiita/api.rb'

lib/qiita/alfred.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ def self.to_alfred(array)
2222

2323
doc.to_s
2424
end
25+
26+
def self.message(str)
27+
puts Qiita::Alfred.to_alfred([{ uid: 0, arg: nil, title: str, subtitle: nil, icon: 'icon.png'}])
28+
end
2529
end

0 commit comments

Comments
 (0)