npr 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.travis.yml +1 -4
  2. data/CHANGELOG.md +27 -1
  3. data/README.md +5 -10
  4. data/lib/npr/api/client.rb +6 -6
  5. data/lib/npr/api/message.rb +5 -5
  6. data/lib/npr/api/query_builder.rb +22 -23
  7. data/lib/npr/api/response.rb +7 -7
  8. data/lib/npr/concern/attr_typecast.rb +11 -13
  9. data/lib/npr/concern/links_association.rb +26 -0
  10. data/lib/npr/concern/relation.rb +17 -17
  11. data/lib/npr/concern/shallow_attributes.rb +12 -12
  12. data/lib/npr/configuration.rb +27 -27
  13. data/lib/npr/entity/audio.rb +3 -4
  14. data/lib/npr/entity/author.rb +3 -3
  15. data/lib/npr/entity/base.rb +1 -1
  16. data/lib/npr/entity/book.rb +2 -2
  17. data/lib/npr/entity/book_edition.rb +5 -5
  18. data/lib/npr/entity/byline.rb +4 -3
  19. data/lib/npr/entity/crop.rb +2 -2
  20. data/lib/npr/entity/enlargement.rb +2 -2
  21. data/lib/npr/entity/external_asset.rb +27 -0
  22. data/lib/npr/entity/formats.rb +2 -2
  23. data/lib/npr/entity/image.rb +4 -4
  24. data/lib/npr/entity/intro_text.rb +4 -4
  25. data/lib/npr/entity/link.rb +3 -3
  26. data/lib/npr/entity/list.rb +2 -4
  27. data/lib/npr/entity/list_text.rb +2 -2
  28. data/lib/npr/entity/member.rb +1 -1
  29. data/lib/npr/entity/member_byline.rb +2 -2
  30. data/lib/npr/entity/member_promo_art.rb +2 -2
  31. data/lib/npr/entity/mp3.rb +4 -4
  32. data/lib/npr/entity/name.rb +4 -4
  33. data/lib/npr/entity/organization.rb +2 -2
  34. data/lib/npr/entity/paragraph.rb +2 -2
  35. data/lib/npr/entity/parent.rb +23 -0
  36. data/lib/npr/entity/permissions.rb +14 -1
  37. data/lib/npr/entity/program.rb +7 -5
  38. data/lib/npr/entity/promo_art.rb +2 -2
  39. data/lib/npr/entity/promo_art_book_edition.rb +2 -3
  40. data/lib/npr/entity/provider.rb +4 -4
  41. data/lib/npr/entity/pull_quote.rb +1 -1
  42. data/lib/npr/entity/related_link.rb +4 -4
  43. data/lib/npr/entity/show.rb +3 -3
  44. data/lib/npr/entity/story.rb +42 -72
  45. data/lib/npr/entity/text.rb +7 -7
  46. data/lib/npr/entity/title.rb +4 -4
  47. data/lib/npr/entity/transcript.rb +2 -2
  48. data/lib/npr/errors.rb +1 -1
  49. data/lib/npr/version.rb +1 -1
  50. data/lib/npr.rb +3 -0
  51. data/spec/fixtures/fetch_formats.rb +4 -4
  52. data/spec/spec_helper.rb +1 -1
  53. data/spec/unit/api/client_spec.rb +4 -4
  54. data/spec/unit/api/message_spec.rb +9 -9
  55. data/spec/unit/api/query_builder_spec.rb +39 -39
  56. data/spec/unit/api/response_spec.rb +8 -8
  57. data/spec/unit/configuration_spec.rb +14 -14
  58. data/spec/unit/entity/audio_spec.rb +6 -6
  59. data/spec/unit/entity/author_spec.rb +3 -3
  60. data/spec/unit/entity/base_spec.rb +19 -19
  61. data/spec/unit/entity/book_edition_spec.rb +4 -4
  62. data/spec/unit/entity/book_spec.rb +2 -2
  63. data/spec/unit/entity/byline_spec.rb +3 -3
  64. data/spec/unit/entity/collection_spec.rb +1 -1
  65. data/spec/unit/entity/crop_spec.rb +2 -2
  66. data/spec/unit/entity/englargement_spec.rb +2 -2
  67. data/spec/unit/entity/external_assset_spec.rb +39 -0
  68. data/spec/unit/entity/formats_spec.rb +4 -4
  69. data/spec/unit/entity/image_spec.rb +7 -7
  70. data/spec/unit/entity/intro_text_spec.rb +3 -3
  71. data/spec/unit/entity/link_spec.rb +3 -3
  72. data/spec/unit/entity/list_spec.rb +3 -3
  73. data/spec/unit/entity/list_text_spec.rb +3 -3
  74. data/spec/unit/entity/member_byline_spec.rb +2 -2
  75. data/spec/unit/entity/member_promo_art_spec.rb +2 -2
  76. data/spec/unit/entity/member_spec.rb +4 -4
  77. data/spec/unit/entity/mp3_spec.rb +4 -4
  78. data/spec/unit/entity/name_spec.rb +3 -3
  79. data/spec/unit/entity/organization_spec.rb +2 -2
  80. data/spec/unit/entity/paragraph_spec.rb +3 -3
  81. data/spec/unit/entity/parent_spec.rb +39 -0
  82. data/spec/unit/entity/permissions_spec.rb +16 -6
  83. data/spec/unit/entity/program_spec.rb +7 -3
  84. data/spec/unit/entity/promo_art_book_edition_spec.rb +2 -2
  85. data/spec/unit/entity/promo_art_spec.rb +2 -2
  86. data/spec/unit/entity/pull_quote_spec.rb +2 -2
  87. data/spec/unit/entity/related_link_spec.rb +7 -7
  88. data/spec/unit/entity/show_spec.rb +3 -3
  89. data/spec/unit/entity/story_spec.rb +35 -36
  90. data/spec/unit/entity/text_spec.rb +4 -4
  91. data/spec/unit/entity/title_spec.rb +3 -3
  92. data/spec/unit/entity/transcript_spec.rb +2 -2
  93. metadata +10 -8
@@ -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
@@ -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
@@ -8,7 +8,7 @@ module NPR
8
8
  class Base
9
9
  include NPR::Concern::Relation
10
10
  include NPR::Concern::ShallowAttributes
11
-
11
+
12
12
  #-----------------
13
13
  # Override this
14
14
  def initialize(json={})
@@ -7,9 +7,9 @@ module NPR
7
7
  attr_accessor :id
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
 
@@ -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 = json["id"].to_i
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
@@ -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)
@@ -5,9 +5,9 @@ module NPR
5
5
  module Entity
6
6
  class Crop < Base
7
7
  attr_accessor :type, :src, :width, :height
8
-
8
+
9
9
  #---------------
10
-
10
+
11
11
  def initialize(json)
12
12
  @type = json["type"]
13
13
  @src = json["src"]
@@ -6,9 +6,9 @@ module NPR
6
6
  class Enlargement < Base
7
7
  attr_accessor :src
8
8
  shallow_attribute "caption"
9
-
9
+
10
10
  #---------------
11
-
11
+
12
12
  def initialize(json)
13
13
  @src = json["src"]
14
14
  extract_shallow_attributes(json)
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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)
@@ -6,9 +6,9 @@ module NPR
6
6
  class ListText < Base
7
7
  attr_accessor :id, :tag
8
8
  has_many "paragraphs", :key => "paragraph", :class_name => NPR::Entity::Paragraph
9
-
9
+
10
10
  #-------------------
11
-
11
+
12
12
  def initialize(json)
13
13
  @id = json["id"].to_i
14
14
  @tag = json["tag"]
@@ -13,7 +13,7 @@ module NPR
13
13
  has_one "byline", :class_name => NPR::Entity::MemberByline
14
14
 
15
15
  #------------------
16
-
16
+
17
17
  def initialize(json)
18
18
  @id = json["id"].to_i
19
19
  create_relations(json)
@@ -5,9 +5,9 @@ module NPR
5
5
  module Entity
6
6
  class MemberByline < 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
@@ -5,9 +5,9 @@ module NPR
5
5
  module Entity
6
6
  class MemberPromoArt < 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
@@ -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
@@ -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
@@ -6,10 +6,10 @@ module NPR
6
6
  class Organization < Base
7
7
  attr_accessor :orgId, :orgAbbr
8
8
  shallow_attribute "name", "website"
9
-
9
+
10
10
  def initialize(json)
11
11
  extract_shallow_attributes(json)
12
-
12
+
13
13
  @orgId = json["orgId"].to_i
14
14
  @orgAbbr = json["orgAbbr"]
15
15
  end
@@ -11,14 +11,14 @@ module NPR
11
11
  attr_accessor :num, :content
12
12
 
13
13
  #---------------------
14
-
14
+
15
15
  def initialize(json)
16
16
  @content = json["$text"]
17
17
  @num = json["num"].to_i
18
18
  end
19
19
 
20
20
  #---------------------
21
-
21
+
22
22
  def to_s
23
23
  @content.to_s
24
24
  end
@@ -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
@@ -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 to_s
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
@@ -5,9 +5,9 @@ module NPR
5
5
  module Entity
6
6
  class PromoArt < Image
7
7
  attr_accessor :bookEditionId
8
-
8
+
9
9
  #--------------------
10
-
10
+
11
11
  def initialize(json)
12
12
  @bookEditionId = json["bookEditionId"].to_i
13
13
  super
@@ -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
-
@@ -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
@@ -6,7 +6,7 @@ module NPR
6
6
  class PullQuote < Base
7
7
  attr_accessor :id
8
8
  shallow_attribute "text", "person", "date"
9
-
9
+
10
10
  def initialize(json)
11
11
  extract_shallow_attributes(json)
12
12
  @id = json["id"].to_i
@@ -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
@@ -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