Class: OutsideIn::Story
Overview
Story model class.
Stories have the following attributes:
-
feed_title
-
feed_url
-
story_url
-
summary
-
tags - (
Array
of Tag) -
title
-
uuid (SimpleUUID::UUID)
Story finders accept query parameter inputs as described by #parameterize_url. They return data structures as described by #query_result.
Class Method Summary collapse
-
.for_city(state, city, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to
city
instate
. -
.for_nabe(state, city, nabe, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to
nabe
incity
instate
. -
.for_state(state, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to
state
. -
.for_uuids(uuids, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to the locations identified by
uuids
. -
.for_zip_code(zip, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to
zip
. -
.query_result(data) ⇒ Hash<Symbol, Object>
Returns a hash encapsulating the data returned from a successful finder query.
Instance Method Summary collapse
-
#to_s ⇒ String
Returns the story’s title and uuid.
Methods inherited from Base
api_attr, api_attrs, #initialize
Constructor Details
This class inherits a constructor from OutsideIn::Base
Class Method Details
.for_city(state, city, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to city
in state
.
43 44 45 46 |
# File 'lib/outside_in/story.rb', line 43 def self.for_city(state, city, inputs = {}) url = "/states/#{URI.escape(state)}/cities/#{URI.escape(city)}/stories" query_result(OutsideIn::Resource::StoryFinder.new(url).GET(inputs)) end |
.for_nabe(state, city, nabe, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to nabe
in city
in state
.
56 57 58 59 |
# File 'lib/outside_in/story.rb', line 56 def self.for_nabe(state, city, nabe, inputs = {}) url = "/states/#{URI.escape(state)}/cities/#{URI.escape(city)}/nabes/#{URI.escape(nabe)}/stories" query_result(OutsideIn::Resource::StoryFinder.new(url).GET(inputs)) end |
.for_state(state, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to state
.
31 32 33 34 |
# File 'lib/outside_in/story.rb', line 31 def self.for_state(state, inputs = {}) url = "/states/#{URI.escape(state)}/stories" query_result(OutsideIn::Resource::StoryFinder.new(url).GET(inputs)) end |
.for_uuids(uuids, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to the locations identified by uuids
.
78 79 80 81 |
# File 'lib/outside_in/story.rb', line 78 def self.for_uuids(uuids, inputs = {}) url = "/locations/#{uuids.map{|u| URI.escape(u.to_guid)}.join(",")}/stories" query_result(OutsideIn::Resource::StoryFinder.new(url).GET(inputs)) end |
.for_zip_code(zip, inputs = {}) ⇒ Hash<Symbol, Object>
Returns the stories attached to zip
.
67 68 69 70 |
# File 'lib/outside_in/story.rb', line 67 def self.for_zip_code(zip, inputs = {}) url = "/zipcodes/#{URI.escape(zip)}/stories" query_result(OutsideIn::Resource::StoryFinder.new(url).GET(inputs)) end |
.query_result(data) ⇒ Hash<Symbol, Object>
Returns a hash encapsulating the data returned from a successful finder query.
The hash contains the following data:
-
:total
- the total number of matching stories (may be greater than the number of returned stories) -
:stories
- the array of most recent matching OutsideIn::Story in reverse chronological order as per the specified or implied limit -
:location
- the Location to which the finder was scoped (present for all non-UUID finders) -
:locations
- the array of Location to which the finder was scoped (present only for the UUIDfinder)
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/outside_in/story.rb', line 105 def self.query_result(data) rv = {:total => data['total'], :stories => []} if data.include?('locations') rv[:locations] = data['locations'].map {|l| Location.new(l)} else rv[:location] = Location.new(data['location']) end rv[:stories] = data['stories'].map {|s| new(s)} rv end |
Instance Method Details
#to_s ⇒ String
Returns the story’s title and uuid.
87 88 89 |
# File 'lib/outside_in/story.rb', line 87 def to_s "#{title} (#{uuid.to_guid})" end |