gnip 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. data/README +144 -0
  2. data/Rakefile +53 -0
  3. data/TODO +72 -0
  4. data/bin/gnip +651 -0
  5. data/doc/api.html +1201 -0
  6. data/gemspec.rb +47 -0
  7. data/gnip-0.4.2.gem +0 -0
  8. data/lib/gnip.rb +71 -0
  9. data/lib/gnip/activity.rb +663 -0
  10. data/lib/gnip/api.rb +191 -0
  11. data/lib/gnip/arguments.rb +21 -0
  12. data/lib/gnip/blankslate.rb +5 -0
  13. data/lib/gnip/config.rb +144 -0
  14. data/lib/gnip/filter.rb +304 -0
  15. data/lib/gnip/list.rb +126 -0
  16. data/lib/gnip/options.rb +96 -0
  17. data/lib/gnip/orderedhash.rb +199 -0
  18. data/lib/gnip/publisher.rb +309 -0
  19. data/lib/gnip/resource.rb +301 -0
  20. data/lib/gnip/template.rb +44 -0
  21. data/lib/gnip/util.rb +120 -0
  22. data/sample/data/activity.yml +21 -0
  23. data/test/auth.rb +60 -0
  24. data/test/config.yml +2 -0
  25. data/test/data/activity.xml +14 -0
  26. data/test/data/activity_only_required.xml +4 -0
  27. data/test/data/activity_with_payload.xml +22 -0
  28. data/test/data/activity_with_place.xml +18 -0
  29. data/test/data/activity_with_place_wo_bounds.xml +36 -0
  30. data/test/data/activity_with_unbounded_media_urls.xml +44 -0
  31. data/test/data/activity_without_bounds.xml +24 -0
  32. data/test/helper.rb +115 -0
  33. data/test/helper.rb.bak +28 -0
  34. data/test/integration/auth.rb +12 -0
  35. data/test/integration/publisher.rb +86 -0
  36. data/test/lib/shoulda.rb +9 -0
  37. data/test/lib/shoulda/action_controller.rb +28 -0
  38. data/test/lib/shoulda/action_controller/helpers.rb +47 -0
  39. data/test/lib/shoulda/action_controller/macros.rb +277 -0
  40. data/test/lib/shoulda/action_controller/matchers.rb +37 -0
  41. data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  42. data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  43. data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  44. data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  45. data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
  46. data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  47. data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  48. data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  49. data/test/lib/shoulda/action_mailer.rb +10 -0
  50. data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
  51. data/test/lib/shoulda/action_view.rb +10 -0
  52. data/test/lib/shoulda/action_view/macros.rb +56 -0
  53. data/test/lib/shoulda/active_record.rb +16 -0
  54. data/test/lib/shoulda/active_record/assertions.rb +69 -0
  55. data/test/lib/shoulda/active_record/helpers.rb +40 -0
  56. data/test/lib/shoulda/active_record/macros.rb +586 -0
  57. data/test/lib/shoulda/active_record/matchers.rb +42 -0
  58. data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  59. data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  60. data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  61. data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  62. data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  63. data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  64. data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  65. data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  66. data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  67. data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  68. data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  69. data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  70. data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  71. data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  72. data/test/lib/shoulda/assertions.rb +59 -0
  73. data/test/lib/shoulda/autoload_macros.rb +46 -0
  74. data/test/lib/shoulda/context.rb +304 -0
  75. data/test/lib/shoulda/helpers.rb +8 -0
  76. data/test/lib/shoulda/macros.rb +73 -0
  77. data/test/lib/shoulda/private_helpers.rb +20 -0
  78. data/test/lib/shoulda/proc_extensions.rb +14 -0
  79. data/test/lib/shoulda/rails.rb +13 -0
  80. data/test/lib/shoulda/rspec.rb +9 -0
  81. data/test/lib/shoulda/tasks.rb +3 -0
  82. data/test/lib/shoulda/tasks/list_tests.rake +29 -0
  83. data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  84. data/test/lib/shoulda/test_unit.rb +19 -0
  85. data/test/lib/xmlsimple.rb +1021 -0
  86. data/test/loader.rb +25 -0
  87. data/test/unit/activity.rb +26 -0
  88. data/test/unit/util.rb +39 -0
  89. metadata +198 -0
data/README ADDED
@@ -0,0 +1,144 @@
1
+ NAME
2
+ gnip
3
+
4
+ SYNOPSIS
5
+ gnip (config|ping|clock_drift|encode|decode|version|publisher|activity|notification|filter) [options]+
6
+
7
+ DESCRIPTION
8
+ gnip.rb is *the* clinically proven, most effective way, to keep your ruby
9
+ codez on the pulse of the freaking interwebs. gnip.rb slings rest-fu
10
+ around like mr.t slings suckas while rocking out to deep-house and pouring
11
+ wine for the ladeez. gnip.rb brings you power and speed with a silkly
12
+ smooth mixture of equal parts restclient, nokogiri, tagz, and threadify.
13
+ sit back and let gnip.rb bring the very tastiest portions of the tubes
14
+ down onto your very own hard drive for your dining pleasure.
15
+
16
+ we have what you are looking for.
17
+
18
+ PARAMETERS
19
+ --username=[username], -U (0 ~> username)
20
+ --password=[password], -P (0 ~> password)
21
+ --scope=[scope], -S (0 ~> scope=gnip)
22
+ --name=[name], -N (0 ~> name)
23
+ --ago=[ago], -a (0 ~> integer(ago))
24
+ --thru=[thru], -t (0 ~> thru)
25
+ --bucket=[bucket], -b (0 ~> bucket)
26
+ --filter=[filter], -f (0 ~> filter)
27
+ --style=[style], -s (0 ~> style)
28
+ --force=[force] (0 ~> boolean(force))
29
+ --log=[log], -l (0 ~> log)
30
+ --input=[input], -i (0 ~> input)
31
+ --help, -h
32
+
33
+ AUTHOR
34
+ ara.t.howard@gmail.com
35
+
36
+ EXAMPLES
37
+ @quick
38
+ . sup on digg recently?
39
+ gnip notification digg --ago=30 --thru=now
40
+
41
+ . and twitter right now?
42
+ gnip notification twitter
43
+
44
+ . stalk someone on tumblr
45
+ gnip filter rule create tumblr catch-him-in-the-act actor:boyfriend
46
+ gnip activity digg --filter=catch-him-in-the-act --bucket=all
47
+
48
+ @setup
49
+ . dump the current gnip config
50
+ gnip config
51
+
52
+ . create a ~/.gnip.yml config file
53
+ gnip config generate
54
+
55
+ . ping gnip to verify your config
56
+ gnip ping
57
+
58
+ . show gnip clock shift from your local time
59
+ gnip clock_drift
60
+
61
+ @publisher
62
+ . list gnip publishers
63
+ gnip publisher list
64
+
65
+ . list publishers in the /my scope
66
+ gnip publisher list --scope=my
67
+
68
+ . create a publisher name 'publisher-name' in the /my scope with actor and keyword rules
69
+ gnip publisher create my-publisher actor keyword --scope=my
70
+
71
+ . show a publisher by name
72
+ gnip publisher show my-publisher
73
+
74
+ . delete a publisher in the /my scope
75
+ gnip publisher delete my-publisher --scope=my
76
+
77
+
78
+ @activity | @notification
79
+ . list the activity stream of a publisher
80
+ gnip notification stream digg
81
+
82
+ . list the activity of a publisher
83
+ gnip notification list digg
84
+
85
+ . list the activity of a publisher 10 minutes ago
86
+ gnip notification list digg --ago=10
87
+
88
+ . list all activity of a publisher starting 60-10 minutes (parallel requests)
89
+ gnip notification list digg --ago=60 --thru=10
90
+
91
+ . list all possible activity of a publisher
92
+ gnip notification list digg --bucket=all
93
+
94
+ . list the filtered activity of a publisher
95
+ gnip activity list digg --filter=my-filter-name --ago=60 --thru=42
96
+
97
+ @filter
98
+ . create a publisher filter for two actors
99
+ gnip filter create digg my-filter-name --full_data=true actor:mohadata actor:livefree12
100
+
101
+ . create a publisher filter from a file full of many rules (same format as command-line, one per line)
102
+ gnip filter create digg my-filter-name --input=file-full-of-rules.txt
103
+
104
+ . append rules to an existing publisher filter
105
+ gnip filter rule create digg my-filter-name actor:foobar actor:barfoo
106
+
107
+ . append rules to an existing publisher filter in bulk
108
+ gnip filter rule create digg my-filter-name --input=input
109
+
110
+ . list a specific rule for a publisher's filter
111
+ gnip filter rule list digg my-filter-name actor:livefree12
112
+
113
+ . delete a specific rule from an existing publisher filter
114
+ gnip filter rule delete digg my-filter-name actor:barfoo
115
+
116
+ . list your filters on a publisher
117
+ gnip filter list digg
118
+
119
+ @publish
120
+ . push a yml activity to a publisher
121
+ gnip activity publish my-publisher ./sample/data/activity.yml --scope=my
122
+
123
+ . scan for what you just posted (roughly)
124
+ gnip activity list my-publisher --scope=my --ago=2 --thru=now
125
+
126
+ @utility
127
+ . encode data
128
+ gnip encode 'some content'
129
+
130
+ . decode data
131
+ gnip encode 'some content' | gnip decode -
132
+
133
+ . round trip data
134
+ echo 'some content' | gnip encode - | gnip decode -
135
+
136
+ LIBRARY
137
+ see this program, samples/*, and test/**/**, for usage
138
+
139
+ URI
140
+ http://gnip.com
141
+
142
+ INSTALL
143
+ $sudo gem install gnip
144
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ task 'default' => 'test:all'
2
+
3
+ namespace 'test' do
4
+ desc 'run all tests'
5
+ task 'all' => %w[ unit integration ] do
6
+ end
7
+
8
+ desc 'run unit tests'
9
+ task 'unit' do
10
+ %w[
11
+ activity
12
+ ].each do |basename|
13
+ test_loader "test/unit/#{ basename }.rb"
14
+ end
15
+ end
16
+
17
+ desc 'run integration tests'
18
+ task 'integration' do
19
+ %w[
20
+ auth
21
+ publisher
22
+ ].each do |basename|
23
+ test_loader "test/integration/#{ basename }.rb", :require_auth => true
24
+ end
25
+ end
26
+ end
27
+
28
+ task 'test' => 'test:all' do
29
+ end
30
+
31
+ namespace 'gem' do
32
+ task 'build' do
33
+ sh 'gemspec.rb'
34
+ end
35
+ task 'release' => 'build' do
36
+ gem = Dir['gnip*.gem'].sort.last or abort('no gem!')
37
+ version = gem[%r/[\d.]+/]
38
+ command = "rubyforge login && rubyforge add_release gnip 'gnip' '#{ version }' '#{ gem }'"
39
+ sh command
40
+ end
41
+ end
42
+
43
+ BEGIN {
44
+ Dir.chdir(File.dirname(__FILE__))
45
+ ENV['PATH'] = [ '.', './bin/', ENV['PATH'] ].join(File::PATH_SEPARATOR)
46
+
47
+ def test_loader basename, options = {}
48
+ auth = '-r test/auth.rb ' if options[:require_auth]
49
+ command = "ruby -r test/loader.rb #{ auth }#{ basename }"
50
+ STDERR.print "\n==== TEST ====\n\n #{ command }\n\n==============\n\n"
51
+ system command or abort("#{ command } # FAILED WITH #{ $?.inspect }")
52
+ end
53
+ }
data/TODO ADDED
@@ -0,0 +1,72 @@
1
+ ---
2
+
3
+ . gem release
4
+
5
+ . more sample programs
6
+
7
+ . tests for bin/gnip using yaml output
8
+
9
+ . flesh out rather minimal tests
10
+
11
+ . yank out shoulda for testing?
12
+
13
+ . unify some of the (to/from)_(hash/yaml) stuff across the lib
14
+
15
+ . abstract builder! pattern out for all Attributes
16
+
17
+
18
+
19
+ ---
20
+ .activity
21
+ . payload compress/decompress
22
+ . publishing to publisher
23
+ . curl --data-binary @activity.xml -H 'Content-Type:application/xml' --silent --user ara.t.howard@gmail.com:password https://api-v21.gnip.com/my/publishers/pub/activity.xml
24
+ . display of payload/raw from commandline
25
+
26
+ . version
27
+
28
+ . clean up pluralization in lib
29
+
30
+ . sample program
31
+
32
+ . server callbacks
33
+
34
+ . flush out bin/gnip
35
+
36
+ . decide between tagz vs erb for xml generation
37
+
38
+ . html escape
39
+ . CGI.escapeHTML(CGI.escapeHTML('world & business'))
40
+
41
+ . filter-rules
42
+ . get
43
+ . post
44
+ . delete
45
+ . post in bulk (stdin)
46
+
47
+ . filters
48
+ . create
49
+ . list
50
+ . delete
51
+ . update/replace/put
52
+ . rule post in bulk (stdin)
53
+
54
+ . publisher
55
+ . create
56
+ . delete
57
+ . notifications
58
+ . current
59
+ . by timestamp
60
+ . ago
61
+ . extract rule types from xml
62
+
63
+ . gnip
64
+ . clock delta
65
+
66
+ . samples
67
+
68
+ . http wrapper/resource
69
+ . my vs gnip
70
+ . safe login uri
71
+ . setup test environment for unit + integration w/shoulda
72
+ . get access to docs
data/bin/gnip ADDED
@@ -0,0 +1,651 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'gnip'
4
+ require 'main'
5
+ require 'pp'
6
+ require 'yaml'
7
+
8
+ Main {
9
+ ##
10
+ description <<-__
11
+ gnip.rb is *the* clinically proven, most effective way, to keep your ruby
12
+ codez on the pulse of the freaking interwebs. gnip.rb slings rest-fu
13
+ around like mr.t slings suckas while rocking out to deep-house and pouring
14
+ wine for the ladeez. gnip.rb brings you power and speed with a silkly
15
+ smooth mixture of equal parts restclient, nokogiri, tagz, and threadify.
16
+ sit back and let gnip.rb bring the very tastiest portions of the tubes
17
+ down onto your very own hard drive for your dining pleasure.
18
+
19
+ we have what you are looking for.
20
+ __
21
+
22
+ ##
23
+ examples <<-__
24
+ @quick
25
+ . sup on digg recently?
26
+ gnip notification digg --ago=30 --thru=now
27
+
28
+ . and twitter right now?
29
+ gnip notification twitter
30
+
31
+ . stalk someone on tumblr
32
+ gnip filter rule create tumblr catch-him-in-the-act actor:boyfriend
33
+ gnip activity digg --filter=catch-him-in-the-act --bucket=all
34
+
35
+ @setup
36
+ . dump the current gnip config
37
+ gnip config
38
+
39
+ . create a ~/.gnip.yml config file
40
+ gnip config generate
41
+
42
+ . ping gnip to verify your config
43
+ gnip ping
44
+
45
+ . show gnip clock shift from your local time
46
+ gnip clock_drift
47
+
48
+ @publisher
49
+ . list gnip publishers
50
+ gnip publisher list
51
+
52
+ . list publishers in the /my scope
53
+ gnip publisher list --scope=my
54
+
55
+ . create a publisher name 'publisher-name' in the /my scope with actor and keyword rules
56
+ gnip publisher create my-publisher actor keyword --scope=my
57
+
58
+ . show a publisher by name
59
+ gnip publisher show my-publisher
60
+
61
+ . delete a publisher in the /my scope
62
+ gnip publisher delete my-publisher --scope=my
63
+
64
+
65
+ @activity | @notification
66
+ . list the activity stream of a publisher
67
+ gnip notification stream digg
68
+
69
+ . list the activity of a publisher
70
+ gnip notification list digg
71
+
72
+ . list the activity of a publisher 10 minutes ago
73
+ gnip notification list digg --ago=10
74
+
75
+ . list all activity of a publisher starting 60-10 minutes (parallel requests)
76
+ gnip notification list digg --ago=60 --thru=10
77
+
78
+ . list all possible activity of a publisher
79
+ gnip notification list digg --bucket=all
80
+
81
+ . list the filtered activity of a publisher
82
+ gnip activity list digg --filter=my-filter-name --ago=60 --thru=42
83
+
84
+ @filter
85
+ . create a publisher filter for two actors
86
+ gnip filter create digg my-filter-name --full_data=true actor:mohadata actor:livefree12
87
+
88
+ . create a publisher filter from a file full of many rules (same format as command-line, one per line)
89
+ gnip filter create digg my-filter-name --input=file-full-of-rules.txt
90
+
91
+ . append rules to an existing publisher filter
92
+ gnip filter rule create digg my-filter-name actor:foobar actor:barfoo
93
+
94
+ . append rules to an existing publisher filter in bulk
95
+ gnip filter rule create digg my-filter-name --input=input
96
+
97
+ . list a specific rule for a publisher's filter
98
+ gnip filter rule list digg my-filter-name actor:livefree12
99
+
100
+ . delete a specific rule from an existing publisher filter
101
+ gnip filter rule delete digg my-filter-name actor:barfoo
102
+
103
+ . list your filters on a publisher
104
+ gnip filter list digg
105
+
106
+ @publish
107
+ . push a yml activity to a publisher
108
+ gnip activity publish my-publisher ./sample/data/activity.yml --scope=my
109
+
110
+ . scan for what you just posted (roughly)
111
+ gnip activity list my-publisher --scope=my --ago=2 --thru=now
112
+
113
+ @utility
114
+ . encode data
115
+ gnip encode 'some content'
116
+
117
+ . decode data
118
+ gnip encode 'some content' | gnip decode -
119
+
120
+ . round trip data
121
+ echo 'some content' | gnip encode - | gnip decode -
122
+ __
123
+
124
+ ##
125
+ author 'ara.t.howard@gmail.com'
126
+
127
+ ##
128
+ usage :LIBRARY, <<-__
129
+ see this program, samples/*, and test/**/**, for usage
130
+ __
131
+
132
+ usage :URI, <<-__
133
+ http://gnip.com
134
+ __
135
+
136
+ usage :INSTALL, <<-__
137
+ $sudo gem install gnip
138
+ __
139
+
140
+ ##
141
+ option('--username', '-U'){
142
+ argument 'required'
143
+ cast{|value| Gnip.username = value}
144
+ }
145
+
146
+ option('--password', '-P'){
147
+ argument 'required'
148
+ cast{|value| Gnip.password = value}
149
+ }
150
+
151
+ option('--scope', '-S'){
152
+ argument 'required'
153
+ default 'gnip'
154
+ }
155
+
156
+ option('--name', '-N'){
157
+ argument 'required'
158
+ }
159
+
160
+ option('--ago', '-a'){
161
+ argument 'required'
162
+ cast :integer
163
+ }
164
+
165
+ option('--thru', '-t'){
166
+ argument 'required'
167
+ cast{|value| Integer(value =~ /current|now/ ? 0 : value)}
168
+ }
169
+
170
+ option('--bucket', '-b'){
171
+ argument 'required'
172
+ }
173
+
174
+ option('--filter', '-f'){
175
+ argument 'required'
176
+ }
177
+
178
+ option('--style', '-s'){
179
+ argument 'required'
180
+ }
181
+
182
+ option('--force'){
183
+ argument 'optional'
184
+ cast :boolean
185
+ }
186
+
187
+ option('--log', '-l'){
188
+ argument :optional
189
+ }
190
+
191
+ option('--input', '-i'){
192
+ argument 'required'
193
+ cast{|value| (value =~ /-/ ? STDIN.readlines : IO.readlines(value)).map{|line| line.strip}}
194
+ }
195
+
196
+ def before_run
197
+ if log = params['log'].value
198
+ log = 'stderr' if log == true
199
+ ENV['GNIP_HTTP_LOG'] = log
200
+ end
201
+ end
202
+
203
+
204
+ ##
205
+ mode(:config) do
206
+ description 'dump out the discovered gnip config'
207
+ def run
208
+ y Gnip.config.default.to_hash
209
+ end
210
+
211
+ mode(:generate) do
212
+ description 'generate a template config file'
213
+ def run
214
+ path = Gnip.config.default.class.default_path
215
+ abort "#{ path } exists!" if test(?s, path)
216
+ open(path, 'w') do |fd|
217
+ config = {'username' => 'YOU@ROCK.COM', 'password' => 'ANGINA'}
218
+ fd.puts config.to_yaml
219
+ end
220
+ system "#{ ENV['EDITOR']||:vim } #{ path }"
221
+ puts path
222
+ end
223
+ end
224
+ end
225
+
226
+ ##
227
+ mode(:ping) do
228
+ def run
229
+ y Gnip.ping
230
+ end
231
+ end
232
+
233
+ ##
234
+ mode(:clock_drift) do
235
+ def run
236
+ force = params[:force].value
237
+ y Gnip.clock_drift(:force => force)
238
+ end
239
+ end
240
+
241
+ ##
242
+ mode(:encode) do
243
+ def run
244
+ stdin = argv.delete('-')
245
+ data = argv.join
246
+ data += STDIN.read if stdin
247
+ STDOUT.write Gnip.encode(data)
248
+ end
249
+ end
250
+
251
+ mode(:decode) do
252
+ def run
253
+ stdin = argv.delete('-')
254
+ data = argv.join
255
+ data += STDIN.read if stdin
256
+ STDOUT.write Gnip.decode(data)
257
+ end
258
+ end
259
+
260
+ mode(:version) do
261
+ def run
262
+ puts Gnip.version
263
+ end
264
+ end
265
+
266
+ ##
267
+ mode(:publisher){
268
+ ##
269
+ mode(:create){
270
+ description 'create a publisher yo'
271
+ def run
272
+ scope = param[:scope].value
273
+ name = param[:name].value || argv.shift || abort('no name')
274
+ rules = argv
275
+
276
+ publisher = Gnip.publisher.create(name, :scope => scope, :rules => rules)
277
+ y publisher.name
278
+ end
279
+ }
280
+ ##
281
+ mode(:list){
282
+ description "list publishers"
283
+ def run
284
+ scope = param[:scope].value
285
+ list = Gnip.publisher.list(:scope => scope)
286
+ y list.map{|publisher| publisher.name}
287
+ end
288
+ }
289
+ ##
290
+ mode(:delete){
291
+ description 'nuke a publisher yo'
292
+ def run
293
+ scope = param[:scope].value
294
+ name = param[:name].value || argv.shift || abort('no name')
295
+
296
+ publisher = Gnip.publisher.for(name, :scope => scope)
297
+ if publisher
298
+ publisher.delete
299
+ y publisher.name
300
+ else
301
+ exit 42
302
+ end
303
+ end
304
+ }
305
+ ##
306
+ mode(:inspect){
307
+ description 'inspect a publisher'
308
+
309
+ def run
310
+ scope = param[:scope].value
311
+ name = param[:name].value || argv.shift || abort('no name')
312
+ publisher = Gnip.publisher.for(name, :scope => scope)
313
+ publisher ? pp(publisher) : exit(42)
314
+ end
315
+ }
316
+ ##
317
+ mode(:show){
318
+ description 'show a publisher'
319
+
320
+ def run
321
+ scope = param[:scope].value
322
+ name = param[:name].value || argv.shift || abort('no name')
323
+ publisher = Gnip.publisher.for(name, :scope => scope)
324
+ if publisher
325
+ y publisher.name => publisher.rules.map{|rule| rule.to_s}
326
+ else
327
+ exit(42)
328
+ end
329
+ end
330
+ }
331
+ }
332
+
333
+ ##
334
+ mixin(:activities){
335
+
336
+ def limited_activity_view activity
337
+ oh =
338
+ Gnip.orderedhash[
339
+ 'activity_id', activity.activity_id,
340
+ 'at', activity.at,
341
+ 'action', activity.action,
342
+ 'url', activity.url,
343
+ 'sources', activity.sources,
344
+ 'keywords', activity.keywords,
345
+ 'places', activity.places,
346
+ 'actors', activity.actors,
347
+ 'destination_url', activity.destination_urls,
348
+ 'tags', activity.tags,
349
+ 'tos', activity.tos,
350
+ 'regarding_url', activity.regarding_urls
351
+ ]
352
+ end
353
+
354
+ mode(:list){
355
+ description 'access publisher activity'
356
+ def run
357
+ scope = param[:scope].value
358
+ ago = param[:ago].value
359
+ thru = param[:thru].value
360
+ bucket = param[:bucket].value
361
+ style = param[:style].value || self.class.const_get(:Style)
362
+ filter = param[:filter].value
363
+
364
+ name = param[:name].value || argv.shift || abort('no name')
365
+
366
+ publisher = Gnip.publisher.for(name, :scope => scope)
367
+ activities = publisher.activity(:filter => filter, :style => style, :ago => ago, :bucket => bucket, :thru => thru)
368
+
369
+ list = []
370
+
371
+ activities.each do |activity|
372
+ list << limited_activity_view(activity)
373
+ end
374
+
375
+ y list
376
+ end
377
+ }
378
+ ##
379
+ mode(:stream){
380
+ description 'dump the activity stream listing for a publisher'
381
+ def run
382
+ scope = param[:scope].value
383
+ name = param[:name].value || argv.shift || abort('no name')
384
+ style = param[:style].value || self.class.const_get(:Style)
385
+
386
+ publisher = Gnip.publisher.for(name, :scope => scope)
387
+ if publisher
388
+ activity_stream = publisher.activity_stream(:style => style)
389
+ y :updated_at => activity_stream.updated_at.to_s, :buckets => activity_stream.buckets.to_a
390
+ else
391
+ exit 42
392
+ end
393
+ end
394
+ }
395
+ }
396
+
397
+ ##
398
+ mode(:activity){
399
+ const_set :Style, 'activity'
400
+ mixin :activities
401
+ ##
402
+ mode(:publish){
403
+ description 'publish activities to a publisher'
404
+ argument('name')
405
+ argument('yaml_input_file_or_stdin'){ optional true }
406
+
407
+ def run
408
+ scope = param[:scope].value
409
+ name = param[:name].value
410
+ yaml_input_file_or_stdin = params[:yaml_input_file_or_stdin]||'-'
411
+
412
+ input = yaml_input_file_or_stdin.value
413
+
414
+ obj =
415
+ if input == '-'
416
+ YAML.load(STDIN.read)
417
+ else
418
+ YAML.load(open(input){|f| f.read})
419
+ end
420
+
421
+ hashes = [obj] unless obj.is_a?(Array)
422
+
423
+ publisher = Gnip.publisher.for(name, :scope => scope)
424
+
425
+ if publisher
426
+ activities = []
427
+
428
+ hashes.each do |hash|
429
+ payload = hash['payload']
430
+ raw = (payload && payload.is_a?(Hash) && payload['raw'])
431
+ if raw =~ %r/^\s*@(.*)\s*$/
432
+ raw = $1.strip
433
+ raw = raw == '-' ? STDIN.read : IO.read(raw)
434
+ payload['raw'] = raw
435
+ end
436
+
437
+ activity = Gnip.activity.from_hash(hash)
438
+ activities << activity
439
+ end
440
+ publisher.publish(activities)
441
+
442
+ list = activities.map{|activity| limited_activity_view(activity)}
443
+ y list
444
+ else
445
+ exit 42
446
+ end
447
+ end
448
+ }
449
+ }
450
+
451
+ ##
452
+ mode(:notification){
453
+ const_set :Style, 'notification'
454
+ mixin :activities
455
+ }
456
+
457
+ ##
458
+ mode(:filter){
459
+ ##
460
+ mode(:create){
461
+ description 'create a filter'
462
+
463
+ argument('publisher_name')
464
+ argument('filter_name')
465
+ argument('rules'){ arity -1 }
466
+
467
+ option('--full_data'){
468
+ argument 'required'
469
+ default false
470
+ cast :boolean
471
+ }
472
+ option('--post_url'){
473
+ argument 'required'
474
+ }
475
+
476
+ def run
477
+ scope = param[:scope].value
478
+ publisher_name = param[:publisher_name].value
479
+ filter_name = param[:filter_name].value
480
+ rules = param[:rules].values
481
+ post_url = param[:post_url].value
482
+ full_data = param[:full_data].value
483
+ input = param[:input].value
484
+
485
+ rules.push(*input) if input
486
+ rules.map! do |rule|
487
+ type, value = rule.strip.split(/:/, 2)
488
+ {:type => type, :value => value} if type and value
489
+ end.compact
490
+
491
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
492
+ if publisher
493
+ filter = publisher.filter.create(filter_name, rules, :full_data => full_data, :post_url => post_url)
494
+ y filter.name
495
+ else
496
+ exit 42
497
+ end
498
+ end
499
+ }
500
+ ##
501
+ mode(:list){
502
+ description 'list filters'
503
+
504
+ def run
505
+ scope = param[:scope].value
506
+ name = param[:name].value || argv.shift || abort('no name')
507
+
508
+ publisher = Gnip.publisher.for(name, :scope => scope)
509
+ if publisher
510
+ filters = publisher.filter.list
511
+ y filters.map{|filter| filter.name}
512
+ else
513
+ exit 42
514
+ end
515
+ end
516
+ }
517
+ ##
518
+ mode(:inspect){
519
+ description 'inspect a filter'
520
+
521
+ argument('publisher_name')
522
+ argument('filter_name')
523
+
524
+ def run
525
+ scope = param[:scope].value
526
+ publisher_name = param[:publisher_name].value
527
+ filter_name = param[:filter_name].value
528
+
529
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
530
+ if publisher
531
+ filter = publisher.filter.for(filter_name)
532
+ filter.publisher = nil rescue nil # just prettier output
533
+ pp filter
534
+ else
535
+ exit 42
536
+ end
537
+ end
538
+ }
539
+ ##
540
+ mode(:delete){
541
+ description 'delete a filter'
542
+
543
+ argument('publisher_name')
544
+ argument('filter_name')
545
+
546
+ def run
547
+ scope = param[:scope].value
548
+ publisher_name = param[:publisher_name].value
549
+ filter_name = param[:filter_name].value
550
+
551
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
552
+ if publisher
553
+ filter = publisher.filter.for(filter_name)
554
+ filter.delete
555
+ y filter.name
556
+ else
557
+ exit 42
558
+ end
559
+ end
560
+ }
561
+
562
+ ##
563
+ mode(:rule){
564
+ mode(:list){
565
+ description 'list the rules for a filter'
566
+
567
+ argument('publisher_name')
568
+ argument('filter_name')
569
+ argument('rule')
570
+
571
+
572
+ def run
573
+ scope = param[:scope].value
574
+ publisher_name = param[:publisher_name].value
575
+ filter_name = param[:filter_name].value
576
+ rule = param[:rule].value
577
+
578
+ type, value = rule.split(/:/, 2)
579
+
580
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
581
+ if publisher
582
+ filter = publisher.filter.for(filter_name)
583
+ y filter.rule.list(:type => type, :value => value).inspect
584
+ else
585
+ exit 42
586
+ end
587
+ end
588
+ }
589
+
590
+ mode(:create){
591
+ description 'append rules to a filter'
592
+
593
+ argument('publisher_name')
594
+ argument('filter_name')
595
+ argument('rules'){ arity -1 }
596
+
597
+ def run
598
+ scope = param[:scope].value
599
+ publisher_name = param[:publisher_name].value
600
+ filter_name = param[:filter_name].value
601
+ rules = param[:rules].values
602
+ input = param[:input].value
603
+
604
+ rules.push(*input) if input
605
+
606
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
607
+ if publisher
608
+ filter = publisher.filter.for(filter_name)
609
+ rules = filter.rule.create(*rules)
610
+ y rules.map{|rule| rule.to_s}
611
+ else
612
+ exit 42
613
+ end
614
+ end
615
+ }
616
+
617
+ mode(:delete){
618
+ description 'delete a filter rule'
619
+
620
+ argument('publisher_name')
621
+ argument('filter_name')
622
+ argument('rule')
623
+
624
+
625
+ def run
626
+ scope = param[:scope].value
627
+ publisher_name = param[:publisher_name].value
628
+ filter_name = param[:filter_name].value
629
+ rule = param[:rule].value
630
+
631
+ type, value = rule.split(/:/, 2)
632
+
633
+ publisher = Gnip.publisher.for(publisher_name, :scope => scope)
634
+ if publisher
635
+ filter = publisher.filter.for(filter_name)
636
+ rule = filter.rule.list(:type => type, :value => value)
637
+ rule.delete
638
+ y rule
639
+ else
640
+ exit 42
641
+ end
642
+ end
643
+ }
644
+ }
645
+ }
646
+
647
+
648
+ def run
649
+ abort usage.to_s
650
+ end
651
+ }