@@ -88,33 +88,40 @@ def self.search(q, options = {})
8888 opts = { :query => query }
8989
9090 response = self . get ( "/search" , opts ) . nested_symbolize_keys! [ :response ]
91+ return collate_results_from_response ( response )
92+ end
9193
92- results = recursively_symbolize_keys! ( response [ :results ] )
93- content = [ ]
94-
95- results . each do |result |
96- content << GuardianContent ::Content . new ( recursively_symbolize_keys! ( result ) )
97- end
98- return content
94+ def self . find_all_by_id ( id , options = { } )
95+ response = response_for_id_find ( id , options )
96+ return collate_results_from_response ( response )
9997 end
10098
10199 # Fetch a Content item using its id. IDs are usually in the form of <tt>section/YYYY/month/DD/name-of-article</tt>.
102100 def self . find_by_id ( id , options = { } )
101+ response = response_for_id_find ( id , options )
102+ content = response [ :content ]
103103
104+ return GuardianContent ::Content . new ( recursively_symbolize_keys! ( content ) )
105+
106+ end
107+
108+ private
109+
110+ def self . collate_results_from_response ( response )
111+ results = recursively_symbolize_keys! ( response [ :results ] )
112+ return results . map do |result |
113+ GuardianContent ::Content . new ( recursively_symbolize_keys! ( result ) )
114+ end
115+ end
116+
117+ def self . response_for_id_find ( id , options )
104118 query = { }
105119 query [ "show-fields" ] = "all"
106120 query [ "show-tags" ] = "all"
107121 query [ :format ] = "json"
108122 opts = { :query => query }
109123
110124 attributes = { }
111-
112- response = recursively_symbolize_keys! self . get ( "/#{ id } " , opts ) . nested_symbolize_keys! [ :response ]
113-
114- content = response [ :content ]
115-
116- return GuardianContent ::Content . new ( recursively_symbolize_keys! ( content ) )
117-
125+ return recursively_symbolize_keys! self . get ( "/#{ id } " , opts ) . nested_symbolize_keys! [ :response ]
118126 end
119-
120127end
0 commit comments