npr 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -4
- data/CHANGELOG.md +27 -1
- data/README.md +5 -10
- data/lib/npr/api/client.rb +6 -6
- data/lib/npr/api/message.rb +5 -5
- data/lib/npr/api/query_builder.rb +22 -23
- data/lib/npr/api/response.rb +7 -7
- data/lib/npr/concern/attr_typecast.rb +11 -13
- data/lib/npr/concern/links_association.rb +26 -0
- data/lib/npr/concern/relation.rb +17 -17
- data/lib/npr/concern/shallow_attributes.rb +12 -12
- data/lib/npr/configuration.rb +27 -27
- data/lib/npr/entity/audio.rb +3 -4
- data/lib/npr/entity/author.rb +3 -3
- data/lib/npr/entity/base.rb +1 -1
- data/lib/npr/entity/book.rb +2 -2
- data/lib/npr/entity/book_edition.rb +5 -5
- data/lib/npr/entity/byline.rb +4 -3
- data/lib/npr/entity/crop.rb +2 -2
- data/lib/npr/entity/enlargement.rb +2 -2
- data/lib/npr/entity/external_asset.rb +27 -0
- data/lib/npr/entity/formats.rb +2 -2
- data/lib/npr/entity/image.rb +4 -4
- data/lib/npr/entity/intro_text.rb +4 -4
- data/lib/npr/entity/link.rb +3 -3
- data/lib/npr/entity/list.rb +2 -4
- data/lib/npr/entity/list_text.rb +2 -2
- data/lib/npr/entity/member.rb +1 -1
- data/lib/npr/entity/member_byline.rb +2 -2
- data/lib/npr/entity/member_promo_art.rb +2 -2
- data/lib/npr/entity/mp3.rb +4 -4
- data/lib/npr/entity/name.rb +4 -4
- data/lib/npr/entity/organization.rb +2 -2
- data/lib/npr/entity/paragraph.rb +2 -2
- data/lib/npr/entity/parent.rb +23 -0
- data/lib/npr/entity/permissions.rb +14 -1
- data/lib/npr/entity/program.rb +7 -5
- data/lib/npr/entity/promo_art.rb +2 -2
- data/lib/npr/entity/promo_art_book_edition.rb +2 -3
- data/lib/npr/entity/provider.rb +4 -4
- data/lib/npr/entity/pull_quote.rb +1 -1
- data/lib/npr/entity/related_link.rb +4 -4
- data/lib/npr/entity/show.rb +3 -3
- data/lib/npr/entity/story.rb +42 -72
- data/lib/npr/entity/text.rb +7 -7
- data/lib/npr/entity/title.rb +4 -4
- data/lib/npr/entity/transcript.rb +2 -2
- data/lib/npr/errors.rb +1 -1
- data/lib/npr/version.rb +1 -1
- data/lib/npr.rb +3 -0
- data/spec/fixtures/fetch_formats.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/api/client_spec.rb +4 -4
- data/spec/unit/api/message_spec.rb +9 -9
- data/spec/unit/api/query_builder_spec.rb +39 -39
- data/spec/unit/api/response_spec.rb +8 -8
- data/spec/unit/configuration_spec.rb +14 -14
- data/spec/unit/entity/audio_spec.rb +6 -6
- data/spec/unit/entity/author_spec.rb +3 -3
- data/spec/unit/entity/base_spec.rb +19 -19
- data/spec/unit/entity/book_edition_spec.rb +4 -4
- data/spec/unit/entity/book_spec.rb +2 -2
- data/spec/unit/entity/byline_spec.rb +3 -3
- data/spec/unit/entity/collection_spec.rb +1 -1
- data/spec/unit/entity/crop_spec.rb +2 -2
- data/spec/unit/entity/englargement_spec.rb +2 -2
- data/spec/unit/entity/external_assset_spec.rb +39 -0
- data/spec/unit/entity/formats_spec.rb +4 -4
- data/spec/unit/entity/image_spec.rb +7 -7
- data/spec/unit/entity/intro_text_spec.rb +3 -3
- data/spec/unit/entity/link_spec.rb +3 -3
- data/spec/unit/entity/list_spec.rb +3 -3
- data/spec/unit/entity/list_text_spec.rb +3 -3
- data/spec/unit/entity/member_byline_spec.rb +2 -2
- data/spec/unit/entity/member_promo_art_spec.rb +2 -2
- data/spec/unit/entity/member_spec.rb +4 -4
- data/spec/unit/entity/mp3_spec.rb +4 -4
- data/spec/unit/entity/name_spec.rb +3 -3
- data/spec/unit/entity/organization_spec.rb +2 -2
- data/spec/unit/entity/paragraph_spec.rb +3 -3
- data/spec/unit/entity/parent_spec.rb +39 -0
- data/spec/unit/entity/permissions_spec.rb +16 -6
- data/spec/unit/entity/program_spec.rb +7 -3
- data/spec/unit/entity/promo_art_book_edition_spec.rb +2 -2
- data/spec/unit/entity/promo_art_spec.rb +2 -2
- data/spec/unit/entity/pull_quote_spec.rb +2 -2
- data/spec/unit/entity/related_link_spec.rb +7 -7
- data/spec/unit/entity/show_spec.rb +3 -3
- data/spec/unit/entity/story_spec.rb +35 -36
- data/spec/unit/entity/text_spec.rb +4 -4
- data/spec/unit/entity/title_spec.rb +3 -3
- data/spec/unit/entity/transcript_spec.rb +2 -2
- metadata +10 -8
data/lib/npr/entity/audio.rb
CHANGED
@@ -8,18 +8,17 @@ module NPR
|
|
8
8
|
shallow_attribute "title", "duration", "description", "rightsHolder"
|
9
9
|
has_one "permissions", :class_name => NPR::Entity::Permissions
|
10
10
|
has_one "formats", :key => "format", :class_name => NPR::Entity::Formats
|
11
|
-
|
11
|
+
|
12
12
|
#-------------------
|
13
13
|
# +stream+ returns true if "active" is set to "true"
|
14
|
-
#
|
15
14
|
def initialize(json)
|
16
15
|
@id = json["id"].to_i
|
17
16
|
@type = json["type"]
|
18
|
-
|
17
|
+
|
19
18
|
if json["stream"]
|
20
19
|
@stream = json["stream"]["active"] == "true"
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
create_relations(json)
|
24
23
|
extract_shallow_attributes(json)
|
25
24
|
end
|
data/lib/npr/entity/author.rb
CHANGED
@@ -7,13 +7,13 @@ module NPR
|
|
7
7
|
attr_accessor :id, :num
|
8
8
|
shallow_attribute "title"
|
9
9
|
has_one "link", :class_name => NPR::Entity::Link
|
10
|
-
|
10
|
+
|
11
11
|
#-----------------
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(json)
|
14
14
|
@id = json["id"].to_i
|
15
15
|
@num = json["num"].to_i
|
16
|
-
|
16
|
+
|
17
17
|
create_relations(json)
|
18
18
|
extract_shallow_attributes(json)
|
19
19
|
end
|
data/lib/npr/entity/base.rb
CHANGED
data/lib/npr/entity/book.rb
CHANGED
@@ -7,17 +7,17 @@ module NPR
|
|
7
7
|
attr_accessor :id, :format_num
|
8
8
|
shallow_attribute "isbn", "publisher", "pubDate", "pagination", "listPrice"
|
9
9
|
has_one "book", :class_name => NPR::Entity::Book
|
10
|
-
|
10
|
+
|
11
11
|
#---------------------
|
12
|
-
# Note that the "format" property is represented on this
|
12
|
+
# Note that the "format" property is represented on this
|
13
13
|
# object as "format_num", because of Kernel's "format"
|
14
14
|
def initialize(json)
|
15
|
-
@id
|
16
|
-
|
15
|
+
@id = json["id"].to_i
|
16
|
+
|
17
17
|
if json["format"]
|
18
18
|
@format_num = json["format"]["$text"].to_i
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
extract_shallow_attributes(json)
|
22
22
|
create_relations(json)
|
23
23
|
end
|
data/lib/npr/entity/byline.rb
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
module NPR
|
5
5
|
module Entity
|
6
6
|
class Byline < Base
|
7
|
+
include NPR::Concern::LinksAssociation
|
8
|
+
|
7
9
|
attr_accessor :id
|
8
|
-
has_many "links", :key => "link", :class_name => NPR::Entity::Link
|
9
10
|
has_one "name", :class_name => NPR::Entity::Name
|
10
|
-
|
11
|
+
|
11
12
|
#-----------------
|
12
|
-
|
13
|
+
|
13
14
|
def initialize(json)
|
14
15
|
@id = json["id"].to_i
|
15
16
|
create_relations(json)
|
data/lib/npr/entity/crop.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::ExternalAsset
|
3
|
+
#
|
4
|
+
# Audio permissions
|
5
|
+
#
|
6
|
+
module NPR
|
7
|
+
module Entity
|
8
|
+
class ExternalAsset < Base
|
9
|
+
attr_accessor :id, :type
|
10
|
+
|
11
|
+
shallow_attribute \
|
12
|
+
"url",
|
13
|
+
"oEmbed",
|
14
|
+
"externalId",
|
15
|
+
"credit",
|
16
|
+
"parameters",
|
17
|
+
"caption"
|
18
|
+
|
19
|
+
def initialize(json)
|
20
|
+
@id = json["id"].to_i
|
21
|
+
@type = json["type"]
|
22
|
+
|
23
|
+
extract_shallow_attributes(json)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/npr/entity/formats.rb
CHANGED
@@ -7,9 +7,9 @@ module NPR
|
|
7
7
|
class Formats < Base
|
8
8
|
has_many "mp3s", :key => "mp3", :class_name => NPR::Entity::MP3
|
9
9
|
shallow_attribute "wm", "rm", "mediastream"
|
10
|
-
|
10
|
+
|
11
11
|
#--------------------
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(json)
|
14
14
|
extract_shallow_attributes(json)
|
15
15
|
create_relations(json)
|
data/lib/npr/entity/image.rb
CHANGED
@@ -12,7 +12,7 @@ module NPR
|
|
12
12
|
|
13
13
|
|
14
14
|
# NOTE that the "link" attribute here is not cast into a Link
|
15
|
-
# object, and the "url" parameter is ignored. Instead, just
|
15
|
+
# object, and the "url" parameter is ignored. Instead, just
|
16
16
|
# calling +image.link+ will return the URL parameter.
|
17
17
|
def initialize(json)
|
18
18
|
@id = json["id"].to_i
|
@@ -20,18 +20,18 @@ module NPR
|
|
20
20
|
@width = json["width"].to_i
|
21
21
|
@src = json["src"]
|
22
22
|
@hasBorder = json["hasBorder"] == "true"
|
23
|
-
|
23
|
+
|
24
24
|
if json["link"]
|
25
25
|
@link = json["link"]["url"]
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
extract_shallow_attributes(json)
|
29
29
|
create_relations(json)
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
33
|
# Find a crop by its type.
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# Arguments:
|
36
36
|
#
|
37
37
|
# * (String) type - the type of crop you're looking for
|
@@ -5,14 +5,14 @@ module NPR
|
|
5
5
|
module Entity
|
6
6
|
class IntroText < Base
|
7
7
|
attr_accessor :num, :content
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(json)
|
10
10
|
@num = json["num"].to_i
|
11
|
-
@content = json["$text"]
|
11
|
+
@content = json["$text"]
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
#--------------------
|
15
|
-
|
15
|
+
|
16
16
|
def to_s
|
17
17
|
@content.to_s
|
18
18
|
end
|
data/lib/npr/entity/link.rb
CHANGED
@@ -5,16 +5,16 @@ module NPR
|
|
5
5
|
module Entity
|
6
6
|
class Link < Base
|
7
7
|
attr_accessor :type, :content
|
8
|
-
|
8
|
+
|
9
9
|
#---------------------
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@content = json["$text"]
|
13
13
|
@type = json["type"]
|
14
14
|
end
|
15
15
|
|
16
16
|
#---------------------
|
17
|
-
|
17
|
+
|
18
18
|
def to_s
|
19
19
|
@content.to_s
|
20
20
|
end
|
data/lib/npr/entity/list.rb
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
module NPR
|
5
5
|
module Entity
|
6
6
|
class List < Base
|
7
|
-
|
8
|
-
|
9
|
-
has_many "links", :key => "link", :class_name => NPR::Entity::Link
|
7
|
+
include NPR::Concern::LinksAssociation
|
10
8
|
has_many "stories", :key => "story", :class_name => NPR::Entity::Story
|
11
9
|
|
12
10
|
#------------------
|
@@ -18,7 +16,7 @@ module NPR
|
|
18
16
|
)
|
19
17
|
|
20
18
|
#------------------
|
21
|
-
|
19
|
+
|
22
20
|
def initialize(json)
|
23
21
|
extract_shallow_attributes(json)
|
24
22
|
create_relations(json)
|
data/lib/npr/entity/list_text.rb
CHANGED
data/lib/npr/entity/member.rb
CHANGED
data/lib/npr/entity/mp3.rb
CHANGED
@@ -5,16 +5,16 @@ module NPR
|
|
5
5
|
module Entity
|
6
6
|
class MP3 < Base
|
7
7
|
attr_accessor :type, :content
|
8
|
-
|
8
|
+
|
9
9
|
#-----------------
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@type = json["type"]
|
13
13
|
@content = json["$text"]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
#-----------------
|
17
|
-
|
17
|
+
|
18
18
|
def to_s
|
19
19
|
@content.to_s
|
20
20
|
end
|
data/lib/npr/entity/name.rb
CHANGED
@@ -7,16 +7,16 @@ module NPR
|
|
7
7
|
module Entity
|
8
8
|
class Name < Base
|
9
9
|
attr_accessor :personId, :content
|
10
|
-
|
10
|
+
|
11
11
|
#-------------------
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(json)
|
14
14
|
@personId = json["personId"].to_i
|
15
15
|
@content = json["$text"]
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
#-------------------
|
19
|
-
|
19
|
+
|
20
20
|
def to_s
|
21
21
|
@content.to_s
|
22
22
|
end
|
data/lib/npr/entity/paragraph.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
##
|
2
|
+
# NPR::Entity::Parent
|
3
|
+
#
|
4
|
+
module NPR
|
5
|
+
module Entity
|
6
|
+
class Parent < Base
|
7
|
+
include NPR::Concern::LinksAssociation
|
8
|
+
|
9
|
+
attr_accessor :id, :type
|
10
|
+
shallow_attribute "title"
|
11
|
+
|
12
|
+
#-------------------
|
13
|
+
|
14
|
+
def initialize(json)
|
15
|
+
@id = json["id"].to_i
|
16
|
+
@type = json["type"]
|
17
|
+
|
18
|
+
extract_shallow_attributes(json)
|
19
|
+
create_relations(json)
|
20
|
+
end
|
21
|
+
end # Program
|
22
|
+
end # Entity
|
23
|
+
end # NPR
|
@@ -7,12 +7,25 @@ module NPR
|
|
7
7
|
module Entity
|
8
8
|
class Permissions < Base
|
9
9
|
attr_accessor :download, :stream, :embed
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@download = json["download"]["allow"] == "true" if json["download"]
|
13
13
|
@stream = json["stream"]["allow"] == "true" if json["stream"]
|
14
14
|
@embed = json["embed"]["allow"] == "true" if json["embed"]
|
15
15
|
end
|
16
|
+
|
17
|
+
|
18
|
+
def download?
|
19
|
+
!!@download
|
20
|
+
end
|
21
|
+
|
22
|
+
def stream?
|
23
|
+
!!@stream
|
24
|
+
end
|
25
|
+
|
26
|
+
def embed?
|
27
|
+
!!@embed
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
18
31
|
end
|
data/lib/npr/entity/program.rb
CHANGED
@@ -6,19 +6,21 @@ module NPR
|
|
6
6
|
class Program < Base
|
7
7
|
attr_accessor :id, :code, :content
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
#-------------------
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@id = json["id"].to_i
|
13
13
|
@content = json["$text"]
|
14
14
|
@code = json["code"]
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
def
|
17
|
+
#-------------------
|
18
|
+
|
19
|
+
def title
|
20
20
|
@content.to_s
|
21
21
|
end
|
22
|
+
|
23
|
+
alias_method :to_s, :title
|
22
24
|
end # Program
|
23
25
|
end # Entity
|
24
26
|
end # NPR
|
data/lib/npr/entity/promo_art.rb
CHANGED
@@ -5,9 +5,9 @@ module NPR
|
|
5
5
|
module Entity
|
6
6
|
class PromoArtBookEdition < Base
|
7
7
|
attr_accessor :refId, :num
|
8
|
-
|
8
|
+
|
9
9
|
#-------------------
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@refId = json["refId"].to_i
|
13
13
|
@num = json["num"].to_i
|
@@ -15,4 +15,3 @@ module NPR
|
|
15
15
|
end # PromoArtBookEdition
|
16
16
|
end # Entity
|
17
17
|
end # NPR
|
18
|
-
|
data/lib/npr/entity/provider.rb
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
#
|
4
4
|
module NPR
|
5
5
|
module Entity
|
6
|
-
class Provider < Base
|
6
|
+
class Provider < Base
|
7
7
|
attr_accessor :content, :url
|
8
8
|
|
9
9
|
#----------------
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(json)
|
12
12
|
@content = json["$text"]
|
13
13
|
@url = json["url"]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
#----------------
|
17
|
-
|
17
|
+
|
18
18
|
def to_s
|
19
19
|
@content.to_s
|
20
20
|
end
|
@@ -4,15 +4,15 @@
|
|
4
4
|
module NPR
|
5
5
|
module Entity
|
6
6
|
class RelatedLink < Base
|
7
|
+
include NPR::Concern::LinksAssociation
|
8
|
+
|
7
9
|
attr_accessor :id, :type
|
8
|
-
|
9
|
-
has_many "links", :key => "link", :class_name => NPR::Entity::Link
|
10
10
|
shallow_attribute "caption"
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(json)
|
13
13
|
extract_shallow_attributes(json)
|
14
14
|
create_relations(json)
|
15
|
-
|
15
|
+
|
16
16
|
@id = json["id"].to_i
|
17
17
|
@type = json["type"]
|
18
18
|
end
|
data/lib/npr/entity/show.rb
CHANGED
@@ -6,13 +6,13 @@ module NPR
|
|
6
6
|
class Show < Base
|
7
7
|
attr_accessor :program
|
8
8
|
shallow_attribute "showDate", "segNum"
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(json)
|
11
11
|
extract_shallow_attributes(json)
|
12
|
-
|
12
|
+
|
13
13
|
if program = json["program"]
|
14
14
|
@program = NPR::Entity::Program.new(program)
|
15
|
-
end
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end # Show
|
18
18
|
end # Entity
|