nelumba 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +6 -0
  2. data/.travis.yml +9 -0
  3. data/Gemfile +20 -0
  4. data/README.md +242 -0
  5. data/Rakefile +7 -0
  6. data/assets/lotus_logo_purple.png +0 -0
  7. data/assets/lotus_logo_purple.svg +262 -0
  8. data/lib/nelumba.rb +47 -0
  9. data/lib/nelumba/activity.rb +250 -0
  10. data/lib/nelumba/application.rb +11 -0
  11. data/lib/nelumba/article.rb +11 -0
  12. data/lib/nelumba/atom/account.rb +50 -0
  13. data/lib/nelumba/atom/address.rb +56 -0
  14. data/lib/nelumba/atom/author.rb +176 -0
  15. data/lib/nelumba/atom/category.rb +41 -0
  16. data/lib/nelumba/atom/comment.rb +96 -0
  17. data/lib/nelumba/atom/entry.rb +216 -0
  18. data/lib/nelumba/atom/feed.rb +198 -0
  19. data/lib/nelumba/atom/generator.rb +40 -0
  20. data/lib/nelumba/atom/link.rb +79 -0
  21. data/lib/nelumba/atom/name.rb +57 -0
  22. data/lib/nelumba/atom/organization.rb +62 -0
  23. data/lib/nelumba/atom/person.rb +179 -0
  24. data/lib/nelumba/atom/portable_contacts.rb +117 -0
  25. data/lib/nelumba/atom/source.rb +179 -0
  26. data/lib/nelumba/atom/thread.rb +60 -0
  27. data/lib/nelumba/audio.rb +39 -0
  28. data/lib/nelumba/badge.rb +11 -0
  29. data/lib/nelumba/binary.rb +52 -0
  30. data/lib/nelumba/bookmark.rb +30 -0
  31. data/lib/nelumba/category.rb +49 -0
  32. data/lib/nelumba/collection.rb +34 -0
  33. data/lib/nelumba/comment.rb +47 -0
  34. data/lib/nelumba/crypto.rb +144 -0
  35. data/lib/nelumba/device.rb +11 -0
  36. data/lib/nelumba/discover.rb +362 -0
  37. data/lib/nelumba/event.rb +57 -0
  38. data/lib/nelumba/feed.rb +173 -0
  39. data/lib/nelumba/file.rb +43 -0
  40. data/lib/nelumba/generator.rb +53 -0
  41. data/lib/nelumba/group.rb +11 -0
  42. data/lib/nelumba/identity.rb +63 -0
  43. data/lib/nelumba/image.rb +30 -0
  44. data/lib/nelumba/link.rb +56 -0
  45. data/lib/nelumba/note.rb +34 -0
  46. data/lib/nelumba/notification.rb +229 -0
  47. data/lib/nelumba/object.rb +251 -0
  48. data/lib/nelumba/person.rb +306 -0
  49. data/lib/nelumba/place.rb +34 -0
  50. data/lib/nelumba/product.rb +30 -0
  51. data/lib/nelumba/publisher.rb +44 -0
  52. data/lib/nelumba/question.rb +30 -0
  53. data/lib/nelumba/review.rb +30 -0
  54. data/lib/nelumba/service.rb +11 -0
  55. data/lib/nelumba/subscription.rb +117 -0
  56. data/lib/nelumba/version.rb +3 -0
  57. data/lib/nelumba/video.rb +43 -0
  58. data/nelumba.gemspec +28 -0
  59. data/spec/activity_spec.rb +116 -0
  60. data/spec/application_spec.rb +136 -0
  61. data/spec/article_spec.rb +136 -0
  62. data/spec/atom/comment_spec.rb +455 -0
  63. data/spec/atom/feed_spec.rb +684 -0
  64. data/spec/audio_spec.rb +164 -0
  65. data/spec/badge_spec.rb +136 -0
  66. data/spec/binary_spec.rb +218 -0
  67. data/spec/bookmark.rb +150 -0
  68. data/spec/collection_spec.rb +152 -0
  69. data/spec/comment_spec.rb +128 -0
  70. data/spec/crypto_spec.rb +126 -0
  71. data/spec/device_spec.rb +136 -0
  72. data/spec/event_spec.rb +239 -0
  73. data/spec/feed_spec.rb +252 -0
  74. data/spec/file_spec.rb +190 -0
  75. data/spec/group_spec.rb +136 -0
  76. data/spec/helper.rb +10 -0
  77. data/spec/identity_spec.rb +67 -0
  78. data/spec/image_spec.rb +150 -0
  79. data/spec/link_spec.rb +30 -0
  80. data/spec/note_spec.rb +163 -0
  81. data/spec/notification_spec.rb +89 -0
  82. data/spec/person_spec.rb +244 -0
  83. data/spec/place_spec.rb +162 -0
  84. data/spec/product_spec.rb +150 -0
  85. data/spec/question_spec.rb +156 -0
  86. data/spec/review_spec.rb +149 -0
  87. data/spec/service_spec.rb +136 -0
  88. data/spec/video_spec.rb +164 -0
  89. data/test/example_feed.atom +393 -0
  90. data/test/example_feed_empty_author.atom +336 -0
  91. data/test/example_feed_false_connected.atom +359 -0
  92. data/test/example_feed_link_without_href.atom +134 -0
  93. data/test/example_page.html +4 -0
  94. data/test/mime_type_bug_feed.atom +874 -0
  95. metadata +288 -0
@@ -0,0 +1,57 @@
1
+ module Nelumba
2
+ class Event
3
+ include Nelumba::Object
4
+
5
+ attr_reader :attending
6
+ attr_reader :maybe_attending
7
+ attr_reader :not_attending
8
+
9
+ attr_reader :start_time
10
+ attr_reader :end_time
11
+
12
+ attr_reader :location
13
+
14
+ def initialize(options = {}, &blk)
15
+ init(options, &blk)
16
+ end
17
+
18
+ def init(options = {}, &blk)
19
+ super options
20
+
21
+ @attending = options[:attending] || []
22
+ @maybe_attending = options[:maybe_attending] || []
23
+ @not_attending = options[:not_attending] || []
24
+ @start_time = options[:start_time]
25
+ @end_time = options[:end_time]
26
+ @location = options[:location]
27
+ end
28
+
29
+ def to_hash
30
+ {
31
+ :attending => @attending.dup,
32
+ :maybe_attending => @maybe_attending.dup,
33
+ :not_attending => @not_attending.dup,
34
+
35
+ :start_time => @start_time,
36
+ :end_time => @end_time,
37
+
38
+ :location => @location
39
+ }.merge(super)
40
+ end
41
+
42
+ def to_json_hash
43
+ {
44
+ :objectType => "event",
45
+
46
+ :attending => @attending.dup,
47
+ :maybeAttending => @maybe_attending.dup,
48
+ :notAttending => @not_attending.dup,
49
+
50
+ :startTime => (@start_time && @start_time.to_date.rfc3339 + 'Z'),
51
+ :endTime => (@end_time && @end_time.to_date.rfc3339 + 'Z'),
52
+
53
+ :location => @location
54
+ }.merge(super)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,173 @@
1
+ module Nelumba
2
+ # This class represents a Nelumba::Feed object.
3
+ class Feed < Nelumba::Collection
4
+ require 'open-uri'
5
+ require 'date'
6
+
7
+ # Holds the list of categories for this feed as Nelumba::Category.
8
+ attr_reader :categories
9
+
10
+ # Holds human-readable information about the content rights of the entries
11
+ # in the feed without an explicit rights field of their own. SHOULD NOT be
12
+ # machine interpreted.
13
+ attr_reader :rights
14
+
15
+ # Holds the title for this feed.
16
+ attr_reader :title
17
+
18
+ # Holds the content-type for the title.
19
+ attr_reader :title_type
20
+
21
+ # Holds the subtitle for this feed.
22
+ attr_reader :subtitle
23
+
24
+ # Holds the content-type for the subtitle.
25
+ attr_reader :subtitle_type
26
+
27
+ # Holds the URL for the icon representing this feed.
28
+ attr_reader :icon
29
+
30
+ # Holds the URL for the logo representing this feed.
31
+ attr_reader :logo
32
+
33
+ # Holds the generator for this content as an Nelumba::Generator.
34
+ attr_reader :generator
35
+
36
+ # Holds the list of contributors, if any, that are involved in this feed
37
+ # as Nelumba::Person.
38
+ attr_reader :contributors
39
+
40
+ # Holds the list of authors as Nelumba::Person responsible for this feed.
41
+ attr_reader :authors
42
+
43
+ # Holds the list of hubs that are available to manage subscriptions to this
44
+ # feed.
45
+ attr_reader :hubs
46
+
47
+ # Holds the salmon url that handles notifications for this feed.
48
+ attr_reader :salmon_url
49
+
50
+ # Holds links to other resources as an array of Nelumba::Link
51
+ attr_reader :links
52
+
53
+ # Creates a new representation of a feed.
54
+ #
55
+ # options:
56
+ # uid => The unique identifier for this feed.
57
+ # url => The url that represents this feed.
58
+ # title => The title for this feed. Defaults: "Untitled"
59
+ # title_type => The content type for the title.
60
+ # subtitle => The subtitle for this feed.
61
+ # subtitle_type => The content type for the subtitle.
62
+ # authors => The list of Nelumba::Person's for this feed.
63
+ # Defaults: []
64
+ # contributors => The list of Nelumba::Person's that contributed to this
65
+ # feed. Defaults: []
66
+ # items => The list of Nelumba::Activity's for this feed.
67
+ # Defaults: []
68
+ # icon => The url of the icon that represents this feed. It
69
+ # should have an aspect ratio of 1 horizontal to 1
70
+ # vertical and optimized for presentation at a
71
+ # small size.
72
+ # logo => The url of the logo that represents this feed. It
73
+ # should have an aspect ratio of 2 horizontal to 1
74
+ # vertical.
75
+ # categories => An array of Nelumba::Category's that describe how to
76
+ # categorize and describe the content of the feed.
77
+ # Defaults: []
78
+ # rights => A String depicting the rights of items without
79
+ # explicit rights of their own. SHOULD NOT be machine
80
+ # interpreted.
81
+ # updated => The DateTime representing when this feed was last
82
+ # modified.
83
+ # published => The DateTime representing when this feed was originally
84
+ # published.
85
+ # salmon_url => The url of the salmon endpoint, if one exists, for this
86
+ # feed.
87
+ # links => An array of Nelumba::Link that adds relations to other
88
+ # resources.
89
+ # generator => A Nelumba::Generator representing the agent
90
+ # responsible for generating this feed.
91
+ #
92
+ # Usage:
93
+ #
94
+ # author = Nelumba::Person.new(:name => "Kelly")
95
+ #
96
+ # feed = Nelumba::Feed.new(:title => "My Feed",
97
+ # :uid => "1",
98
+ # :url => "http://example.com/feeds/1",
99
+ # :authors => [author])
100
+ def initialize(options = {}, &blk)
101
+ init(options, &blk)
102
+ end
103
+
104
+ def init(options = {})
105
+ super options
106
+
107
+ @icon = options[:icon]
108
+ @logo = options[:logo]
109
+ @rights = options[:rights]
110
+ @title = options[:title] || "Untitled"
111
+ @title_type = options[:title_type]
112
+ @subtitle = options[:subtitle]
113
+ @subtitle_type = options[:subtitle_type]
114
+ @authors = options[:authors] || []
115
+ @categories = options[:categories] || []
116
+ @contributors = options[:contributors] || []
117
+ @salmon_url = options[:salmon_url]
118
+ @hubs = options[:hubs] || []
119
+ @generator = options[:generator]
120
+ end
121
+
122
+ # Yields a Nelumba::Link to this feed.
123
+ #
124
+ # options: Can override Nelumba::Link properties, such as rel.
125
+ #
126
+ # Usage:
127
+ #
128
+ # feed = Nelumba::Feed.new(:title => "Foo", :url => "http://example.com")
129
+ # feed.to_link(:rel => "alternate", :title => "Foo's Feed")
130
+ #
131
+ # Generates a link with:
132
+ # <Nelumba::Link rel="alternate" title="Foo's Feed" url="http://example.com">
133
+ def to_link(options = {})
134
+ options = { :title => self.title,
135
+ :href => self.url }.merge(options)
136
+
137
+ Nelumba::Link.new(options)
138
+ end
139
+
140
+ # Returns a hash of the properties of the feed.
141
+ def to_hash
142
+ {
143
+ :hubs => (self.hubs || []).dup,
144
+ :icon => self.icon,
145
+ :logo => self.logo,
146
+ :rights => self.rights,
147
+ :title => self.title,
148
+ :title_type => self.title_type,
149
+ :subtitle => self.subtitle,
150
+ :subtitle_type => self.subtitle_type,
151
+ :authors => (self.authors || []).dup,
152
+ :categories => (self.categories || []).dup,
153
+ :contributors => (self.contributors || []).dup,
154
+ :updated => self.updated,
155
+ :salmon_url => self.salmon_url,
156
+ :published => self.published,
157
+ :generator => self.generator
158
+ }.merge(super)
159
+ end
160
+
161
+ def to_json_hash
162
+ {
163
+ }.merge(super)
164
+ end
165
+
166
+ # Returns a string containing an Atom representation of the feed.
167
+ def to_atom
168
+ require 'nelumba/atom/feed'
169
+
170
+ Nelumba::Atom::Feed.from_canonical(self).to_xml
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,43 @@
1
+ module Nelumba
2
+ class File
3
+ include Nelumba::Object
4
+
5
+ attr_reader :file_url
6
+ attr_reader :mime_type
7
+
8
+ attr_reader :length
9
+ attr_reader :md5
10
+
11
+ def initialize(options = {}, &blk)
12
+ init(options, &blk)
13
+ end
14
+
15
+ def init(options = {}, &blk)
16
+ super options
17
+
18
+ @md5 = options[:md5]
19
+ @file_url = options[:file_url]
20
+ @mime_type = options[:mime_type]
21
+ @length = options[:length]
22
+ end
23
+
24
+ def to_hash
25
+ {
26
+ :md5 => @md5,
27
+ :file_url => @file_url,
28
+ :mime_type => @mime_type,
29
+ :length => @length
30
+ }.merge(super)
31
+ end
32
+
33
+ def to_json_hash
34
+ {
35
+ :objectType => "file",
36
+ :md5 => @md5,
37
+ :fileUrl => @file_url,
38
+ :mimeType => @mime_type,
39
+ :length => @length
40
+ }.merge(super)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ module Nelumba
2
+ # The generator element identifies the agent used to generate the feed.
3
+ class Generator
4
+ # Holds the base URI for relative URIs contained in uri.
5
+ attr_reader :base
6
+
7
+ # Holds the language of the name, when it exists. The language
8
+ # should be specified as RFC 3066 as either 2 or 3 letter codes.
9
+ # For example: 'en' for English or more specifically 'en-us'
10
+ attr_reader :lang
11
+
12
+ # Holds the optional uri that SHOULD produce a representation that is
13
+ # relevant to the agent.
14
+ attr_reader :uri
15
+
16
+ # Holds the optional string identifying the version of the generating
17
+ # agent.
18
+ attr_reader :version
19
+
20
+ # Holds the string that provides a human-readable name that identifies
21
+ # the generating agent. The content of this field is language sensitive.
22
+ attr_reader :name
23
+
24
+ # Creates a representation of a generator.
25
+ #
26
+ # options:
27
+ # :base => Optional base URI for use with a relative URI in uri.
28
+ # :lang => Optional string identifying the language of the name field.
29
+ # :uri => Optional string identifying the URL that SHOULD produce
30
+ # a representation that is relevant to the agent.
31
+ # :version => Optional string indicating the version of the generating
32
+ # agent.
33
+ # :name => Optional name of the agent.
34
+ def initialize(options = {})
35
+ @base = options[:base]
36
+ @lang = options[:lang]
37
+ @uri = options[:uri]
38
+ @version = options[:version]
39
+ @name = options[:name]
40
+ end
41
+
42
+ # Yields a hash that represents the generator.
43
+ def to_hash
44
+ {
45
+ :base => self.base,
46
+ :lang => self.lang,
47
+ :version => self.version,
48
+ :uri => self.uri,
49
+ :name => self.name
50
+ }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ module Nelumba
2
+ class Group
3
+ include Nelumba::Object
4
+
5
+ def to_json_hash
6
+ {
7
+ :objectType => "group"
8
+ }.merge(super)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ module Nelumba
2
+ # Holds information about an Identity. This is more specific to identifying
3
+ # an Person than that structure. It is generally hosted in one place and
4
+ # not replicated. It holds identifying information that allow you to
5
+ # ensure verification of communication with the author.
6
+ class Identity
7
+ # Holds the public key for this identity.
8
+ attr_reader :public_key
9
+
10
+ # Holds the salmon endpoint used for direct notifications for this
11
+ # identity.
12
+ attr_reader :salmon_endpoint
13
+
14
+ # Holds the dialback endpoint used for capability transfer and
15
+ # authentication for this identity.
16
+ attr_reader :dialback_endpoint
17
+
18
+ # Holds the activity streams inbox endpoint for this identity.
19
+ attr_reader :activity_inbox_endpoint
20
+
21
+ # Holds the activity streams outbox endpoint for this identity.
22
+ attr_reader :activity_outbox_endpoint
23
+
24
+ # Holds the url to this identity's profile.
25
+ attr_reader :profile_page
26
+
27
+ # Create an instance of an Identity.
28
+ #
29
+ # options:
30
+ # :public_key => The identity's public key.
31
+ # :salmon_endpoint => The salmon endpoint for this identity.
32
+ # :dialback_endpoint => The dialback endpoint for this identity.
33
+ # :activity_inbox_endpoint => The activity streams inbox for this
34
+ # identity.
35
+ # :activity_outbox_endpoint => The activity streams outbox for this
36
+ # identity.
37
+ # :profile_page => The url for this identity's profile page.
38
+ def initialize(options = {})
39
+ init(options)
40
+ end
41
+
42
+ def init(options = {})
43
+ @public_key = options[:public_key]
44
+ @salmon_endpoint = options[:salmon_endpoint]
45
+ @dialback_endpoint = options[:dialback_endpoint]
46
+ @activity_inbox_endpoint = options[:activity_inbox_endpoint]
47
+ @activity_outbox_endpoint = options[:activity_outbox_endpoint]
48
+ @profile_page = options[:profile_page]
49
+ end
50
+
51
+ # Returns a hash of the properties of the identity.
52
+ def to_hash
53
+ {
54
+ :public_key => self.public_key,
55
+ :salmon_endpoint => self.salmon_endpoint,
56
+ :dialback_endpoint => self.dialback_endpoint,
57
+ :activity_inbox_endpoint => self.activity_inbox_endpoint,
58
+ :activity_outbox_endpoint => self.activity_outbox_endpoint,
59
+ :profile_page => self.profile_page
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,30 @@
1
+ module Nelumba
2
+ class Image
3
+ include Nelumba::Object
4
+
5
+ attr_reader :full_image
6
+
7
+ def initialize(options = {}, &blk)
8
+ init(options, &blk)
9
+ end
10
+
11
+ def init(options = {}, &blk)
12
+ super(options, &blk)
13
+
14
+ @full_image = options[:full_image]
15
+ end
16
+
17
+ def to_hash
18
+ {
19
+ :full_image => @full_image
20
+ }.merge(super)
21
+ end
22
+
23
+ def to_json_hash
24
+ {
25
+ :objectType => "image",
26
+ :fullImage => @full_image
27
+ }.merge(super)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ module Nelumba
2
+ require 'atom'
3
+
4
+ class Link
5
+ # The URL for the related resource.
6
+ attr_reader :href
7
+
8
+ # A string indicating the relationship type with the current
9
+ # document.
10
+ #
11
+ # Standard:
12
+ # "alternate" = Signifies that the URL in href identifies an alternative
13
+ # version of the resource described by the containing
14
+ # element.
15
+ # "related" = Signifies that the URL in href identifies a resource that
16
+ # is related to the contained resource. For example, the
17
+ # feed for a site that discusses the performance of the
18
+ # search engine at "http://search.example.com" might
19
+ # contain, as a link of Feed, a related link to that
20
+ # "http://search.example.com".
21
+ # "self" = Signifies that href contains a URL to the containing
22
+ # resource.
23
+ # "enclosure" = Signifies that the URL in href identifies a related
24
+ # resource that is potentially large in size and
25
+ # require special handling. SHOULD use the length field.
26
+ # "via" = Signifies that the URL in href identifies a resource that
27
+ # is the source of the information provided in the
28
+ # containing element.
29
+ attr_reader :rel
30
+
31
+ # Advises to the content MIME type of the linked resource.
32
+ attr_reader :type
33
+
34
+ # Advises to the language of the linked resource. When used with
35
+ # rel="alternate" it depicts a translated version of the entry.
36
+ # Use with a RFC3066 language tag.
37
+ attr_reader :hreflang
38
+
39
+ # Conveys human-readable information about the linked resource.
40
+ attr_reader :title
41
+
42
+ # Advises the length of the linked content in number of bytes. It is simply
43
+ # a hint about the length based upon prior information. It may change, and
44
+ # cannot override the actual content length.
45
+ attr_reader :length
46
+
47
+ def initialize(options = {})
48
+ @href = options[:href]
49
+ @rel = options[:rel]
50
+ @type = options[:type]
51
+ @hreflang = options[:hreflang]
52
+ @title = options[:title]
53
+ @length = options[:length]
54
+ end
55
+ end
56
+ end