Class: TimesWire::Item

Inherits:
Base
  • Object
show all
Defined in:
lib/times_wire/item.rb

Constant Summary

Constants inherited from Base

Base::API_BASE, Base::API_NAME, Base::API_SERVER, Base::API_VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#abstractObject (readonly)

Returns the value of attribute abstract.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def abstract
  @abstract
end

#bylineObject (readonly)

Returns the value of attribute byline.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def 
  @byline
end

#created_dateObject (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_facetsObject (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_facetsObject (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_typeObject (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

#kickerObject (readonly)

Returns the value of attribute kicker.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def kicker
  @kicker
end

#material_type_facetObject (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

#multimediaObject (readonly)

Returns the value of attribute multimedia.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def multimedia
  @multimedia
end

#org_facetsObject (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_facetsObject (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_dateObject (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

Returns the value of attribute related_urls.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def related_urls
  @related_urls
end

#sectionObject (readonly)

Returns the value of attribute section.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def section
  @section
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def source
  @source
end

#subheadlineObject (readonly)

Returns the value of attribute subheadline.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def subheadline
  @subheadline
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/times_wire/item.rb', line 4

def title
  @title
end

#updated_dateObject (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

#urlObject (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_termsObject



63
64
65
# File 'lib/times_wire/item.rb', line 63

def semantic_terms
  
end