npr 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +13 -0
- data/{LICENSE → MIT-LICENSE} +1 -1
- data/README.md +115 -3
- data/Rakefile +6 -0
- data/gemfiles/Gemfile.rb-1.8.7 +6 -0
- data/lib/npr/api/client.rb +87 -0
- data/lib/npr/api/message.rb +38 -0
- data/lib/npr/api/query_builder.rb +222 -0
- data/lib/npr/api/response.rb +32 -0
- data/lib/npr/api.rb +7 -0
- data/lib/npr/concern/attr_typecast.rb +59 -0
- data/lib/npr/concern/relation.rb +103 -0
- data/lib/npr/concern/shallow_attributes.rb +71 -0
- data/lib/npr/concern.rb +9 -0
- data/lib/npr/configuration.rb +120 -0
- data/lib/npr/core_ext/array/wrap.rb +15 -0
- data/lib/npr/entity/audio.rb +28 -0
- data/lib/npr/entity/author.rb +22 -0
- data/lib/npr/entity/base.rb +19 -0
- data/lib/npr/entity/book.rb +21 -0
- data/lib/npr/entity/book_edition.rb +26 -0
- data/lib/npr/entity/byline.rb +18 -0
- data/lib/npr/entity/collection.rb +11 -0
- data/lib/npr/entity/crop.rb +20 -0
- data/lib/npr/entity/enlargement.rb +20 -0
- data/lib/npr/entity/formats.rb +19 -0
- data/lib/npr/entity/image.rb +33 -0
- data/lib/npr/entity/intro_text.rb +21 -0
- data/lib/npr/entity/link.rb +23 -0
- data/lib/npr/entity/list.rb +28 -0
- data/lib/npr/entity/list_text.rb +19 -0
- data/lib/npr/entity/member.rb +23 -0
- data/lib/npr/entity/member_byline.rb +17 -0
- data/lib/npr/entity/member_promo_art.rb +17 -0
- data/lib/npr/entity/mp3.rb +23 -0
- data/lib/npr/entity/organization.rb +18 -0
- data/lib/npr/entity/paragraph.rb +27 -0
- data/lib/npr/entity/permissions.rb +18 -0
- data/lib/npr/entity/program.rb +24 -0
- data/lib/npr/entity/promo_art.rb +17 -0
- data/lib/npr/entity/promo_art_book_edition.rb +18 -0
- data/lib/npr/entity/provider.rb +23 -0
- data/lib/npr/entity/pull_quote.rb +16 -0
- data/lib/npr/entity/related_link.rb +21 -0
- data/lib/npr/entity/show.rb +19 -0
- data/lib/npr/entity/story.rb +179 -0
- data/lib/npr/entity/text.rb +22 -0
- data/lib/npr/entity/title.rb +21 -0
- data/lib/npr/entity/transcript.rb +16 -0
- data/lib/npr/entity.rb +7 -0
- data/lib/npr/errors.rb +17 -0
- data/lib/npr/version.rb +1 -1
- data/lib/npr.rb +64 -3
- data/npr.gemspec +12 -2
- data/spec/fixtures/README.md +30 -0
- data/spec/fixtures/atom/01_story_full_media.atom +36 -0
- data/spec/fixtures/atom/02_story_multiple_images.atom +32 -0
- data/spec/fixtures/atom/03_no_results.atom +10 -0
- data/spec/fixtures/atom/04_invalid_id.atom +344 -0
- data/spec/fixtures/atom/05_no_api_key.atom +9 -0
- data/spec/fixtures/atom/06_story_multiple_ids.atom +59 -0
- data/spec/fixtures/fetch_formats.rb +65 -0
- data/spec/fixtures/html/01_story_full_media.html +54 -0
- data/spec/fixtures/html/02_story_multiple_images.html +55 -0
- data/spec/fixtures/html/03_no_results.html +38 -0
- data/spec/fixtures/html/04_invalid_id.html +82 -0
- data/spec/fixtures/html/05_no_api_key.html +8 -0
- data/spec/fixtures/html/06_story_multiple_ids.html +69 -0
- data/spec/fixtures/js/01_story_full_media.js +1 -0
- data/spec/fixtures/js/02_story_multiple_images.js +1 -0
- data/spec/fixtures/js/03_no_results.js +1 -0
- data/spec/fixtures/js/04_invalid_id.js +1 -0
- data/spec/fixtures/js/05_no_api_key.js +8 -0
- data/spec/fixtures/js/06_story_multiple_ids.js +1 -0
- data/spec/fixtures/json/01_story_full_media.json +1 -0
- data/spec/fixtures/json/02_story_multiple_images.json +1 -0
- data/spec/fixtures/json/03_no_results.json +1 -0
- data/spec/fixtures/json/04_invalid_id.json +1 -0
- data/spec/fixtures/json/05_no_api_key.json +1 -0
- data/spec/fixtures/json/06_story_multiple_ids.json +1 -0
- data/spec/fixtures/json/list.json +1 -0
- data/spec/fixtures/mediarss/01_story_full_media.rss +31 -0
- data/spec/fixtures/mediarss/02_story_multiple_images.rss +40 -0
- data/spec/fixtures/mediarss/03_no_results.rss +17 -0
- data/spec/fixtures/mediarss/04_invalid_id.rss +279 -0
- data/spec/fixtures/mediarss/05_no_api_key.rss +31 -0
- data/spec/fixtures/mediarss/06_story_multiple_ids.rss +65 -0
- data/spec/fixtures/nprml/01_story_full_media.xml +271 -0
- data/spec/fixtures/nprml/02_story_multiple_images.xml +165 -0
- data/spec/fixtures/nprml/03_no_results.xml +14 -0
- data/spec/fixtures/nprml/04_invalid_id.xml +1780 -0
- data/spec/fixtures/nprml/05_no_api_key.xml +9 -0
- data/spec/fixtures/nprml/06_story_multiple_ids.xml +435 -0
- data/spec/fixtures/nprml/list.xml +440 -0
- data/spec/fixtures/podcast/01_story_full_media.rss +30 -0
- data/spec/fixtures/podcast/02_story_multiple_images.rss +32 -0
- data/spec/fixtures/podcast/03_no_results.rss +19 -0
- data/spec/fixtures/podcast/04_invalid_id.rss +186 -0
- data/spec/fixtures/podcast/05_no_api_key.rss +31 -0
- data/spec/fixtures/podcast/06_story_multiple_ids.rss +43 -0
- data/spec/fixtures/rss/01_story_full_media.rss +25 -0
- data/spec/fixtures/rss/02_story_multiple_images.rss +25 -0
- data/spec/fixtures/rss/03_no_results.rss +17 -0
- data/spec/fixtures/rss/04_invalid_id.rss +137 -0
- data/spec/fixtures/rss/05_no_api_key.rss +31 -0
- data/spec/fixtures/rss/06_story_multiple_ids.rss +33 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/config_helper.rb +64 -0
- data/spec/support/fake_response.rb +54 -0
- data/spec/support/fixture_helper.rb +23 -0
- data/spec/unit/api/client_spec.rb +42 -0
- data/spec/unit/api/message_spec.rb +68 -0
- data/spec/unit/api/query_builder_spec.rb +195 -0
- data/spec/unit/api/response_spec.rb +45 -0
- data/spec/unit/configuration_spec.rb +63 -0
- data/spec/unit/entity/audio_spec.rb +75 -0
- data/spec/unit/entity/author_spec.rb +30 -0
- data/spec/unit/entity/base_spec.rb +87 -0
- data/spec/unit/entity/book_edition_spec.rb +57 -0
- data/spec/unit/entity/book_spec.rb +31 -0
- data/spec/unit/entity/byline_spec.rb +23 -0
- data/spec/unit/entity/collection_spec.rb +39 -0
- data/spec/unit/entity/crop_spec.rb +25 -0
- data/spec/unit/entity/englargement_spec.rb +21 -0
- data/spec/unit/entity/formats_spec.rb +41 -0
- data/spec/unit/entity/image_spec.rb +82 -0
- data/spec/unit/entity/intro_text_spec.rb +25 -0
- data/spec/unit/entity/link_spec.rb +25 -0
- data/spec/unit/entity/list_spec.rb +22 -0
- data/spec/unit/entity/list_text_spec.rb +31 -0
- data/spec/unit/entity/member_byline_spec.rb +21 -0
- data/spec/unit/entity/member_promo_art_spec.rb +21 -0
- data/spec/unit/entity/member_spec.rb +59 -0
- data/spec/unit/entity/mp3_spec.rb +25 -0
- data/spec/unit/entity/organization_spec.rb +29 -0
- data/spec/unit/entity/paragraph_spec.rb +25 -0
- data/spec/unit/entity/permissions_spec.rb +56 -0
- data/spec/unit/entity/program_spec.rb +27 -0
- data/spec/unit/entity/promo_art_book_edition_spec.rb +21 -0
- data/spec/unit/entity/promo_art_spec.rb +42 -0
- data/spec/unit/entity/pull_quote_spec.rb +29 -0
- data/spec/unit/entity/related_link_spec.rb +55 -0
- data/spec/unit/entity/show_spec.rb +41 -0
- data/spec/unit/entity/story_spec.rb +154 -0
- data/spec/unit/entity/text_spec.rb +54 -0
- data/spec/unit/entity/title_spec.rb +25 -0
- data/spec/unit/entity/transcript_spec.rb +22 -0
- metadata +340 -8
@@ -0,0 +1,103 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Concern::Relation
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Concern
|
6
|
+
module Relation
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
#-----------------
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
#-----------------
|
15
|
+
# Define a relationship
|
16
|
+
# Similar to ActiveRecord's +has_many+
|
17
|
+
#
|
18
|
+
# Arguments:
|
19
|
+
#
|
20
|
+
# * name (String) - the name of the relation
|
21
|
+
# * options (Hash)
|
22
|
+
# * class_name (Class) - the class for the related objects
|
23
|
+
# * key (String) - the JSON key that holds this relation
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
#
|
27
|
+
# has_many "links", key: "link", class_name: NPR::Entity::Link
|
28
|
+
#
|
29
|
+
def has_many(name, options)
|
30
|
+
relation = build_relation(name, options)
|
31
|
+
|
32
|
+
# Define getter and setter for this attribute
|
33
|
+
# Forces the relation into an empty array when
|
34
|
+
# it's first accessed.
|
35
|
+
attr_writer name
|
36
|
+
define_method name do
|
37
|
+
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", [])
|
38
|
+
end
|
39
|
+
|
40
|
+
_has_many_relations.push relation
|
41
|
+
end
|
42
|
+
|
43
|
+
#-----------------
|
44
|
+
|
45
|
+
def has_one(name, options)
|
46
|
+
relation = build_relation(name, options)
|
47
|
+
attr_accessor name
|
48
|
+
_has_one_relations.push relation
|
49
|
+
end
|
50
|
+
|
51
|
+
#-----------------
|
52
|
+
|
53
|
+
def _has_many_relations
|
54
|
+
@_has_many_relations ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def _has_one_relations
|
58
|
+
@_has_one_relations ||= []
|
59
|
+
end
|
60
|
+
|
61
|
+
#-----------------
|
62
|
+
|
63
|
+
private
|
64
|
+
attr_writer :_has_many_relations, :_has_one_relations
|
65
|
+
|
66
|
+
def build_relation(name, options)
|
67
|
+
relation = {
|
68
|
+
:name => name,
|
69
|
+
:class_name => options[:class_name],
|
70
|
+
:key => options[:key] || name
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
#-----------------
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
#-----------------
|
81
|
+
# Populate the relations based on
|
82
|
+
def create_relations(json)
|
83
|
+
self.class._has_many_relations.each do |relation|
|
84
|
+
collection = []
|
85
|
+
|
86
|
+
if node = json[relation[:key]]
|
87
|
+
node.each do |obj|
|
88
|
+
collection.push relation[:class_name].new(obj)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
send "#{relation[:name]}=", collection
|
93
|
+
end
|
94
|
+
|
95
|
+
self.class._has_one_relations.each do |relation|
|
96
|
+
if node = json[relation[:key]]
|
97
|
+
send "#{relation[:name]}=", relation[:class_name].new(node)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end # Relation
|
102
|
+
end # Concern
|
103
|
+
end # NPR
|
@@ -0,0 +1,71 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Concern::ShallowAttributes
|
3
|
+
#
|
4
|
+
# A "shallow attribute" is one that only contains the "$text"
|
5
|
+
# node. Use this class method to define which attributes those
|
6
|
+
# are.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# { "link": { "$text": "www.google.com" } }
|
11
|
+
#
|
12
|
+
# shallow_attribute "link"
|
13
|
+
#
|
14
|
+
module NPR
|
15
|
+
module Concern
|
16
|
+
module ShallowAttributes
|
17
|
+
include AttrTypecast
|
18
|
+
|
19
|
+
def self.included(base)
|
20
|
+
base.extend ClassMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
#-----------------
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
def shallow_attribute(*attrs)
|
27
|
+
_shallow_attributes.push *attrs
|
28
|
+
attr_accessor *attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
#-----------------
|
32
|
+
|
33
|
+
def _shallow_attributes
|
34
|
+
@shallow_attributes ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
#-----------------
|
38
|
+
|
39
|
+
private
|
40
|
+
attr_writer :_shallow_attributes
|
41
|
+
end
|
42
|
+
|
43
|
+
#-----------------
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
#-----------------
|
48
|
+
# Extract the defined shallow_attributes from the JSON
|
49
|
+
# and set the corresponding attribute.
|
50
|
+
#
|
51
|
+
# If the JSON doesn't contain a key for an attribute,
|
52
|
+
# then attribute will remain at its default state (nil).
|
53
|
+
#
|
54
|
+
# Arguments: Hash of the JSON for this object
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
#
|
58
|
+
# def initialize(json)
|
59
|
+
# extract_shallow_attributes(json)
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
def extract_shallow_attributes(json)
|
63
|
+
self.class._shallow_attributes.each do |key|
|
64
|
+
if node = json[key]
|
65
|
+
send "#{key}=", attr_typecast(key, node["$text"].to_s)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end # ShallowAttribute
|
70
|
+
end # Concern
|
71
|
+
end # NPR
|
data/lib/npr/concern.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Configuration
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
#-------------------
|
6
|
+
# Pass a block to configure NPR client globally.
|
7
|
+
#
|
8
|
+
# Options configured globally will be
|
9
|
+
# passed in to every API request. They can
|
10
|
+
# still be overridden on a per-query or per-client
|
11
|
+
# basis.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# NPR.configure do |config|
|
16
|
+
# config.apiKey = "YOUR_API_KEY"
|
17
|
+
# config.sort = "date descending"
|
18
|
+
# config.output = "NPRML"
|
19
|
+
# config.requiredAssets = "text"
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
def self.configure
|
23
|
+
yield config
|
24
|
+
end
|
25
|
+
|
26
|
+
#-------------------
|
27
|
+
|
28
|
+
def self.config
|
29
|
+
@config ||= NPR::Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
#-------------------
|
33
|
+
# NPR::Configuration
|
34
|
+
#
|
35
|
+
# Probably doesn't need to be accessed directly.
|
36
|
+
# You can get the global configuration for the NPR
|
37
|
+
# gem by accessing +NPR.config+
|
38
|
+
#
|
39
|
+
class Configuration
|
40
|
+
API_ROOT = "http://api.npr.org"
|
41
|
+
|
42
|
+
API_QUERY_PATH = "/query"
|
43
|
+
API_LIST_PATH = "/list"
|
44
|
+
|
45
|
+
# List all the parameters that the NPR API
|
46
|
+
# can accept. Some are left out that don't
|
47
|
+
# make sense to globally configure (such as
|
48
|
+
# +:id+, +:startNum+, and +:callback+)
|
49
|
+
API_OPTIONS = [
|
50
|
+
# List options
|
51
|
+
:storyCountAll,
|
52
|
+
:storyCountMonth,
|
53
|
+
:storyCountToday,
|
54
|
+
:childrenOf,
|
55
|
+
:hideChildren,
|
56
|
+
|
57
|
+
# Story options
|
58
|
+
:apiKey,
|
59
|
+
:orgId,
|
60
|
+
:meta,
|
61
|
+
:output,
|
62
|
+
:fields,
|
63
|
+
:sort,
|
64
|
+
:numResults,
|
65
|
+
:action,
|
66
|
+
:requiredAssets,
|
67
|
+
:date,
|
68
|
+
:startDate,
|
69
|
+
:endDate,
|
70
|
+
:dateType,
|
71
|
+
:searchTerm,
|
72
|
+
:searchType,
|
73
|
+
:title
|
74
|
+
]
|
75
|
+
|
76
|
+
attr_accessor *API_OPTIONS
|
77
|
+
|
78
|
+
#-------------------
|
79
|
+
# You can pass in a hash of options to
|
80
|
+
# Configuration.new
|
81
|
+
def initialize(options={})
|
82
|
+
options.each do |key, value|
|
83
|
+
send "#{key}=", value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#-------------------
|
88
|
+
# Convenience method
|
89
|
+
def merge(hash)
|
90
|
+
to_hash.merge hash
|
91
|
+
end
|
92
|
+
|
93
|
+
#-------------------
|
94
|
+
# Convert this Configuration object into a Hash
|
95
|
+
#
|
96
|
+
# Why don't we inherit from OrderedOptions?
|
97
|
+
#
|
98
|
+
# Since the API options are out of our control
|
99
|
+
# (without having to map every API option to
|
100
|
+
# internal methods), it is possible that one
|
101
|
+
# of the config options will conflict with
|
102
|
+
# something in Ruby. For example, the "sort"
|
103
|
+
# option that the NPR API allows would mean
|
104
|
+
# we'd have to overwrite Ruby's Hash#sort
|
105
|
+
# method.
|
106
|
+
#
|
107
|
+
# We *could* just map out config options to
|
108
|
+
# the API options, but I think it's more
|
109
|
+
# important to keep the gem config options
|
110
|
+
# in perfect sync with the API options.
|
111
|
+
#
|
112
|
+
def to_hash
|
113
|
+
hash = {}
|
114
|
+
instance_variables.each do |var|
|
115
|
+
hash[var[1..-1].to_sym] = instance_variable_get(var)
|
116
|
+
end
|
117
|
+
hash
|
118
|
+
end
|
119
|
+
end # Configuration
|
120
|
+
end # NPR
|
@@ -0,0 +1,15 @@
|
|
1
|
+
##
|
2
|
+
# Copied directly from ActiveSupport
|
3
|
+
# <https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/wrap.rb>
|
4
|
+
#
|
5
|
+
class Array
|
6
|
+
def self.wrap(object)
|
7
|
+
if object.nil?
|
8
|
+
[]
|
9
|
+
elsif object.respond_to?(:to_ary)
|
10
|
+
object.to_ary || [object]
|
11
|
+
else
|
12
|
+
[object]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Audio
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Audio < Base
|
7
|
+
attr_accessor :id, :type, :stream
|
8
|
+
shallow_attribute "title", "duration", "description", "rightsHolder"
|
9
|
+
has_one "permissions", :class_name => NPR::Entity::Permissions
|
10
|
+
has_one "formats", :key => "format", :class_name => NPR::Entity::Formats
|
11
|
+
|
12
|
+
#-------------------
|
13
|
+
# +stream+ returns true if "active" is set to "true"
|
14
|
+
#
|
15
|
+
def initialize(json)
|
16
|
+
@id = json["id"].to_i
|
17
|
+
@type = json["type"]
|
18
|
+
|
19
|
+
if json["stream"]
|
20
|
+
@stream = json["stream"]["active"] == "true"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_relations(json)
|
24
|
+
extract_shallow_attributes(json)
|
25
|
+
end
|
26
|
+
end # Audio
|
27
|
+
end # Entity
|
28
|
+
end # NPR
|
@@ -0,0 +1,22 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Author
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Author < Base
|
7
|
+
attr_accessor :id, :num
|
8
|
+
shallow_attribute "title"
|
9
|
+
has_one "link", :class_name => NPR::Entity::Link
|
10
|
+
|
11
|
+
#-----------------
|
12
|
+
|
13
|
+
def initialize(json)
|
14
|
+
@id = json["id"].to_i
|
15
|
+
@num = json["num"].to_i
|
16
|
+
|
17
|
+
create_relations(json)
|
18
|
+
extract_shallow_attributes(json)
|
19
|
+
end
|
20
|
+
end # Author
|
21
|
+
end # Entity
|
22
|
+
end # NPR
|
@@ -0,0 +1,19 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Base
|
3
|
+
#
|
4
|
+
# Class for all NPR Objects to inherit from
|
5
|
+
#
|
6
|
+
module NPR
|
7
|
+
module Entity
|
8
|
+
class Base
|
9
|
+
include NPR::Concern::Relation
|
10
|
+
include NPR::Concern::ShallowAttributes
|
11
|
+
|
12
|
+
#-----------------
|
13
|
+
# Override this
|
14
|
+
def initialize(json={})
|
15
|
+
@_json = json
|
16
|
+
end
|
17
|
+
end # Base
|
18
|
+
end # Entity
|
19
|
+
end # NPR
|
@@ -0,0 +1,21 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Book
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Book < Base
|
7
|
+
attr_accessor :id
|
8
|
+
shallow_attribute "title"
|
9
|
+
has_one "link", :class_name => NPR::Entity::Link
|
10
|
+
|
11
|
+
#---------------------
|
12
|
+
|
13
|
+
def initialize(json)
|
14
|
+
@id = json["id"].to_i
|
15
|
+
|
16
|
+
extract_shallow_attributes(json)
|
17
|
+
create_relations(json)
|
18
|
+
end
|
19
|
+
end # Book
|
20
|
+
end # Entity
|
21
|
+
end # NPR
|
@@ -0,0 +1,26 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::BookEdition
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class BookEdition < Base
|
7
|
+
attr_accessor :id, :format_num
|
8
|
+
shallow_attribute "isbn", "publisher", "pubDate", "pagination", "listPrice"
|
9
|
+
has_one "book", :class_name => NPR::Entity::Book
|
10
|
+
|
11
|
+
#---------------------
|
12
|
+
# Note that the "format" property is represented on this
|
13
|
+
# object as "format_num", because of Kernel's "format"
|
14
|
+
def initialize(json)
|
15
|
+
@id = json["id"].to_i
|
16
|
+
|
17
|
+
if json["format"]
|
18
|
+
@format_num = json["format"]["$text"].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
extract_shallow_attributes(json)
|
22
|
+
create_relations(json)
|
23
|
+
end
|
24
|
+
end # BookEdition
|
25
|
+
end # Entity
|
26
|
+
end # NPR
|
@@ -0,0 +1,18 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Byline
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Byline < Base
|
7
|
+
attr_accessor :id
|
8
|
+
shallow_attribute "name"
|
9
|
+
|
10
|
+
#-----------------
|
11
|
+
|
12
|
+
def initialize(json)
|
13
|
+
@id = json["id"].to_i
|
14
|
+
extract_shallow_attributes(json)
|
15
|
+
end
|
16
|
+
end # Byline
|
17
|
+
end # Entity
|
18
|
+
end # NPR
|
@@ -0,0 +1,20 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Crop
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Crop < Base
|
7
|
+
attr_accessor :type, :src, :width, :height
|
8
|
+
|
9
|
+
#---------------
|
10
|
+
|
11
|
+
def initialize(json)
|
12
|
+
@type = json["type"]
|
13
|
+
@src = json["src"]
|
14
|
+
@width = json["width"].to_i
|
15
|
+
@height = json["height"].to_i
|
16
|
+
end
|
17
|
+
end # Crop
|
18
|
+
end # Entity
|
19
|
+
end # NPR
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Enlargement
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Enlargement < Base
|
7
|
+
attr_accessor :src
|
8
|
+
shallow_attribute "caption"
|
9
|
+
|
10
|
+
#---------------
|
11
|
+
|
12
|
+
def initialize(json)
|
13
|
+
@src = json["src"]
|
14
|
+
extract_shallow_attributes(json)
|
15
|
+
end
|
16
|
+
end # Enlargement
|
17
|
+
end # Entity
|
18
|
+
end # NPR
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Formats
|
3
|
+
#
|
4
|
+
# Audio Formats
|
5
|
+
module NPR
|
6
|
+
module Entity
|
7
|
+
class Formats < Base
|
8
|
+
has_many "mp3s", :key => "mp3", :class_name => NPR::Entity::MP3
|
9
|
+
shallow_attribute "wm", "rm", "mediastream"
|
10
|
+
|
11
|
+
#--------------------
|
12
|
+
|
13
|
+
def initialize(json)
|
14
|
+
extract_shallow_attributes(json)
|
15
|
+
create_relations(json)
|
16
|
+
end
|
17
|
+
end # Formats
|
18
|
+
end # Entity
|
19
|
+
end # NPR
|
@@ -0,0 +1,33 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Image
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Image < Base
|
7
|
+
attr_accessor :id, :type, :width, :src, :hasBorder, :link
|
8
|
+
shallow_attribute "title", "caption", "producer", "copyright"
|
9
|
+
has_many "crops", :key => "crop", :class_name => NPR::Entity::Crop
|
10
|
+
has_one "enlargement", :class_name => NPR::Entity::Enlargement
|
11
|
+
has_one "provider", :class_name => NPR::Entity::Provider
|
12
|
+
|
13
|
+
#-------------
|
14
|
+
# NOTE that the "link" attribute here is not cast into a Link
|
15
|
+
# object, and the "url" parameter is ignored. Instead, just
|
16
|
+
# calling +image.link+ will return the URL parameter.
|
17
|
+
def initialize(json)
|
18
|
+
@id = json["id"].to_i
|
19
|
+
@type = json["type"]
|
20
|
+
@width = json["width"].to_i
|
21
|
+
@src = json["src"]
|
22
|
+
@hasBorder = json["hasBorder"] == "true"
|
23
|
+
|
24
|
+
if json["link"]
|
25
|
+
@link = json["link"]["url"]
|
26
|
+
end
|
27
|
+
|
28
|
+
extract_shallow_attributes(json)
|
29
|
+
create_relations(json)
|
30
|
+
end
|
31
|
+
end # Image
|
32
|
+
end # Entity
|
33
|
+
end # NPR
|
@@ -0,0 +1,21 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::IntroText
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class IntroText < Base
|
7
|
+
attr_accessor :num, :content
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@num = json["num"].to_i
|
11
|
+
@content = json["$text"]
|
12
|
+
end
|
13
|
+
|
14
|
+
#--------------------
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@content
|
18
|
+
end
|
19
|
+
end # IntroText
|
20
|
+
end # Entity
|
21
|
+
end # NPR
|
@@ -0,0 +1,23 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Link
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Link < Base
|
7
|
+
attr_accessor :type, :content
|
8
|
+
|
9
|
+
#---------------------
|
10
|
+
|
11
|
+
def initialize(json)
|
12
|
+
@content = json["$text"]
|
13
|
+
@type = json["type"]
|
14
|
+
end
|
15
|
+
|
16
|
+
#---------------------
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@content
|
20
|
+
end
|
21
|
+
end # Link
|
22
|
+
end # Entity
|
23
|
+
end # NPR
|
@@ -0,0 +1,28 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::List
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class List < Base
|
7
|
+
#------------------
|
8
|
+
|
9
|
+
has_many "links", :key => "link", :class_name => NPR::Entity::Link
|
10
|
+
has_many "stories", :key => "story", :class_name => NPR::Entity::Story
|
11
|
+
|
12
|
+
#------------------
|
13
|
+
|
14
|
+
shallow_attribute(
|
15
|
+
"title",
|
16
|
+
"teaser",
|
17
|
+
"miniTeaser"
|
18
|
+
)
|
19
|
+
|
20
|
+
#------------------
|
21
|
+
|
22
|
+
def initialize(json)
|
23
|
+
extract_shallow_attributes(json)
|
24
|
+
create_relations(json)
|
25
|
+
end
|
26
|
+
end # List
|
27
|
+
end # Entity
|
28
|
+
end # NPR
|
@@ -0,0 +1,19 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::ListText
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class ListText < Base
|
7
|
+
attr_accessor :id, :tag
|
8
|
+
has_many "paragraphs", :key => "paragraph", :class_name => NPR::Entity::Paragraph
|
9
|
+
|
10
|
+
#-------------------
|
11
|
+
|
12
|
+
def initialize(json)
|
13
|
+
@id = json["id"].to_i
|
14
|
+
@tag = json["tag"]
|
15
|
+
create_relations(json)
|
16
|
+
end
|
17
|
+
end # ListText
|
18
|
+
end # Entity
|
19
|
+
end # NPR
|
@@ -0,0 +1,23 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Member
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Member < Base
|
7
|
+
attr_accessor :id
|
8
|
+
has_one "promoArt", :class_name => NPR::Entity::MemberPromoArt
|
9
|
+
has_one "title", :class_name => NPR::Entity::Title
|
10
|
+
has_one "author", :class_name => NPR::Entity::Author
|
11
|
+
has_one "bookEdition", :class_name => NPR::Entity::PromoArtBookEdition
|
12
|
+
has_one "introText", :class_name => NPR::Entity::IntroText
|
13
|
+
has_one "byline", :class_name => NPR::Entity::MemberByline
|
14
|
+
|
15
|
+
#------------------
|
16
|
+
|
17
|
+
def initialize(json)
|
18
|
+
@id = json["id"].to_i
|
19
|
+
create_relations(json)
|
20
|
+
end
|
21
|
+
end # Member
|
22
|
+
end # Entity
|
23
|
+
end # NPR
|