Class: TimesWire::Item
Constant Summary
Constants inherited from Base
Base::API_BASE, Base::API_NAME, Base::API_SERVER, Base::API_VERSION
Instance Attribute Summary collapse
-
#abstract ⇒ Object
readonly
Returns the value of attribute abstract.
-
#byline ⇒ Object
readonly
Returns the value of attribute byline.
-
#created_date ⇒ Object
readonly
Returns the value of attribute created_date.
-
#des_facets ⇒ Object
readonly
Returns the value of attribute des_facets.
-
#geo_facets ⇒ Object
readonly
Returns the value of attribute geo_facets.
-
#item_type ⇒ Object
readonly
Returns the value of attribute item_type.
-
#kicker ⇒ Object
readonly
Returns the value of attribute kicker.
-
#material_type_facet ⇒ Object
readonly
Returns the value of attribute material_type_facet.
-
#multimedia ⇒ Object
readonly
Returns the value of attribute multimedia.
-
#org_facets ⇒ Object
readonly
Returns the value of attribute org_facets.
-
#per_facets ⇒ Object
readonly
Returns the value of attribute per_facets.
-
#published_date ⇒ Object
readonly
Returns the value of attribute published_date.
-
#related_urls ⇒ Object
readonly
Returns the value of attribute related_urls.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#subheadline ⇒ Object
readonly
Returns the value of attribute subheadline.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated_date ⇒ Object
readonly
Returns the value of attribute updated_date.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .blog_name(source = 'nyt', section = section, blog = blog, limit = 20) ⇒ Object
- .create_from_api(params = {}) ⇒ Object
- .latest(source = "nyt", limit = 20) ⇒ Object
- .section(source = 'nyt', section = section, limit = 20) ⇒ Object
- .url(url) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Item
constructor
A new instance of Item.
- #semantic_terms ⇒ Object
Methods inherited from Base
api_key, api_key=, build_request_url, #copyright, datetime_parser, invoke, semantic_api_key=
Constructor Details
#initialize(params = {}) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 |
# File 'lib/times_wire/item.rb', line 8 def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#abstract ⇒ Object (readonly)
Returns the value of attribute abstract.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def abstract @abstract end |
#byline ⇒ Object (readonly)
Returns the value of attribute byline.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def @byline end |
#created_date ⇒ Object (readonly)
Returns the value of attribute created_date.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def created_date @created_date end |
#des_facets ⇒ Object (readonly)
Returns the value of attribute des_facets.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def des_facets @des_facets end |
#geo_facets ⇒ Object (readonly)
Returns the value of attribute geo_facets.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def geo_facets @geo_facets end |
#item_type ⇒ Object (readonly)
Returns the value of attribute item_type.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def item_type @item_type end |
#kicker ⇒ Object (readonly)
Returns the value of attribute kicker.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def kicker @kicker end |
#material_type_facet ⇒ Object (readonly)
Returns the value of attribute material_type_facet.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def material_type_facet @material_type_facet end |
#multimedia ⇒ Object (readonly)
Returns the value of attribute multimedia.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def multimedia @multimedia end |
#org_facets ⇒ Object (readonly)
Returns the value of attribute org_facets.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def org_facets @org_facets end |
#per_facets ⇒ Object (readonly)
Returns the value of attribute per_facets.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def per_facets @per_facets end |
#published_date ⇒ Object (readonly)
Returns the value of attribute published_date.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def published_date @published_date end |
#related_urls ⇒ Object (readonly)
Returns the value of attribute related_urls.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def @related_urls end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def section @section end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def source @source end |
#subheadline ⇒ Object (readonly)
Returns the value of attribute subheadline.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def subheadline @subheadline end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def title @title end |
#updated_date ⇒ Object (readonly)
Returns the value of attribute updated_date.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def updated_date @updated_date end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/times_wire/item.rb', line 4 def url @url end |
Class Method Details
.blog_name(source = 'nyt', section = section, blog = blog, limit = 20) ⇒ Object
57 58 59 60 61 |
# File 'lib/times_wire/item.rb', line 57 def self.blog_name(source='nyt', section=section, blog=blog, limit=20) reply = Base.invoke("#{source}/#{section}/", {"limit" => limit}) results = reply['results'].select{|i| i['blog_name'] == blog} @items = results.map {|r| Item.create_from_api(r)} end |
.create_from_api(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/times_wire/item.rb', line 14 def self.create_from_api(params={}) self.new :section => params['section'], :title => params['title'], :abstract => params['abstract'], :url => params['url'], :byline => params['byline'], :item_type => params['item_type'], :source => params['source'], :updated_date => datetime_parser(params['updated_date']), :created_date => datetime_parser(params['created_date']), :published_date => datetime_parser(params['published_date']), :material_type_facet => params['material_type_facet'], :kicker => params['kicker'], :subheadline => params['subheadline'], :multimedia => params['multimedia'], :des_facets => params['des_facet'], :org_facets => params['org_facet'], :per_facets => params['per_facet'], :geo_facets => params['geo_facet'], :blog_name => params['blog_name'], :related_urls => params['related_urls'], :multimedia => params['multimedia'] end |
.latest(source = "nyt", limit = 20) ⇒ Object
44 45 46 47 48 |
# File 'lib/times_wire/item.rb', line 44 def self.latest(source="nyt", limit=20) reply = Base.invoke("#{source}/all", {"limit" => limit}) results = reply['results'] @items = results.map {|r| Item.create_from_api(r)} end |
.section(source = 'nyt', section = section, limit = 20) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/times_wire/item.rb', line 50 def self.section(source='nyt', section=section, limit=20) section = section.gsub(' ', '+').gsub('&', '%26') reply = Base.invoke("#{source}/#{section}/", {"limit" => limit}) results = reply['results'] @items = results.map {|r| Item.create_from_api(r)} end |
.url(url) ⇒ Object
38 39 40 41 42 |
# File 'lib/times_wire/item.rb', line 38 def self.url(url) reply = Base.invoke('', {'url' => url}) return nil unless reply['results'].first Item.create_from_api(reply['results'].first) end |
Instance Method Details
#semantic_terms ⇒ Object
63 64 65 |
# File 'lib/times_wire/item.rb', line 63 def semantic_terms end |