Skip to content

Commit f9e8f96

Browse files
author
Tom ten Thij
committed
Clean up white space in lib and test code
1 parent 90cdc3a commit f9e8f96

File tree

11 files changed

+150
-150
lines changed

11 files changed

+150
-150
lines changed

lib/guardian-content.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module GuardianContent
2-
2+
33
require 'httparty'
4-
5-
4+
5+
66
def self.new(*params)
77
GuardianContent::Base.new(*params)
88
end
9-
9+
1010
class Base
1111
include HTTParty
1212
base_uri 'http://content.guardianapis.com/'
13-
13+
1414
def initialize(key = nil)
1515
if defined?(GUARDIAN_CONTENT_API_KEY)
1616
key = GUARDIAN_CONTENT_API_KEY
1717
end
1818
self.class.default_params "api-key" => key, "format" => "json"
19-
end
19+
end
2020

2121
def reload(options = nil)
2222
@attributes.update(self.class.find_by_id(self.id, options).instance_variable_get('@attributes'))
@@ -29,4 +29,4 @@ def reload(options = nil)
2929

3030
%w(extensions content section tag keyword contributor).each do |file|
3131
require File.join(File.dirname(__FILE__), 'guardian-content', file)
32-
end
32+
end

lib/guardian-content/content.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This class represents 'content' items that have appeared on guardian.co.uk. Content items
22
# are usually articles, but can also be image galleries, videos, and so on.
33
# ==== Attributes
4-
# * +id+ - The Guardian ID of the content item, which is the same as the 'path' part of its URL, eg +world/2010/may/17/iran-nuclear-uranium-swap-turkey+
4+
# * +id+ - The Guardian ID of the content item, which is the same as the 'path' part of its URL, eg +world/2010/may/17/iran-nuclear-uranium-swap-turkey+
55
# * +title+ - The content item's title, as used on its web page.
66
# * +url+ - The full URL of the content item.
77
# * +publication_date+ - The date and time on which the content item was published. Returned as a DateTime instance.
@@ -22,16 +22,16 @@ def initialize(attributes = {})
2222
@publication_date = DateTime.parse(@publication_date)
2323
end
2424
@body = attributes[:body]
25-
25+
2626
if attributes[:tags]
2727
@tags = []
2828
attributes[:tags].each do |tag|
2929
@tags << tag
3030
end
3131
end
32-
32+
3333
@fields = attributes[:fields].nested_symbolize_keys! if attributes[:fields]
34-
34+
3535
if attributes[:fields]
3636
@headline = attributes[:fields][:headline]
3737
end
@@ -40,7 +40,7 @@ def initialize(attributes = {})
4040
def inspect
4141
"#<Article id: \"" + self.id.to_s + "\" title: \"" + self.title.to_s + "\" + url: \"" + self.url.to_s + "\">"
4242
end
43-
43+
4444
# Returns the Section in which the content item was published.
4545
def section
4646
return GuardianContent::Section.find_by_id(self.section_id)
@@ -55,7 +55,7 @@ def section
5555
# * GuardianContent::Content.search("election")
5656
# * GuardianContent::Content.search("election", :conditions => {:section => "politics"})
5757
def self.search(q, options = {})
58-
58+
5959
query = {}
6060
query["page-size"] = options[:limit] if options[:limit]
6161
query["order-by"] = options[:order] if options[:order]
@@ -71,7 +71,7 @@ def self.search(q, options = {})
7171

7272
if options[:conditions]
7373
conditions = options[:conditions]
74-
74+
7575
query[:tag] = conditions[:tag] if conditions[:tag]
7676
query[:section] = conditions[:section] if conditions[:section]
7777

@@ -80,15 +80,15 @@ def self.search(q, options = {})
8080

8181
end
8282

83-
83+
8484
query[:format] = "json"
85-
85+
8686
query[:q] = q
87-
87+
8888
opts = {:query => query}
8989

9090
response = self.get("/search", opts).nested_symbolize_keys![:response]
91-
91+
9292
results = recursively_symbolize_keys!(response[:results])
9393
content = []
9494

@@ -98,23 +98,23 @@ def self.search(q, options = {})
9898
return content
9999
end
100100

101-
# Fetch a Content item using its id. IDs are usually in the form of <tt>section/YYYY/month/DD/name-of-article</tt>.
101+
# Fetch a Content item using its id. IDs are usually in the form of <tt>section/YYYY/month/DD/name-of-article</tt>.
102102
def self.find_by_id(id, options = {})
103-
103+
104104
query = {}
105105
query["show-fields"] = "all"
106106
query["show-tags"] = "all"
107107
query[:format] = "json"
108108
opts = {:query => query}
109-
109+
110110
attributes = {}
111-
111+
112112
response = recursively_symbolize_keys!self.get("/#{id}", opts).nested_symbolize_keys![:response]
113-
113+
114114
content = response[:content]
115115

116116
return GuardianContent::Content.new(recursively_symbolize_keys!(content))
117-
118-
end
119-
117+
118+
end
119+
120120
end
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class GuardianContent::Contributor < GuardianContent::Tag
22

33
attr_reader :title, :id, :url
4-
4+
55
def initialize(attributes = {})
66
@id = attributes[:id] || nil
77
@title = attributes[:web_title] || nil
@@ -10,17 +10,17 @@ def initialize(attributes = {})
1010

1111
def inspect
1212
"#<Contributor id:" + self.id.to_s + " title:\"" + self.title.to_s + "\">"
13-
end
14-
13+
end
14+
1515
def self.find_by_id(id)
16-
16+
1717
query = {}
1818
query["show-fields"] = "all"
1919
query[:format] = "json"
2020
opts = {:query => query}
21-
21+
2222
return GuardianContent::Contributor.new(self.get("/#{id}").nested_symbolize_keys![:response][:tag])
23-
24-
end
25-
26-
end
23+
24+
end
25+
26+
end

lib/guardian-content/extensions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def nested_symbolize_keys!
88
end
99
self
1010
end
11-
11+
1212
def nested_stringify_keys!
1313
each do |k,v|
1414
s = k.respond_to?(:to_s) ? k.to_s : k
@@ -17,7 +17,7 @@ def nested_stringify_keys!
1717
end
1818
self
1919
end
20-
20+
2121
end
2222

2323
# This version works with both hashes and arrays

lib/guardian-content/keyword.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class GuardianContent::Keyword < GuardianContent::Tag
22

33
attr_reader :title, :id, :url
4-
4+
55
def initialize(attributes = {})
66
@id = attributes[:id] || nil
77
@title = attributes[:web_title] || nil
@@ -10,17 +10,17 @@ def initialize(attributes = {})
1010

1111
def inspect
1212
"#<Keyword id:" + self.id.to_s + " title:\"" + self.title.to_s + "\">"
13-
end
14-
13+
end
14+
1515
def self.find_by_id(id)
16-
16+
1717
query = {}
1818
query["show-fields"] = "all"
1919
query[:format] = "json"
2020
opts = {:query => query}
21-
21+
2222
return GuardianContent::Keyword.new(self.get("/#{id}").nested_symbolize_keys![:response][:tag])
23-
24-
end
25-
26-
end
23+
24+
end
25+
26+
end

lib/guardian-content/section.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class GuardianContent::Section < GuardianContent::Base
22

33
attr_reader :title, :id, :url
4-
4+
55
def initialize(attributes = {})
66
@@attributes = attributes
77
@id = attributes[:id] || nil
@@ -11,56 +11,56 @@ def initialize(attributes = {})
1111

1212
def inspect
1313
"#<Section id: \"" + self.id.to_s + "\" title: \"" + self.title.to_s + "\" url:\"" + self.url + "\">"
14-
end
14+
end
1515

1616
def self.search(q, options = {})
1717

1818
query = {}
19-
19+
2020
query[:q] = q
2121
query[:format] = "json"
22-
opts = {:query => query}
22+
opts = {:query => query}
2323

2424
response = self.get("/sections", opts).nested_symbolize_keys![:response]
25-
25+
2626
results = recursively_symbolize_keys!(response[:results])
2727
content = []
2828

2929
results.each do |result|
3030
content << GuardianContent::Section.new(recursively_symbolize_keys!(result))
3131
end
32-
return content
32+
return content
3333
end
34-
34+
3535
def self.find_by_id(id)
3636

3737
query = {}
3838
query["show-fields"] = "all"
3939
query[:format] = "json"
40-
opts = {:query => query}
41-
40+
opts = {:query => query}
41+
4242
response = recursively_symbolize_keys!self.get("/#{id}", opts).nested_symbolize_keys![:response]
43-
43+
4444
content = response[:section]
4545

4646
return GuardianContent::Section.new(recursively_symbolize_keys!(content))
47-
end
48-
47+
end
48+
4949
def content(options = {})
5050
GuardianContent::Content.search("", options.merge!(:conditions => {:section => self.id}))
5151
end
52-
52+
5353
def self.all(options = {})
5454

5555
response = self.get("/sections", {:query => {:format => "json"}}).nested_symbolize_keys![:response]
56-
56+
5757
results = recursively_symbolize_keys!(response[:results])
5858
content = []
5959

6060
results.each do |result|
6161
content << GuardianContent::Section.new(recursively_symbolize_keys!(result))
6262
end
63-
return content
63+
return content
6464
end
65-
66-
end
65+
66+
end

0 commit comments

Comments
 (0)