Class: OutsideIn::Story

Inherits:
Base
  • Object
show all
Defined in:
lib/outside_in/story.rb

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

Instance Method Summary collapse

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.

Parameters:

  • state (String)

    the state name or postal abbreviation

  • city (String)

    the city name

  • inputs (Hash<String, Object>) (defaults to: {})

    the query parameter inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



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.

Parameters:

  • state (String)

    the state name or postal abbreviation

  • city (String)

    the city name

  • nabe (String)

    the neighborhood name

  • inputs (Hash<String, Object>) (defaults to: {})

    the query parameter inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



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.

Parameters:

  • state (String)

    the state name or postal abbreviation

  • inputs (Hash<String, Object>) (defaults to: {})

    the query parameter inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



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.

Parameters:

  • uuids (Array<SimpleUUID::UUID>)

    the location uuids

  • inputs (Hash<String, Object>) (defaults to: {})

    the query parameter inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



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.

Parameters:

  • zip (String)

    the zip code

  • inputs (Hash<String, Object>) (defaults to: {})

    the query parameter inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



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 UUID

    finder)
    

Parameters:

  • data (Hash<String, Object>)

    the raw query result

Returns:

  • (Hash<Symbol, Object>)

Since:

  • 1.0



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_sString

Returns the story’s title and uuid.

Returns:

  • (String)

Since:

  • 1.0



87
88
89
# File 'lib/outside_in/story.rb', line 87

def to_s
  "#{title} (#{uuid.to_guid})"
end