gnip-gnip 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +144 -0
- data/Rakefile +221 -0
- data/TODO +72 -0
- data/bin/gnip +651 -0
- data/doc/api.html +1201 -0
- data/gemspec.rb +25 -0
- data/gnip-ruby.gemspec +26 -0
- data/lib/gnip.rb +71 -0
- data/lib/gnip/activity.rb +665 -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 +311 -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 +316 -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/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 +158 -0
data/gemspec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
Gem::Specification::new do |spec|
|
3
|
+
spec.name = "gnip"
|
4
|
+
spec.version = "1.1.1"
|
5
|
+
spec.platform = Gem::Platform::RUBY
|
6
|
+
spec.summary = "gnip"
|
7
|
+
|
8
|
+
spec.files = ["bin", "bin/gnip", "doc", "doc/api.html", "gemspec.rb", "gnip-ruby.gemspec", "lib", "lib/gnip", "lib/gnip/activity.rb", "lib/gnip/api.rb", "lib/gnip/arguments.rb", "lib/gnip/blankslate.rb", "lib/gnip/config.rb", "lib/gnip/filter.rb", "lib/gnip/list.rb", "lib/gnip/options.rb", "lib/gnip/orderedhash.rb", "lib/gnip/publisher.rb", "lib/gnip/resource.rb", "lib/gnip/template.rb", "lib/gnip/util.rb", "lib/gnip.rb", "Rakefile", "README", "sample", "sample/data", "sample/data/activity.yml", "test", "test/auth.rb", "test/config.yml", "test/data", "test/data/activity.xml", "test/data/activity_only_required.xml", "test/data/activity_with_payload.xml", "test/data/activity_with_place.xml", "test/data/activity_with_place_wo_bounds.xml", "test/data/activity_with_unbounded_media_urls.xml", "test/data/activity_without_bounds.xml", "test/helper.rb", "test/integration", "test/integration/auth.rb", "test/integration/publisher.rb", "test/lib", "test/lib/shoulda", "test/lib/shoulda/action_controller", "test/lib/shoulda/action_controller/helpers.rb", "test/lib/shoulda/action_controller/macros.rb", "test/lib/shoulda/action_controller/matchers", "test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb", "test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb", "test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb", "test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb", "test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb", "test/lib/shoulda/action_controller/matchers/route_matcher.rb", "test/lib/shoulda/action_controller/matchers/set_session_matcher.rb", "test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb", "test/lib/shoulda/action_controller/matchers.rb", "test/lib/shoulda/action_controller.rb", "test/lib/shoulda/action_mailer", "test/lib/shoulda/action_mailer/assertions.rb", "test/lib/shoulda/action_mailer.rb", "test/lib/shoulda/action_view", "test/lib/shoulda/action_view/macros.rb", "test/lib/shoulda/action_view.rb", "test/lib/shoulda/active_record", "test/lib/shoulda/active_record/assertions.rb", "test/lib/shoulda/active_record/helpers.rb", "test/lib/shoulda/active_record/macros.rb", "test/lib/shoulda/active_record/matchers", "test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb", "test/lib/shoulda/active_record/matchers/allow_value_matcher.rb", "test/lib/shoulda/active_record/matchers/association_matcher.rb", "test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb", "test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb", "test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb", "test/lib/shoulda/active_record/matchers/have_index_matcher.rb", "test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb", "test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validation_matcher.rb", "test/lib/shoulda/active_record/matchers.rb", "test/lib/shoulda/active_record.rb", "test/lib/shoulda/assertions.rb", "test/lib/shoulda/autoload_macros.rb", "test/lib/shoulda/context.rb", "test/lib/shoulda/helpers.rb", "test/lib/shoulda/macros.rb", "test/lib/shoulda/private_helpers.rb", "test/lib/shoulda/proc_extensions.rb", "test/lib/shoulda/rails.rb", "test/lib/shoulda/rspec.rb", "test/lib/shoulda/tasks", "test/lib/shoulda/tasks/list_tests.rake", "test/lib/shoulda/tasks/yaml_to_shoulda.rake", "test/lib/shoulda/tasks.rb", "test/lib/shoulda/test_unit.rb", "test/lib/shoulda.rb", "test/lib/xmlsimple.rb", "test/loader.rb", "test/unit", "test/unit/activity.rb", "test/unit/util.rb", "TODO"]
|
9
|
+
spec.executables = ["gnip"]
|
10
|
+
|
11
|
+
spec.require_path = "lib"
|
12
|
+
|
13
|
+
spec.has_rdoc = true
|
14
|
+
spec.test_files = nil
|
15
|
+
#spec.add_dependency 'lib', '>= version'
|
16
|
+
#spec.add_dependency 'fattr'
|
17
|
+
|
18
|
+
spec.extensions.push(*["rakefile", "Rakefile"])
|
19
|
+
|
20
|
+
spec.rubyforge_project = 'codeforpeople'
|
21
|
+
spec.author = "Ara T. Howard"
|
22
|
+
spec.email = "ara.t.howard@gmail.com"
|
23
|
+
spec.homepage = "http://github.com/ahoward/gnip/tree/master"
|
24
|
+
end
|
25
|
+
|
data/gnip-ruby.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## gnip-ruby.gemspec
|
2
|
+
#
|
3
|
+
|
4
|
+
Gem::Specification::new do |spec|
|
5
|
+
spec.name = "gnip"
|
6
|
+
spec.version = "1.1.1"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "gnip"
|
9
|
+
|
10
|
+
spec.files = ["bin", "bin/gnip", "doc", "doc/api.html", "gemspec.rb", "gnip-ruby.gemspec", "lib", "lib/gnip", "lib/gnip/activity.rb", "lib/gnip/api.rb", "lib/gnip/arguments.rb", "lib/gnip/blankslate.rb", "lib/gnip/config.rb", "lib/gnip/filter.rb", "lib/gnip/list.rb", "lib/gnip/options.rb", "lib/gnip/orderedhash.rb", "lib/gnip/publisher.rb", "lib/gnip/resource.rb", "lib/gnip/template.rb", "lib/gnip/util.rb", "lib/gnip.rb", "Rakefile", "README", "sample", "sample/data", "sample/data/activity.yml", "test", "test/auth.rb", "test/config.yml", "test/data", "test/data/activity.xml", "test/data/activity_only_required.xml", "test/data/activity_with_payload.xml", "test/data/activity_with_place.xml", "test/data/activity_with_place_wo_bounds.xml", "test/data/activity_with_unbounded_media_urls.xml", "test/data/activity_without_bounds.xml", "test/helper.rb", "test/integration", "test/integration/auth.rb", "test/integration/publisher.rb", "test/lib", "test/lib/shoulda", "test/lib/shoulda/action_controller", "test/lib/shoulda/action_controller/helpers.rb", "test/lib/shoulda/action_controller/macros.rb", "test/lib/shoulda/action_controller/matchers", "test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb", "test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb", "test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb", "test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb", "test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb", "test/lib/shoulda/action_controller/matchers/route_matcher.rb", "test/lib/shoulda/action_controller/matchers/set_session_matcher.rb", "test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb", "test/lib/shoulda/action_controller/matchers.rb", "test/lib/shoulda/action_controller.rb", "test/lib/shoulda/action_mailer", "test/lib/shoulda/action_mailer/assertions.rb", "test/lib/shoulda/action_mailer.rb", "test/lib/shoulda/action_view", "test/lib/shoulda/action_view/macros.rb", "test/lib/shoulda/action_view.rb", "test/lib/shoulda/active_record", "test/lib/shoulda/active_record/assertions.rb", "test/lib/shoulda/active_record/helpers.rb", "test/lib/shoulda/active_record/macros.rb", "test/lib/shoulda/active_record/matchers", "test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb", "test/lib/shoulda/active_record/matchers/allow_value_matcher.rb", "test/lib/shoulda/active_record/matchers/association_matcher.rb", "test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb", "test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb", "test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb", "test/lib/shoulda/active_record/matchers/have_index_matcher.rb", "test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb", "test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb", "test/lib/shoulda/active_record/matchers/validation_matcher.rb", "test/lib/shoulda/active_record/matchers.rb", "test/lib/shoulda/active_record.rb", "test/lib/shoulda/assertions.rb", "test/lib/shoulda/autoload_macros.rb", "test/lib/shoulda/context.rb", "test/lib/shoulda/helpers.rb", "test/lib/shoulda/macros.rb", "test/lib/shoulda/private_helpers.rb", "test/lib/shoulda/proc_extensions.rb", "test/lib/shoulda/rails.rb", "test/lib/shoulda/rspec.rb", "test/lib/shoulda/tasks", "test/lib/shoulda/tasks/list_tests.rake", "test/lib/shoulda/tasks/yaml_to_shoulda.rake", "test/lib/shoulda/tasks.rb", "test/lib/shoulda/test_unit.rb", "test/lib/shoulda.rb", "test/lib/xmlsimple.rb", "test/loader.rb", "test/unit", "test/unit/activity.rb", "test/unit/util.rb", "TODO"]
|
11
|
+
spec.executables = ["gnip"]
|
12
|
+
|
13
|
+
spec.require_path = "lib"
|
14
|
+
|
15
|
+
spec.has_rdoc = true
|
16
|
+
spec.test_files = nil
|
17
|
+
#spec.add_dependency 'lib', '>= version'
|
18
|
+
#spec.add_dependency 'fattr'
|
19
|
+
|
20
|
+
spec.extensions.push(*[])
|
21
|
+
|
22
|
+
spec.rubyforge_project = "codeforpeople"
|
23
|
+
spec.author = "Ara T. Howard"
|
24
|
+
spec.email = "ara.t.howard@gmail.com"
|
25
|
+
spec.homepage = "http://github.com/ahoward/gnip/tree/master"
|
26
|
+
end
|
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 = '1.1.1'
|
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,665 @@
|
|
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
|
+
attr_accessor :gnip_resource_uri
|
273
|
+
|
274
|
+
def initialize(options = {})
|
275
|
+
options = Gnip.options_for(options)
|
276
|
+
options.each{|key, value| send("#{ key }=", value)}
|
277
|
+
end
|
278
|
+
|
279
|
+
include Tagz
|
280
|
+
def to_xml(*args)
|
281
|
+
args, options = Gnip.args_for(args)
|
282
|
+
doc = args.shift
|
283
|
+
|
284
|
+
tagz(doc) {
|
285
|
+
activity_{
|
286
|
+
at_{ at.utc.iso8601(3) }
|
287
|
+
action_{ action.to_s }
|
288
|
+
|
289
|
+
if activity_id
|
290
|
+
activityID_{ activity_id }
|
291
|
+
end
|
292
|
+
if url
|
293
|
+
URL_{ url }
|
294
|
+
end
|
295
|
+
if sources
|
296
|
+
sources.each{|source| source_{ source } }
|
297
|
+
end
|
298
|
+
if keywords
|
299
|
+
keywords.each{|keyword| keyword_{ keyword } }
|
300
|
+
end
|
301
|
+
if places
|
302
|
+
places.each{|place| place.to_xml(tagz)}
|
303
|
+
end
|
304
|
+
if actors
|
305
|
+
actors.each{|actor| actor.to_xml(tagz)}
|
306
|
+
end
|
307
|
+
if destination_urls
|
308
|
+
destination_urls.each{|destination_url| destination_url.to_xml(tagz)}
|
309
|
+
end
|
310
|
+
if tags
|
311
|
+
tags.each{|tag| tag.to_xml(tagz)}
|
312
|
+
end
|
313
|
+
if tos
|
314
|
+
tos.each{|to| to.to_xml(tagz)}
|
315
|
+
end
|
316
|
+
if regarding_urls
|
317
|
+
regarding_urls.each{|regarding_url| regarding_url.to_xml(tagz)}
|
318
|
+
end
|
319
|
+
if payload
|
320
|
+
payload.to_xml(tagz)
|
321
|
+
end
|
322
|
+
}
|
323
|
+
}
|
324
|
+
end
|
325
|
+
|
326
|
+
class Place
|
327
|
+
def Place.for(*args, &block)
|
328
|
+
arg = args.first if(args.size == 1 and args.first.is_a?(Place))
|
329
|
+
new(*args, &block)
|
330
|
+
end
|
331
|
+
|
332
|
+
def initialize(options = {}, &block)
|
333
|
+
options.each{|key, value| send "#{ key }=", value}
|
334
|
+
end
|
335
|
+
|
336
|
+
class Point
|
337
|
+
def Point.for(*args, &block)
|
338
|
+
new(*args, &block)
|
339
|
+
end
|
340
|
+
|
341
|
+
attr_accessor :lat
|
342
|
+
attr_accessor :lon
|
343
|
+
|
344
|
+
def initialize(*args)
|
345
|
+
@lat, @lon = Point.parse(*args)
|
346
|
+
end
|
347
|
+
|
348
|
+
def Point.parse(*args)
|
349
|
+
string = args.join(' ')
|
350
|
+
coords = string.strip.split(%r/\s+/, 2).map{|coord| Util.number_for(coord)}
|
351
|
+
raise ArgumentError, args.inspect unless coords.size == 2
|
352
|
+
coords
|
353
|
+
end
|
354
|
+
|
355
|
+
def to_s
|
356
|
+
[@lat, @lon].join(' ')
|
357
|
+
end
|
358
|
+
|
359
|
+
def format n
|
360
|
+
'%03.3f' % n
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
attr :point
|
365
|
+
def point= value
|
366
|
+
@point = Point.for(value)
|
367
|
+
end
|
368
|
+
|
369
|
+
attr :elev
|
370
|
+
def elev= value
|
371
|
+
@elev = Util.number_for(value)
|
372
|
+
end
|
373
|
+
|
374
|
+
attr :floor
|
375
|
+
def floor= value
|
376
|
+
@floor = Util.number_for(value).to_i
|
377
|
+
end
|
378
|
+
|
379
|
+
attr :featuretypetag
|
380
|
+
def featuretypetag= value
|
381
|
+
@featuretypetag = String(value)
|
382
|
+
end
|
383
|
+
|
384
|
+
attr :featurename
|
385
|
+
def featurename= value
|
386
|
+
@featurename = String(value)
|
387
|
+
end
|
388
|
+
|
389
|
+
attr :relationshiptag
|
390
|
+
def relationshiptag= value
|
391
|
+
@relationshiptag = String(value)
|
392
|
+
end
|
393
|
+
|
394
|
+
def to_yaml(*a, &b)
|
395
|
+
oh = OrderedHash.new
|
396
|
+
oh['point'] = [point.lat, point.lon] if point
|
397
|
+
oh['elev'] = elev
|
398
|
+
oh['floor'] = floor
|
399
|
+
oh['featuretypetag'] = featuretypetag
|
400
|
+
oh['featurename'] = featurename
|
401
|
+
oh['relationshiptag'] = relationshiptag
|
402
|
+
oh.to_yaml(*a, &b)
|
403
|
+
end
|
404
|
+
|
405
|
+
include Tagz
|
406
|
+
def to_xml(*args)
|
407
|
+
args, options = Gnip.args_for(args)
|
408
|
+
doc = args.shift
|
409
|
+
|
410
|
+
tagz(doc) {
|
411
|
+
place_{
|
412
|
+
point_{ point } if point
|
413
|
+
elev_{ elev } if elev
|
414
|
+
floor_{ floor } if floor
|
415
|
+
featuretypetag_{ featuretypetag } if featuretypetag
|
416
|
+
featurename_{ featurename } if featurename
|
417
|
+
relationshiptag_{ relationshiptag } if relationshiptag
|
418
|
+
}
|
419
|
+
}
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
class MetaURL
|
424
|
+
attr_accessor :content
|
425
|
+
attr_accessor :meta_url
|
426
|
+
|
427
|
+
def MetaURL.for(*args)
|
428
|
+
arg = args.flatten.compact.first
|
429
|
+
self.class === arg ? arg : new(*args)
|
430
|
+
end
|
431
|
+
|
432
|
+
def initialize(*args)
|
433
|
+
args, options = Gnip.args_for(args)
|
434
|
+
self.content = args.join unless args.empty?
|
435
|
+
options.each{|k,v| send "#{ k }=", v}
|
436
|
+
end
|
437
|
+
|
438
|
+
def to_yaml(*a, &b)
|
439
|
+
oh = OrderedHash.new
|
440
|
+
oh['content'] = content
|
441
|
+
oh['meta_url'] = meta_url
|
442
|
+
oh.to_yaml(*a, &b)
|
443
|
+
end
|
444
|
+
|
445
|
+
include Tagz
|
446
|
+
def to_xml(*args)
|
447
|
+
args, options = Gnip.args_for(args)
|
448
|
+
doc = args.shift
|
449
|
+
tagz(doc){ send("#{ xml_tag }_", xml_attributes){ content } }
|
450
|
+
end
|
451
|
+
|
452
|
+
def xml_attributes
|
453
|
+
attributes = {}
|
454
|
+
attributes.update(:metaURL => meta_url) if meta_url
|
455
|
+
attributes
|
456
|
+
end
|
457
|
+
|
458
|
+
def xml_tag
|
459
|
+
self.class.const_get(:XML_TAG)
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
class Actor < MetaURL
|
464
|
+
XML_TAG = 'actor'
|
465
|
+
|
466
|
+
attr_accessor :uid
|
467
|
+
|
468
|
+
def to_yaml(*a, &b)
|
469
|
+
oh = OrderedHash.new
|
470
|
+
oh['content'] = content
|
471
|
+
oh['meta_url'] = meta_url
|
472
|
+
oh['uid'] = uid
|
473
|
+
oh.to_yaml(*a, &b)
|
474
|
+
end
|
475
|
+
|
476
|
+
def xml_attributes
|
477
|
+
attributes = super
|
478
|
+
attributes.update(:uid => uid) if uid
|
479
|
+
attributes
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
class Tag < MetaURL
|
484
|
+
XML_TAG = 'tag'
|
485
|
+
end
|
486
|
+
|
487
|
+
class To < MetaURL
|
488
|
+
XML_TAG = 'to'
|
489
|
+
end
|
490
|
+
|
491
|
+
class DestinationURL < MetaURL
|
492
|
+
XML_TAG = 'destinationURL'
|
493
|
+
end
|
494
|
+
|
495
|
+
class RegardingURL < MetaURL
|
496
|
+
XML_TAG = 'regardingURL'
|
497
|
+
end
|
498
|
+
|
499
|
+
class Payload
|
500
|
+
def Payload.for(*args)
|
501
|
+
return args.first if(args.size == 1 and args.first.is_a?(Place))
|
502
|
+
new(*args)
|
503
|
+
end
|
504
|
+
|
505
|
+
def initialize(options = {}, &block)
|
506
|
+
options.each{|key, value| send "#{ key }=", value}
|
507
|
+
end
|
508
|
+
|
509
|
+
def title
|
510
|
+
@title ||= nil
|
511
|
+
end
|
512
|
+
def title= title
|
513
|
+
@title = String(title)
|
514
|
+
end
|
515
|
+
|
516
|
+
def body
|
517
|
+
@body ||= nil
|
518
|
+
end
|
519
|
+
def body= body
|
520
|
+
@body = String(body)
|
521
|
+
end
|
522
|
+
|
523
|
+
def media_urls
|
524
|
+
@media_urls ||= List.of(MediaURL)
|
525
|
+
end
|
526
|
+
def media_urls= value
|
527
|
+
media_urls.replace value
|
528
|
+
end
|
529
|
+
|
530
|
+
def raw
|
531
|
+
@raw ||= nil
|
532
|
+
end
|
533
|
+
def __raw__
|
534
|
+
@raw ||= nil
|
535
|
+
end
|
536
|
+
def raw= raw
|
537
|
+
@raw = raw
|
538
|
+
end
|
539
|
+
def __raw__= raw
|
540
|
+
@raw = raw
|
541
|
+
end
|
542
|
+
|
543
|
+
include Tagz
|
544
|
+
def to_xml(*args)
|
545
|
+
args, options = Gnip.args_for(args)
|
546
|
+
doc = args.shift
|
547
|
+
tagz(doc){
|
548
|
+
payload_{
|
549
|
+
title_{ title } if title
|
550
|
+
body_{ normalize(body) } if body
|
551
|
+
media_urls.each{|media_url| media_url.to_xml(tagz)} if media_urls
|
552
|
+
raw_{ encode(raw) } if raw
|
553
|
+
}
|
554
|
+
}
|
555
|
+
end
|
556
|
+
|
557
|
+
def encode(data)
|
558
|
+
Util.encode(raw)
|
559
|
+
end
|
560
|
+
|
561
|
+
def decode(raw)
|
562
|
+
Util.decode(raw)
|
563
|
+
end
|
564
|
+
|
565
|
+
def normalize(string)
|
566
|
+
Util.normalize!(string)
|
567
|
+
end
|
568
|
+
|
569
|
+
class MediaURL
|
570
|
+
attr_accessor :content
|
571
|
+
attr_accessor :height
|
572
|
+
attr_accessor :width
|
573
|
+
attr_accessor :duration
|
574
|
+
attr_accessor :mime_type
|
575
|
+
attr_accessor :type
|
576
|
+
|
577
|
+
def initialize(*args)
|
578
|
+
args, options = Gnip.args_for(args)
|
579
|
+
self.content = args.join
|
580
|
+
options.each{|k,v| send "#{ k }=", v}
|
581
|
+
end
|
582
|
+
|
583
|
+
def to_yaml(*a, &b)
|
584
|
+
oh = OrderedHash.new
|
585
|
+
oh['content'] = content
|
586
|
+
oh['height'] = height
|
587
|
+
oh['width'] = width
|
588
|
+
oh['duration'] = duration
|
589
|
+
oh['mime_type'] = mime_type
|
590
|
+
oh['type'] = type
|
591
|
+
oh.to_yaml(*a, &b)
|
592
|
+
end
|
593
|
+
|
594
|
+
include Tagz
|
595
|
+
def to_xml(*args)
|
596
|
+
args, options = Gnip.args_for(args)
|
597
|
+
doc = args.shift
|
598
|
+
tagz(doc){
|
599
|
+
options = {}
|
600
|
+
options['height'] = height if height
|
601
|
+
options['width'] = width if width
|
602
|
+
options['duration'] = duration if duration
|
603
|
+
options['mimeType'] = mime_type if mime_type
|
604
|
+
options['type'] = type if type
|
605
|
+
mediaURL_(options){ content }
|
606
|
+
}
|
607
|
+
end
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
class Stream
|
612
|
+
def Stream.from_xml(xml, options = {}, &block)
|
613
|
+
doc = Nokogiri::XML.parse(xml)
|
614
|
+
selector = 'activityStream'
|
615
|
+
node = doc.at(selector)
|
616
|
+
Stream.from_node(node)
|
617
|
+
end
|
618
|
+
|
619
|
+
def Stream.from_node(node)
|
620
|
+
updated_at = node.at('activitiesAddedAt').content
|
621
|
+
buckets = []
|
622
|
+
node.search('bucket').each do |bucket|
|
623
|
+
buckets << bucket['href']
|
624
|
+
end
|
625
|
+
Stream.new(:updated_at => updated_at, :buckets => buckets)
|
626
|
+
end
|
627
|
+
|
628
|
+
Attributes = []
|
629
|
+
|
630
|
+
Attributes << 'updated_at'
|
631
|
+
def updated_at
|
632
|
+
@updated_at ||= nil
|
633
|
+
end
|
634
|
+
def updated_at= value
|
635
|
+
@updated_at = Time.parse(value.to_s)
|
636
|
+
end
|
637
|
+
|
638
|
+
Attributes << 'buckets'
|
639
|
+
def buckets
|
640
|
+
@buckets ||= List.of(String)
|
641
|
+
end
|
642
|
+
def buckets= value
|
643
|
+
buckets.replace(value)
|
644
|
+
end
|
645
|
+
|
646
|
+
def initialize(options = {})
|
647
|
+
options = Gnip.options_for(options)
|
648
|
+
options.each{|key, value| send("#{ key }=", value)}
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
def Activity.stream(options = {})
|
653
|
+
options = Gnip.options_for(options)
|
654
|
+
scope = options.getopt(:scope, Gnip.scope)
|
655
|
+
resource = options.getopt(:resource, Gnip.default.resource)
|
656
|
+
style = options.getopt(:style, 'activity')
|
657
|
+
publisher = options.getopt(:publisher)
|
658
|
+
endpoint = resource.endpoint "#{ scope }/publishers/#{ publisher.name }/#{ style }.xml"
|
659
|
+
response = endpoint.get
|
660
|
+
xml = response.to_s
|
661
|
+
Activity::Stream.from_xml(xml)
|
662
|
+
end
|
663
|
+
|
664
|
+
end
|
665
|
+
end
|