ostatus 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ostatus/feed.rb +29 -19
- data/lib/ostatus/version.rb +1 -1
- metadata +3 -3
data/lib/ostatus/feed.rb
CHANGED
@@ -9,17 +9,13 @@ module OStatus
|
|
9
9
|
|
10
10
|
# This class represents an OStatus Feed object.
|
11
11
|
class Feed
|
12
|
-
def initialize(str, url, access_token,
|
12
|
+
def initialize(str, url, access_token, options)
|
13
13
|
@str = str
|
14
14
|
@url = url
|
15
15
|
@access_token = access_token
|
16
|
-
@
|
17
|
-
@entries = entries
|
18
|
-
@id = id
|
19
|
-
@title = title
|
20
|
-
@links = links
|
16
|
+
@options = options
|
21
17
|
|
22
|
-
if
|
18
|
+
if options == nil
|
23
19
|
@xml = Nokogiri::XML::Document.parse(self.atom)
|
24
20
|
end
|
25
21
|
end
|
@@ -27,17 +23,17 @@ module OStatus
|
|
27
23
|
# Creates a new Feed instance given by the atom feed located at 'url'
|
28
24
|
# and optionally using the OAuth::AccessToken given.
|
29
25
|
def Feed.from_url(url, access_token = nil)
|
30
|
-
Feed.new(nil, url, access_token, nil
|
26
|
+
Feed.new(nil, url, access_token, nil)
|
31
27
|
end
|
32
28
|
|
33
29
|
# Creates a new Feed instance that contains the information given by
|
34
30
|
# the various instances of author and entries.
|
35
|
-
def Feed.from_data(
|
36
|
-
Feed.new(nil, url, nil,
|
31
|
+
def Feed.from_data(url, options)
|
32
|
+
Feed.new(nil, url, nil, options)
|
37
33
|
end
|
38
34
|
|
39
35
|
def Feed.from_string(str)
|
40
|
-
Feed.new(str, nil, nil, nil
|
36
|
+
Feed.new(str, nil, nil, nil)
|
41
37
|
end
|
42
38
|
|
43
39
|
# Returns an array of Nokogiri::XML::Element instances for all link tags
|
@@ -49,7 +45,7 @@ module OStatus
|
|
49
45
|
# returns the contents of the href attribute.
|
50
46
|
#
|
51
47
|
def link(attribute)
|
52
|
-
return @links[attribute] unless @
|
48
|
+
return @options[:links][attribute] unless @options == nil
|
53
49
|
|
54
50
|
# get all links with rel attribute being equal to attribute
|
55
51
|
@xml.xpath('/xmlns:feed/xmlns:link').select do |link|
|
@@ -69,16 +65,30 @@ module OStatus
|
|
69
65
|
link(:salmon).first[:href]
|
70
66
|
end
|
71
67
|
|
68
|
+
# Returns the logo
|
69
|
+
def logo
|
70
|
+
return @options[:logo] unless @options == nil
|
71
|
+
|
72
|
+
pick_first_node(@xml.xpath('/xmlns:feed/xmlns:logo'))
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns the icon
|
76
|
+
def icon
|
77
|
+
return @options[:icon] unless @options == nil
|
78
|
+
|
79
|
+
pick_first_node(@xml.xpath('/xmlns:feed/xmlns:icon'))
|
80
|
+
end
|
81
|
+
|
72
82
|
# This method will return a String containing the actual content of
|
73
83
|
# the atom feed. It will make a network request (through OAuth if
|
74
84
|
# an access token was given) to retrieve the document if necessary.
|
75
85
|
def atom
|
76
86
|
if @str != nil
|
77
87
|
@str
|
78
|
-
elsif @
|
88
|
+
elsif @options == nil and @access_token == nil
|
79
89
|
# simply open the url
|
80
90
|
open(@url).read
|
81
|
-
elsif @
|
91
|
+
elsif @options == nil and @url != nil
|
82
92
|
# open the url through OAuth
|
83
93
|
@access_token.get(@url).body
|
84
94
|
else
|
@@ -96,7 +106,7 @@ module OStatus
|
|
96
106
|
:hubs => self.hubs
|
97
107
|
)
|
98
108
|
|
99
|
-
@entries.each do |entry|
|
109
|
+
@options[:entries].each do |entry|
|
100
110
|
entry_url = entry.link[:href]
|
101
111
|
entry_url = @url if entry_url == nil
|
102
112
|
|
@@ -131,13 +141,13 @@ module OStatus
|
|
131
141
|
private :pick_first_node
|
132
142
|
|
133
143
|
def id
|
134
|
-
return @id
|
144
|
+
return @options[:id] unless @options == nil
|
135
145
|
|
136
146
|
pick_first_node(@xml.xpath('/xmlns:feed/xmlns:id'))
|
137
147
|
end
|
138
148
|
|
139
149
|
def title
|
140
|
-
return @title
|
150
|
+
return @options[:title] unless @options == nil
|
141
151
|
|
142
152
|
pick_first_node(@xml.xpath('/xmlns:feed/xmlns:title'))
|
143
153
|
end
|
@@ -149,7 +159,7 @@ module OStatus
|
|
149
159
|
# Returns an OStatus::Author that will parse the author information
|
150
160
|
# within the Feed.
|
151
161
|
def author
|
152
|
-
return @author
|
162
|
+
return @options[:author] unless @options == nil
|
153
163
|
|
154
164
|
author_xml = @xml.at_css('author')
|
155
165
|
OStatus::Author.new(author_xml)
|
@@ -158,7 +168,7 @@ module OStatus
|
|
158
168
|
# This method gives you an array of OStatus::Entry instances for
|
159
169
|
# each entry listed in the feed.
|
160
170
|
def entries
|
161
|
-
return @entries
|
171
|
+
return @options[:entries] unless @options == nil
|
162
172
|
|
163
173
|
entries_xml = @xml.css('entry')
|
164
174
|
|
data/lib/ostatus/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hackers of the Severed Hand
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|