apple-news 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +4 -0
  6. data/README.md +138 -0
  7. data/Rakefile +6 -0
  8. data/apple-news.gemspec +28 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/apple-news.rb +41 -0
  12. data/lib/apple-news/addition.rb +7 -0
  13. data/lib/apple-news/additions/base.rb +15 -0
  14. data/lib/apple-news/additions/link.rb +9 -0
  15. data/lib/apple-news/animation.rb +7 -0
  16. data/lib/apple-news/animations/appear.rb +7 -0
  17. data/lib/apple-news/animations/base.rb +17 -0
  18. data/lib/apple-news/animations/fade_in.rb +8 -0
  19. data/lib/apple-news/animations/move_in.rb +8 -0
  20. data/lib/apple-news/animations/scale_fade.rb +8 -0
  21. data/lib/apple-news/article.rb +33 -0
  22. data/lib/apple-news/behavior.rb +7 -0
  23. data/lib/apple-news/behaviors/background_motion.rb +7 -0
  24. data/lib/apple-news/behaviors/background_parallax.rb +7 -0
  25. data/lib/apple-news/behaviors/base.rb +15 -0
  26. data/lib/apple-news/behaviors/motion.rb +7 -0
  27. data/lib/apple-news/behaviors/parallax.rb +8 -0
  28. data/lib/apple-news/behaviors/springy.rb +7 -0
  29. data/lib/apple-news/channel.rb +40 -0
  30. data/lib/apple-news/component.rb +28 -0
  31. data/lib/apple-news/component_layout.rb +9 -0
  32. data/lib/apple-news/components/audio.rb +16 -0
  33. data/lib/apple-news/components/author.rb +8 -0
  34. data/lib/apple-news/components/banner_advertisement.rb +14 -0
  35. data/lib/apple-news/components/base.rb +17 -0
  36. data/lib/apple-news/components/body.rb +8 -0
  37. data/lib/apple-news/components/byline.rb +8 -0
  38. data/lib/apple-news/components/caption.rb +8 -0
  39. data/lib/apple-news/components/chapter.rb +10 -0
  40. data/lib/apple-news/components/container.rb +8 -0
  41. data/lib/apple-news/components/divider.rb +8 -0
  42. data/lib/apple-news/components/embed_web_video.rb +12 -0
  43. data/lib/apple-news/components/figure.rb +8 -0
  44. data/lib/apple-news/components/gallery.rb +8 -0
  45. data/lib/apple-news/components/header.rb +7 -0
  46. data/lib/apple-news/components/heading.rb +8 -0
  47. data/lib/apple-news/components/illustrator.rb +8 -0
  48. data/lib/apple-news/components/image.rb +14 -0
  49. data/lib/apple-news/components/instagram.rb +9 -0
  50. data/lib/apple-news/components/intro.rb +8 -0
  51. data/lib/apple-news/components/logo.rb +8 -0
  52. data/lib/apple-news/components/medium_rectangle_advertisement.rb +7 -0
  53. data/lib/apple-news/components/mosaic.rb +8 -0
  54. data/lib/apple-news/components/music.rb +8 -0
  55. data/lib/apple-news/components/photo.rb +8 -0
  56. data/lib/apple-news/components/photographer.rb +8 -0
  57. data/lib/apple-news/components/portrait.rb +8 -0
  58. data/lib/apple-news/components/pullquote.rb +8 -0
  59. data/lib/apple-news/components/quote.rb +8 -0
  60. data/lib/apple-news/components/scalable_image.rb +14 -0
  61. data/lib/apple-news/components/section.rb +8 -0
  62. data/lib/apple-news/components/text.rb +13 -0
  63. data/lib/apple-news/components/title.rb +8 -0
  64. data/lib/apple-news/components/tweet.rb +9 -0
  65. data/lib/apple-news/components/video.rb +12 -0
  66. data/lib/apple-news/configuration.rb +12 -0
  67. data/lib/apple-news/document.rb +22 -0
  68. data/lib/apple-news/document/attachments.rb +24 -0
  69. data/lib/apple-news/document/metadata.rb +43 -0
  70. data/lib/apple-news/document/persistence.rb +42 -0
  71. data/lib/apple-news/layout.rb +8 -0
  72. data/lib/apple-news/links.rb +19 -0
  73. data/lib/apple-news/metadata.rb +15 -0
  74. data/lib/apple-news/multipart_post_patch.rb +29 -0
  75. data/lib/apple-news/properties.rb +87 -0
  76. data/lib/apple-news/properties/advertising_layout.rb +7 -0
  77. data/lib/apple-news/properties/advertising_settings.rb +7 -0
  78. data/lib/apple-news/properties/anchor.rb +15 -0
  79. data/lib/apple-news/properties/base.rb +7 -0
  80. data/lib/apple-news/properties/caption_descriptor.rb +8 -0
  81. data/lib/apple-news/properties/color_stop.rb +8 -0
  82. data/lib/apple-news/properties/content_inset.rb +7 -0
  83. data/lib/apple-news/properties/gallery_item.rb +7 -0
  84. data/lib/apple-news/properties/margin.rb +7 -0
  85. data/lib/apple-news/properties/offset.rb +7 -0
  86. data/lib/apple-news/property.rb +7 -0
  87. data/lib/apple-news/request.rb +6 -0
  88. data/lib/apple-news/requests/get.rb +28 -0
  89. data/lib/apple-news/requests/post.rb +57 -0
  90. data/lib/apple-news/resource.rb +25 -0
  91. data/lib/apple-news/scene.rb +7 -0
  92. data/lib/apple-news/scenes/base.rb +15 -0
  93. data/lib/apple-news/scenes/fading_sticky_header.rb +8 -0
  94. data/lib/apple-news/scenes/parallax_scale_header.rb +7 -0
  95. data/lib/apple-news/section.rb +27 -0
  96. data/lib/apple-news/security.rb +46 -0
  97. data/lib/apple-news/style.rb +10 -0
  98. data/lib/apple-news/styles/base.rb +7 -0
  99. data/lib/apple-news/styles/border.rb +7 -0
  100. data/lib/apple-news/styles/component.rb +7 -0
  101. data/lib/apple-news/styles/component_text.rb +9 -0
  102. data/lib/apple-news/styles/document.rb +7 -0
  103. data/lib/apple-news/styles/drop_cap.rb +9 -0
  104. data/lib/apple-news/styles/fill.rb +11 -0
  105. data/lib/apple-news/styles/gradient_fill.rb +12 -0
  106. data/lib/apple-news/styles/image_fill.rb +11 -0
  107. data/lib/apple-news/styles/inline_text.rb +7 -0
  108. data/lib/apple-news/styles/linear_gradient_fill.rb +9 -0
  109. data/lib/apple-news/styles/shadow.rb +8 -0
  110. data/lib/apple-news/styles/stroke.rb +7 -0
  111. data/lib/apple-news/styles/text.rb +8 -0
  112. data/lib/apple-news/styles/text_stroke.rb +8 -0
  113. data/lib/apple-news/styles/video_fill.rb +12 -0
  114. data/lib/apple-news/version.rb +3 -0
  115. metadata +241 -0
@@ -0,0 +1,7 @@
1
+ module AppleNews
2
+ module Behavior
3
+ class Motion < Base
4
+ type "motion"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Behavior
3
+ class Parallax < Base
4
+ type "parallax"
5
+ optional_property :factor
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module AppleNews
2
+ module Behavior
3
+ class Springy < Base
4
+ type "springy"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ module AppleNews
2
+ class Channel
3
+ include Resource
4
+ include Links
5
+
6
+ attr_reader :id, :type, :name, :website, :links, :created_at, :modified_at,
7
+ :default_section
8
+
9
+ def self.current
10
+ self.new(AppleNews.config.channel_id)
11
+ end
12
+
13
+ def initialize(id, data = nil)
14
+ @id = id
15
+ @url = "/channels/#{id}"
16
+
17
+ data.nil? ? hydrate! : process_data(data)
18
+ end
19
+
20
+ def default_section
21
+ Section.new(section_link_id('defaultSection'))
22
+ end
23
+
24
+ def sections
25
+ request = Request::Get.new("/channels/#{id}/sections")
26
+ resp = request.call
27
+ resp['data'].map do |section|
28
+ Section.new(section['id'], section)
29
+ end
30
+ end
31
+
32
+ def articles(params = {})
33
+ request = Request::Get.new("/channels/#{id}/articles")
34
+ resp = request.call(params)
35
+ resp['data'].map do |article|
36
+ Article.new(article['id'], article)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ require "apple-news/components/base"
2
+ require "apple-news/components/text"
3
+ require "apple-news/components/audio"
4
+ require "apple-news/components/image"
5
+ require "apple-news/components/scalable_image"
6
+ Dir["#{File.dirname(__FILE__)}/components/*.rb"].each { |path| require path }
7
+
8
+ module AppleNews
9
+ module Component
10
+ extend self
11
+
12
+ def factory(data)
13
+ components.each do |component|
14
+ if component.role == data[:role]
15
+ return component.new(data)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def components
23
+ @components ||= self.constants.
24
+ map { |const| self.const_get(const) }.
25
+ select { |const| const.name.demodulize != "Base" && const.is_a?(Class) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module AppleNews
2
+ class ComponentLayout
3
+ include Properties
4
+
5
+ optional_properties :column_span, :column_start, :content_inset, :horizontal_content_alignment,
6
+ :ignore_document_gutter, :ignore_document_margin, :margin,
7
+ :maximum_content_width, :minimum_height
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module AppleNews
2
+ module Component
3
+ module Audio
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ role "audio"
8
+ required_property :url
9
+ optional_properties :accessibility_caption, :caption, :explicit_content, :image_url
10
+
11
+ property_inflection :url, 'URL'
12
+ property_inflection :image_url, 'imageURL'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Author < Base
4
+ include Text
5
+ role "author"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module AppleNews
2
+ module Component
3
+ class BannerAdvertisement < Base
4
+ role "banner_advertisement"
5
+ optional_property :banner_type, "any"
6
+
7
+ def valid?
8
+ super && [
9
+ 'any', 'standard', 'double_height', 'large'
10
+ ].include?(banner_type)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module AppleNews
2
+ module Component
3
+ class Base
4
+ include Properties
5
+
6
+ optional_properties :identifier, :layout, :style
7
+
8
+ def self.role(val = nil)
9
+ val.nil? ? _required_property_map[:role] : required_property(:role, val)
10
+ end
11
+
12
+ def role
13
+ self.class.role
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Body < Base
4
+ include Text
5
+ role "body"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Byline < Base
4
+ include Text
5
+ role "byline"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Caption < Base
4
+ include Text
5
+ role "caption"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'apple-news/components/container'
2
+
3
+ module AppleNews
4
+ module Component
5
+ class Chapter < Container
6
+ role "chapter"
7
+ optional_property :scene
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Container < Base
4
+ role "container"
5
+ optional_property :components, []
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Divider < Base
4
+ role "divider"
5
+ optional_property :stroke
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module AppleNews
2
+ module Component
3
+ class EmbedWebVideo < Base
4
+ role "embedwebvideo"
5
+ required_property :url
6
+ optional_properties :accessibility_caption, :aspect_ratio, :caption,
7
+ :explicit_content
8
+
9
+ property_inflection :url, 'URL'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Figure < Base
4
+ include ScalableImage
5
+ role "figure"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Gallery < Base
4
+ role "gallery"
5
+ required_property :items, []
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module AppleNews
2
+ module Component
3
+ class Header < Container
4
+ role "header"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Heading < Base
4
+ include Text
5
+ role "heading"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Illustrator < Base
4
+ include Text
5
+ role "illustrator"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module AppleNews
2
+ module Component
3
+ module Image
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ required_property :url
8
+ optional_properties :accessibility_caption, :caption, :explicit_content
9
+
10
+ property_inflection :url, 'URL'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module AppleNews
2
+ module Component
3
+ class Instagram < Base
4
+ role "instagram"
5
+ required_property :url
6
+ property_inflection :url, 'URL'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Intro < Base
4
+ include Text
5
+ role "intro"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Logo < Base
4
+ include Image
5
+ role "logo"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module AppleNews
2
+ module Component
3
+ class MediumRectangleAdvertisement < Base
4
+ role "medium_rectangle_advertisement"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Mosaic < Base
4
+ role "mosaic"
5
+ required_property :items, []
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Music < Base
4
+ include Audio
5
+ role "music"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Photo < Base
4
+ include ScalableImage
5
+ role "photo"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Photographer < Base
4
+ include Text
5
+ role "photographer"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Portrait < Base
4
+ include ScalableImage
5
+ role "portrait"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Pullquote < Base
4
+ include Text
5
+ role "pullquote"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Quote < Base
4
+ include Text
5
+ role "quote"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module AppleNews
2
+ module Component
3
+ module ScalableImage
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ required_property :url
8
+ optional_properties :accessibility_caption, :caption, :explicit_content
9
+
10
+ property_inflection :url, 'URL'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module AppleNews
2
+ module Component
3
+ class Section < Container
4
+ role "section"
5
+ optional_property :scene
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module AppleNews
2
+ module Component
3
+ module Text
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ required_property :text
8
+ optional_properties :anchor, :animation, :behavior, :format,
9
+ :inlineTextStyles, :textStyle
10
+ end
11
+ end
12
+ end
13
+ end