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.
- data/README +144 -0
- data/Rakefile +53 -0
- data/TODO +72 -0
- data/bin/gnip +651 -0
- data/doc/api.html +1201 -0
- data/gemspec.rb +47 -0
- data/gnip-0.4.2.gem +0 -0
- data/lib/gnip.rb +71 -0
- data/lib/gnip/activity.rb +663 -0
- data/lib/gnip/api.rb +191 -0
- data/lib/gnip/arguments.rb +21 -0
- data/lib/gnip/blankslate.rb +5 -0
- data/lib/gnip/config.rb +144 -0
- data/lib/gnip/filter.rb +304 -0
- data/lib/gnip/list.rb +126 -0
- data/lib/gnip/options.rb +96 -0
- data/lib/gnip/orderedhash.rb +199 -0
- data/lib/gnip/publisher.rb +309 -0
- data/lib/gnip/resource.rb +301 -0
- data/lib/gnip/template.rb +44 -0
- data/lib/gnip/util.rb +120 -0
- data/sample/data/activity.yml +21 -0
- data/test/auth.rb +60 -0
- data/test/config.yml +2 -0
- data/test/data/activity.xml +14 -0
- data/test/data/activity_only_required.xml +4 -0
- data/test/data/activity_with_payload.xml +22 -0
- data/test/data/activity_with_place.xml +18 -0
- data/test/data/activity_with_place_wo_bounds.xml +36 -0
- data/test/data/activity_with_unbounded_media_urls.xml +44 -0
- data/test/data/activity_without_bounds.xml +24 -0
- data/test/helper.rb +115 -0
- data/test/helper.rb.bak +28 -0
- data/test/integration/auth.rb +12 -0
- data/test/integration/publisher.rb +86 -0
- data/test/lib/shoulda.rb +9 -0
- data/test/lib/shoulda/action_controller.rb +28 -0
- data/test/lib/shoulda/action_controller/helpers.rb +47 -0
- data/test/lib/shoulda/action_controller/macros.rb +277 -0
- data/test/lib/shoulda/action_controller/matchers.rb +37 -0
- data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
- data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
- data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
- data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
- data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
- data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
- data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
- data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
- data/test/lib/shoulda/action_mailer.rb +10 -0
- data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
- data/test/lib/shoulda/action_view.rb +10 -0
- data/test/lib/shoulda/action_view/macros.rb +56 -0
- data/test/lib/shoulda/active_record.rb +16 -0
- data/test/lib/shoulda/active_record/assertions.rb +69 -0
- data/test/lib/shoulda/active_record/helpers.rb +40 -0
- data/test/lib/shoulda/active_record/macros.rb +586 -0
- data/test/lib/shoulda/active_record/matchers.rb +42 -0
- data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
- data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
- data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
- data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
- data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
- data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
- data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
- data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
- data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
- data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
- data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
- data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
- data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
- data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
- data/test/lib/shoulda/assertions.rb +59 -0
- data/test/lib/shoulda/autoload_macros.rb +46 -0
- data/test/lib/shoulda/context.rb +304 -0
- data/test/lib/shoulda/helpers.rb +8 -0
- data/test/lib/shoulda/macros.rb +73 -0
- data/test/lib/shoulda/private_helpers.rb +20 -0
- data/test/lib/shoulda/proc_extensions.rb +14 -0
- data/test/lib/shoulda/rails.rb +13 -0
- data/test/lib/shoulda/rspec.rb +9 -0
- data/test/lib/shoulda/tasks.rb +3 -0
- data/test/lib/shoulda/tasks/list_tests.rake +29 -0
- data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
- data/test/lib/shoulda/test_unit.rb +19 -0
- data/test/lib/xmlsimple.rb +1021 -0
- data/test/loader.rb +25 -0
- data/test/unit/activity.rb +26 -0
- data/test/unit/util.rb +39 -0
- metadata +198 -0
data/gemspec.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#! /usr/bin/env gem build
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
|
|
5
|
+
Gem::Specification::new do |spec|
|
|
6
|
+
$VERBOSE = nil
|
|
7
|
+
|
|
8
|
+
shiteless = lambda do |list|
|
|
9
|
+
list.delete_if do |file|
|
|
10
|
+
file =~ %r/\.git/ or
|
|
11
|
+
file =~ %r/\.svn/ or
|
|
12
|
+
file =~ %r/\.tmp/
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
spec.name = $lib
|
|
17
|
+
spec.version = $version
|
|
18
|
+
spec.platform = Gem::Platform::RUBY
|
|
19
|
+
spec.summary = $lib
|
|
20
|
+
|
|
21
|
+
spec.files = shiteless[Dir::glob("**/**")]
|
|
22
|
+
spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename(exe)}
|
|
23
|
+
|
|
24
|
+
spec.require_path = "lib"
|
|
25
|
+
|
|
26
|
+
spec.has_rdoc = true #File::exist? "doc"
|
|
27
|
+
# spec.test_suite_file = "test/#{ $lib }.rb" if File::file?("test/#{ $lib }.rb")
|
|
28
|
+
spec.add_dependency 'rest-client'
|
|
29
|
+
spec.add_dependency 'nokogiri'
|
|
30
|
+
spec.add_dependency 'threadify'
|
|
31
|
+
spec.add_dependency 'tagz', '>= 5.0.1'
|
|
32
|
+
|
|
33
|
+
spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
|
|
34
|
+
|
|
35
|
+
spec.rubyforge_project = 'gnip'
|
|
36
|
+
spec.author = "Ara T. Howard"
|
|
37
|
+
spec.email = "ara.t.howard@gmail.com"
|
|
38
|
+
spec.homepage = "http://gnip.com"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
BEGIN{
|
|
43
|
+
Dir.chdir(File.dirname(__FILE__))
|
|
44
|
+
$lib = 'gnip'
|
|
45
|
+
Kernel.load "./lib/#{ $lib }.rb"
|
|
46
|
+
$version = Gnip.version
|
|
47
|
+
}
|
data/gnip-0.4.2.gem
ADDED
|
File without changes
|
data/lib/gnip.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# built-in libs
|
|
2
|
+
#
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require 'time'
|
|
5
|
+
require 'zlib'
|
|
6
|
+
require 'enumerator'
|
|
7
|
+
require 'base64'
|
|
8
|
+
# require 'erb'
|
|
9
|
+
|
|
10
|
+
# gems and third party libs
|
|
11
|
+
#
|
|
12
|
+
begin
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
gem 'tagz', '>= 5.0.1'
|
|
15
|
+
rescue LoadError
|
|
16
|
+
'oh noes!'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
require 'restclient'
|
|
21
|
+
rescue
|
|
22
|
+
abort 'sudo gem install rest-client'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
require 'nokogiri'
|
|
27
|
+
rescue
|
|
28
|
+
abort 'sudo gem install nokogiri #=> depends on libxml + libxslt'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
begin
|
|
32
|
+
require 'tagz'
|
|
33
|
+
rescue
|
|
34
|
+
abort 'sudo gem install tagz'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
begin
|
|
38
|
+
require 'threadify'
|
|
39
|
+
rescue
|
|
40
|
+
abort 'sudo gem install threadify'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# gnip libs
|
|
44
|
+
#
|
|
45
|
+
module Gnip
|
|
46
|
+
Version = '0.4.2'
|
|
47
|
+
|
|
48
|
+
def version
|
|
49
|
+
Gnip::Version
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def libdir(*args)
|
|
53
|
+
@libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
|
|
54
|
+
args.empty? ? @libdir : File.join(@libdir, *args)
|
|
55
|
+
end
|
|
56
|
+
extend self
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
require Gnip.libdir('util')
|
|
60
|
+
require Gnip.libdir('orderedhash')
|
|
61
|
+
# require Gnip.libdir('blankslate')
|
|
62
|
+
require Gnip.libdir('arguments')
|
|
63
|
+
require Gnip.libdir('options')
|
|
64
|
+
require Gnip.libdir('list')
|
|
65
|
+
require Gnip.libdir('config')
|
|
66
|
+
require Gnip.libdir('resource')
|
|
67
|
+
# require Gnip.libdir('template')
|
|
68
|
+
require Gnip.libdir('publisher')
|
|
69
|
+
require Gnip.libdir('filter')
|
|
70
|
+
require Gnip.libdir('activity')
|
|
71
|
+
require Gnip.libdir('api')
|
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
module Gnip
|
|
2
|
+
class Activity
|
|
3
|
+
|
|
4
|
+
def Activity.list_from_xml(xml, &block)
|
|
5
|
+
list = []
|
|
6
|
+
parse_xml(xml) do |activity|
|
|
7
|
+
block ? block.call(activity) : list.push(activity)
|
|
8
|
+
end
|
|
9
|
+
block ? nil : list
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def Activity.from_xml(xml)
|
|
13
|
+
parse_xml(xml){|activity| return activity}
|
|
14
|
+
nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def Activity.parse_xml(xml, &block)
|
|
18
|
+
doc = Nokogiri::XML.parse(xml)
|
|
19
|
+
list = []
|
|
20
|
+
selectors = '*/activities', 'activity'
|
|
21
|
+
selectors.each do |selector|
|
|
22
|
+
search = doc.search(selector)
|
|
23
|
+
next unless search.size > 0
|
|
24
|
+
search.each do |node|
|
|
25
|
+
activity = Activity.from_node(node)
|
|
26
|
+
block ? block.call(activity) : list.push(activity)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
block ? nil : list
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def Activity.from_node(node)
|
|
33
|
+
activity = new
|
|
34
|
+
|
|
35
|
+
if value = node.at('at')
|
|
36
|
+
activity.at = value.content
|
|
37
|
+
end
|
|
38
|
+
if value = node.at('action')
|
|
39
|
+
activity.action = value.content
|
|
40
|
+
end
|
|
41
|
+
if value = node.at('activityID')
|
|
42
|
+
activity.activity_id = value.content
|
|
43
|
+
end
|
|
44
|
+
if value = node.at('URL')
|
|
45
|
+
activity.url = value.content
|
|
46
|
+
end
|
|
47
|
+
if values = node.search('source')
|
|
48
|
+
values.each{|value| activity.sources << value.content}
|
|
49
|
+
end
|
|
50
|
+
if values = node.search('keyword')
|
|
51
|
+
values.each{|value| activity.keywords << value.content}
|
|
52
|
+
end
|
|
53
|
+
if places = node.search('place')
|
|
54
|
+
places.each do |value|
|
|
55
|
+
place = activity.places.build
|
|
56
|
+
%w( point elev floor featuretypetag featurename relationshiptag ).each do |tag|
|
|
57
|
+
tag_value = value.at(tag)
|
|
58
|
+
place.send("#{ tag }=", tag_value.content) if tag_value
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
if values = node.search('actor')
|
|
63
|
+
values.each do |value|
|
|
64
|
+
actor = activity.actors.build
|
|
65
|
+
actor.content = value.content
|
|
66
|
+
actor.meta_url = value['metaURL']
|
|
67
|
+
actor.uid = value['uid']
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
if values = node.search('destinationURL')
|
|
71
|
+
values.each do |value|
|
|
72
|
+
destination_url = activity.destination_urls.build
|
|
73
|
+
destination_url.content = value.content
|
|
74
|
+
destination_url.meta_url = value['metaURL']
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
if values = node.search('tag')
|
|
78
|
+
values.each do |value|
|
|
79
|
+
tag = activity.tags.build
|
|
80
|
+
tag.content = value.content
|
|
81
|
+
tag.meta_url = value['metaURL']
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
if values = node.search('to')
|
|
85
|
+
values.each do |value|
|
|
86
|
+
to = activity.tos.build
|
|
87
|
+
to.content = value.content
|
|
88
|
+
to.meta_url = value['metaURL']
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
if values = node.search('regardingURL')
|
|
92
|
+
values.each do |value|
|
|
93
|
+
regarding_url = activity.regarding_urls.build
|
|
94
|
+
regarding_url.content = value.content
|
|
95
|
+
regarding_url.meta_url = value['metaURL']
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
if payload_node = node.at('payload')
|
|
99
|
+
activity.payload! do |payload|
|
|
100
|
+
if title_node = payload_node.at('title')
|
|
101
|
+
payload.title = title_node.content
|
|
102
|
+
end
|
|
103
|
+
if body_node = payload_node.at('body')
|
|
104
|
+
payload.body = body_node.content
|
|
105
|
+
end
|
|
106
|
+
if raw_node = payload_node.at('raw')
|
|
107
|
+
payload.raw = payload.decode(raw_node.content)
|
|
108
|
+
end
|
|
109
|
+
if media_url_nodes = payload_node.search('mediaURL')
|
|
110
|
+
media_url_nodes.each do |media_url_node|
|
|
111
|
+
media_url = payload.media_urls.build
|
|
112
|
+
media_url.content = media_url_node.content
|
|
113
|
+
media_url.height = media_url_node['height']
|
|
114
|
+
media_url.width = media_url_node['width']
|
|
115
|
+
media_url.duration = media_url_node['duration']
|
|
116
|
+
media_url.mime_type = media_url_node['mimeType']
|
|
117
|
+
media_url.type = media_url_node['type']
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
activity
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def Activity.from_hash(*args)
|
|
127
|
+
args, options = Gnip.args_for(args)
|
|
128
|
+
|
|
129
|
+
activity = new
|
|
130
|
+
|
|
131
|
+
%w(
|
|
132
|
+
at
|
|
133
|
+
action
|
|
134
|
+
activity_id
|
|
135
|
+
url
|
|
136
|
+
sources
|
|
137
|
+
keywords
|
|
138
|
+
places
|
|
139
|
+
actors
|
|
140
|
+
destination_urls
|
|
141
|
+
tags
|
|
142
|
+
tos
|
|
143
|
+
regarding_urls
|
|
144
|
+
payload
|
|
145
|
+
).each do |opt|
|
|
146
|
+
if options.hasopt?(opt)
|
|
147
|
+
activity.send("#{ opt }=", options.getopt(opt))
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
activity
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def Activity.from_yaml(string)
|
|
155
|
+
string = string.read if string.respond_to?(:read)
|
|
156
|
+
to_hash(YAML.load(string))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
Attributes = []
|
|
160
|
+
|
|
161
|
+
Attributes << 'activity_id'
|
|
162
|
+
def activity_id
|
|
163
|
+
@activity_id ||= nil
|
|
164
|
+
end
|
|
165
|
+
def activity_id= value
|
|
166
|
+
@activity_id = value.to_s
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
Attributes << 'at'
|
|
170
|
+
def at
|
|
171
|
+
@at ||= nil
|
|
172
|
+
end
|
|
173
|
+
def at= value
|
|
174
|
+
@at = Time === value ? value : Time.parse(value.to_s).utc #.iso8601(3)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
Attributes << 'action'
|
|
178
|
+
def action
|
|
179
|
+
@action ||= nil
|
|
180
|
+
end
|
|
181
|
+
def action= value
|
|
182
|
+
@action = value.to_s
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
Attributes << 'url'
|
|
186
|
+
def url
|
|
187
|
+
@url ||= nil
|
|
188
|
+
end
|
|
189
|
+
def url= value
|
|
190
|
+
@url = value.to_s
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
Attributes << 'sources'
|
|
194
|
+
def sources
|
|
195
|
+
@sources ||= List.of(String)
|
|
196
|
+
end
|
|
197
|
+
def sources= value
|
|
198
|
+
sources.replace(value)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
Attributes << 'keywords'
|
|
202
|
+
def keywords
|
|
203
|
+
@keywords ||= List.of(String)
|
|
204
|
+
end
|
|
205
|
+
def keywords= value
|
|
206
|
+
keywords.replace(value)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
Attributes << 'places'
|
|
210
|
+
def places
|
|
211
|
+
@places ||= List.of(Place)
|
|
212
|
+
end
|
|
213
|
+
def places= value
|
|
214
|
+
places.replace(value)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
Attributes << 'actors'
|
|
218
|
+
def actors
|
|
219
|
+
@actors ||= List.of(Actor)
|
|
220
|
+
end
|
|
221
|
+
def actors= value
|
|
222
|
+
actors.replace(value)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
Attributes << 'destination_urls'
|
|
226
|
+
def destination_urls
|
|
227
|
+
@destination_urls ||= List.of(DestinationURL)
|
|
228
|
+
end
|
|
229
|
+
def destination_urls= value
|
|
230
|
+
destination_urls.replace(value)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
Attributes << 'tags'
|
|
234
|
+
def tags
|
|
235
|
+
@tags ||= List.of(Tag)
|
|
236
|
+
end
|
|
237
|
+
def tags= value
|
|
238
|
+
tags.replace(value)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
Attributes << 'tos'
|
|
242
|
+
def tos
|
|
243
|
+
@tos ||= List.of(To)
|
|
244
|
+
end
|
|
245
|
+
def tos= value
|
|
246
|
+
tos.replace(value)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
Attributes << 'regarding_urls'
|
|
250
|
+
def regarding_urls
|
|
251
|
+
@regarding_urls ||= List.of(RegardingURL)
|
|
252
|
+
end
|
|
253
|
+
def regarding_urls= value
|
|
254
|
+
regarding_urls.replace(value)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# TODO - extend this pattern to other elements
|
|
258
|
+
#
|
|
259
|
+
Attributes << 'payload'
|
|
260
|
+
def payload(*args, &block)
|
|
261
|
+
return payload!(*args, &block) if block
|
|
262
|
+
@payload ||= nil
|
|
263
|
+
end
|
|
264
|
+
def payload!(*args, &block)
|
|
265
|
+
@payload = Payload.for(*args)
|
|
266
|
+
block ? block.call(@payload) : @payload
|
|
267
|
+
end
|
|
268
|
+
def payload= value
|
|
269
|
+
@payload = Payload.for(value)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def initialize(options = {})
|
|
273
|
+
options = Gnip.options_for(options)
|
|
274
|
+
options.each{|key, value| send("#{ key }=", value)}
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
include Tagz
|
|
278
|
+
def to_xml(*args)
|
|
279
|
+
args, options = Gnip.args_for(args)
|
|
280
|
+
doc = args.shift
|
|
281
|
+
|
|
282
|
+
tagz(doc) {
|
|
283
|
+
activity_{
|
|
284
|
+
at_{ at.utc.iso8601(3) }
|
|
285
|
+
action_{ action.to_s }
|
|
286
|
+
|
|
287
|
+
if activity_id
|
|
288
|
+
activityID_{ activity_id }
|
|
289
|
+
end
|
|
290
|
+
if url
|
|
291
|
+
URL_{ url }
|
|
292
|
+
end
|
|
293
|
+
if sources
|
|
294
|
+
sources.each{|source| source_{ source } }
|
|
295
|
+
end
|
|
296
|
+
if keywords
|
|
297
|
+
keywords.each{|keyword| keyword_{ keyword } }
|
|
298
|
+
end
|
|
299
|
+
if places
|
|
300
|
+
places.each{|place| place.to_xml(tagz)}
|
|
301
|
+
end
|
|
302
|
+
if actors
|
|
303
|
+
actors.each{|actor| actor.to_xml(tagz)}
|
|
304
|
+
end
|
|
305
|
+
if destination_urls
|
|
306
|
+
destination_urls.each{|destination_url| destination_url.to_xml(tagz)}
|
|
307
|
+
end
|
|
308
|
+
if tags
|
|
309
|
+
tags.each{|tag| tag.to_xml(tagz)}
|
|
310
|
+
end
|
|
311
|
+
if tos
|
|
312
|
+
tos.each{|to| to.to_xml(tagz)}
|
|
313
|
+
end
|
|
314
|
+
if regarding_urls
|
|
315
|
+
regarding_urls.each{|regarding_url| regarding_url.to_xml(tagz)}
|
|
316
|
+
end
|
|
317
|
+
if payload
|
|
318
|
+
payload.to_xml(tagz)
|
|
319
|
+
end
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
class Place
|
|
325
|
+
def Place.for(*args, &block)
|
|
326
|
+
arg = args.first if(args.size == 1 and args.first.is_a?(Place))
|
|
327
|
+
new(*args, &block)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def initialize(options = {}, &block)
|
|
331
|
+
options.each{|key, value| send "#{ key }=", value}
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
class Point
|
|
335
|
+
def Point.for(*args, &block)
|
|
336
|
+
new(*args, &block)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
attr_accessor :lat
|
|
340
|
+
attr_accessor :lon
|
|
341
|
+
|
|
342
|
+
def initialize(*args)
|
|
343
|
+
@lat, @lon = Point.parse(*args)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def Point.parse(*args)
|
|
347
|
+
string = args.join(' ')
|
|
348
|
+
coords = string.strip.split(%r/\s+/, 2).map{|coord| Util.number_for(coord)}
|
|
349
|
+
raise ArgumentError, args.inspect unless coords.size == 2
|
|
350
|
+
coords
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
def to_s
|
|
354
|
+
[@lat, @lon].join(' ')
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def format n
|
|
358
|
+
'%03.3f' % n
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
attr :point
|
|
363
|
+
def point= value
|
|
364
|
+
@point = Point.for(value)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
attr :elev
|
|
368
|
+
def elev= value
|
|
369
|
+
@elev = Util.number_for(value)
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
attr :floor
|
|
373
|
+
def floor= value
|
|
374
|
+
@floor = Util.number_for(value).to_i
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
attr :featuretypetag
|
|
378
|
+
def featuretypetag= value
|
|
379
|
+
@featuretypetag = String(value)
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
attr :featurename
|
|
383
|
+
def featurename= value
|
|
384
|
+
@featurename = String(value)
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
attr :relationshiptag
|
|
388
|
+
def relationshiptag= value
|
|
389
|
+
@relationshiptag = String(value)
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def to_yaml(*a, &b)
|
|
393
|
+
oh = OrderedHash.new
|
|
394
|
+
oh['point'] = [point.lat, point.lon] if point
|
|
395
|
+
oh['elev'] = elev
|
|
396
|
+
oh['floor'] = floor
|
|
397
|
+
oh['featuretypetag'] = featuretypetag
|
|
398
|
+
oh['featurename'] = featurename
|
|
399
|
+
oh['relationshiptag'] = relationshiptag
|
|
400
|
+
oh.to_yaml(*a, &b)
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
include Tagz
|
|
404
|
+
def to_xml(*args)
|
|
405
|
+
args, options = Gnip.args_for(args)
|
|
406
|
+
doc = args.shift
|
|
407
|
+
|
|
408
|
+
tagz(doc) {
|
|
409
|
+
place_{
|
|
410
|
+
point_{ point } if point
|
|
411
|
+
elev_{ elev } if elev
|
|
412
|
+
floor_{ floor } if floor
|
|
413
|
+
featuretypetag_{ featuretypetag } if featuretypetag
|
|
414
|
+
featurename_{ featurename } if featurename
|
|
415
|
+
relationshiptag_{ relationshiptag } if relationshiptag
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
class MetaURL
|
|
422
|
+
attr_accessor :content
|
|
423
|
+
attr_accessor :meta_url
|
|
424
|
+
|
|
425
|
+
def MetaURL.for(*args)
|
|
426
|
+
arg = args.flatten.compact.first
|
|
427
|
+
self.class === arg ? arg : new(*args)
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def initialize(*args)
|
|
431
|
+
args, options = Gnip.args_for(args)
|
|
432
|
+
self.content = args.join unless args.empty?
|
|
433
|
+
options.each{|k,v| send "#{ k }=", v}
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
def to_yaml(*a, &b)
|
|
437
|
+
oh = OrderedHash.new
|
|
438
|
+
oh['content'] = content
|
|
439
|
+
oh['meta_url'] = meta_url
|
|
440
|
+
oh.to_yaml(*a, &b)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
include Tagz
|
|
444
|
+
def to_xml(*args)
|
|
445
|
+
args, options = Gnip.args_for(args)
|
|
446
|
+
doc = args.shift
|
|
447
|
+
tagz(doc){ send("#{ xml_tag }_", xml_attributes){ content } }
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def xml_attributes
|
|
451
|
+
attributes = {}
|
|
452
|
+
attributes.update(:metaURL => meta_url) if meta_url
|
|
453
|
+
attributes
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
def xml_tag
|
|
457
|
+
self.class.const_get(:XML_TAG)
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
class Actor < MetaURL
|
|
462
|
+
XML_TAG = 'actor'
|
|
463
|
+
|
|
464
|
+
attr_accessor :uid
|
|
465
|
+
|
|
466
|
+
def to_yaml(*a, &b)
|
|
467
|
+
oh = OrderedHash.new
|
|
468
|
+
oh['content'] = content
|
|
469
|
+
oh['meta_url'] = meta_url
|
|
470
|
+
oh['uid'] = uid
|
|
471
|
+
oh.to_yaml(*a, &b)
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def xml_attributes
|
|
475
|
+
attributes = super
|
|
476
|
+
attributes.update(:uid => uid) if uid
|
|
477
|
+
attributes
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
class Tag < MetaURL
|
|
482
|
+
XML_TAG = 'tag'
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
class To < MetaURL
|
|
486
|
+
XML_TAG = 'to'
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
class DestinationURL < MetaURL
|
|
490
|
+
XML_TAG = 'destinationURL'
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
class RegardingURL < MetaURL
|
|
494
|
+
XML_TAG = 'regardingURL'
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
class Payload
|
|
498
|
+
def Payload.for(*args)
|
|
499
|
+
return args.first if(args.size == 1 and args.first.is_a?(Place))
|
|
500
|
+
new(*args)
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
def initialize(options = {}, &block)
|
|
504
|
+
options.each{|key, value| send "#{ key }=", value}
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
def title
|
|
508
|
+
@title ||= nil
|
|
509
|
+
end
|
|
510
|
+
def title= title
|
|
511
|
+
@title = String(title)
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
def body
|
|
515
|
+
@body ||= nil
|
|
516
|
+
end
|
|
517
|
+
def body= body
|
|
518
|
+
@body = String(body)
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
def media_urls
|
|
522
|
+
@media_urls ||= List.of(MediaURL)
|
|
523
|
+
end
|
|
524
|
+
def media_urls= value
|
|
525
|
+
media_urls.replace value
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
def raw
|
|
529
|
+
@raw ||= nil
|
|
530
|
+
end
|
|
531
|
+
def __raw__
|
|
532
|
+
@raw ||= nil
|
|
533
|
+
end
|
|
534
|
+
def raw= raw
|
|
535
|
+
@raw = raw
|
|
536
|
+
end
|
|
537
|
+
def __raw__= raw
|
|
538
|
+
@raw = raw
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
include Tagz
|
|
542
|
+
def to_xml(*args)
|
|
543
|
+
args, options = Gnip.args_for(args)
|
|
544
|
+
doc = args.shift
|
|
545
|
+
tagz(doc){
|
|
546
|
+
payload_{
|
|
547
|
+
title_{ title } if title
|
|
548
|
+
body_{ normalize(body) } if body
|
|
549
|
+
media_urls.each{|media_url| media_url.to_xml(tagz)} if media_urls
|
|
550
|
+
raw_{ encode(raw) } if raw
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
def encode(data)
|
|
556
|
+
Util.encode(raw)
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def decode(raw)
|
|
560
|
+
Util.decode(raw)
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
def normalize(string)
|
|
564
|
+
Util.normalize!(string)
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
class MediaURL
|
|
568
|
+
attr_accessor :content
|
|
569
|
+
attr_accessor :height
|
|
570
|
+
attr_accessor :width
|
|
571
|
+
attr_accessor :duration
|
|
572
|
+
attr_accessor :mime_type
|
|
573
|
+
attr_accessor :type
|
|
574
|
+
|
|
575
|
+
def initialize(*args)
|
|
576
|
+
args, options = Gnip.args_for(args)
|
|
577
|
+
self.content = args.join
|
|
578
|
+
options.each{|k,v| send "#{ k }=", v}
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
def to_yaml(*a, &b)
|
|
582
|
+
oh = OrderedHash.new
|
|
583
|
+
oh['content'] = content
|
|
584
|
+
oh['height'] = height
|
|
585
|
+
oh['width'] = width
|
|
586
|
+
oh['duration'] = duration
|
|
587
|
+
oh['mime_type'] = mime_type
|
|
588
|
+
oh['type'] = type
|
|
589
|
+
oh.to_yaml(*a, &b)
|
|
590
|
+
end
|
|
591
|
+
|
|
592
|
+
include Tagz
|
|
593
|
+
def to_xml(*args)
|
|
594
|
+
args, options = Gnip.args_for(args)
|
|
595
|
+
doc = args.shift
|
|
596
|
+
tagz(doc){
|
|
597
|
+
options = {}
|
|
598
|
+
options['height'] = height if height
|
|
599
|
+
options['width'] = width if width
|
|
600
|
+
options['duration'] = duration if duration
|
|
601
|
+
options['mimeType'] = mime_type if mime_type
|
|
602
|
+
options['type'] = type if type
|
|
603
|
+
mediaURL_(options){ content }
|
|
604
|
+
}
|
|
605
|
+
end
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
class Stream
|
|
610
|
+
def Stream.from_xml(xml, options = {}, &block)
|
|
611
|
+
doc = Nokogiri::XML.parse(xml)
|
|
612
|
+
selector = 'activityStream'
|
|
613
|
+
node = doc.at(selector)
|
|
614
|
+
Stream.from_node(node)
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
def Stream.from_node(node)
|
|
618
|
+
updated_at = node.at('activitiesAddedAt').content
|
|
619
|
+
buckets = []
|
|
620
|
+
node.search('bucket').each do |bucket|
|
|
621
|
+
buckets << bucket['href']
|
|
622
|
+
end
|
|
623
|
+
Stream.new(:updated_at => updated_at, :buckets => buckets)
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
Attributes = []
|
|
627
|
+
|
|
628
|
+
Attributes << 'updated_at'
|
|
629
|
+
def updated_at
|
|
630
|
+
@updated_at ||= nil
|
|
631
|
+
end
|
|
632
|
+
def updated_at= value
|
|
633
|
+
@updated_at = Time.parse(value.to_s)
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
Attributes << 'buckets'
|
|
637
|
+
def buckets
|
|
638
|
+
@buckets ||= List.of(String)
|
|
639
|
+
end
|
|
640
|
+
def buckets= value
|
|
641
|
+
buckets.replace(value)
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
def initialize(options = {})
|
|
645
|
+
options = Gnip.options_for(options)
|
|
646
|
+
options.each{|key, value| send("#{ key }=", value)}
|
|
647
|
+
end
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
def Activity.stream(options = {})
|
|
651
|
+
options = Gnip.options_for(options)
|
|
652
|
+
scope = options.getopt(:scope, Gnip.scope)
|
|
653
|
+
resource = options.getopt(:resource, Gnip.default.resource)
|
|
654
|
+
style = options.getopt(:style, 'activity')
|
|
655
|
+
publisher = options.getopt(:publisher)
|
|
656
|
+
endpoint = resource.endpoint "#{ scope }/publishers/#{ publisher.name }/#{ style }.xml"
|
|
657
|
+
response = endpoint.get
|
|
658
|
+
xml = response.to_s
|
|
659
|
+
Activity::Stream.from_xml(xml)
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
end
|
|
663
|
+
end
|