agave-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +14 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/CONTRIBUTORS.md +34 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE.txt +29 -0
  8. data/README.md +41 -0
  9. data/Rakefile +7 -0
  10. data/agave-client.gemspec +63 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/exe/agave +10 -0
  14. data/lib/agave.rb +11 -0
  15. data/lib/agave/api_client.rb +97 -0
  16. data/lib/agave/api_error.rb +23 -0
  17. data/lib/agave/cli.rb +93 -0
  18. data/lib/agave/dump/dsl/add_to_data_file.rb +14 -0
  19. data/lib/agave/dump/dsl/create_data_file.rb +14 -0
  20. data/lib/agave/dump/dsl/create_post.rb +33 -0
  21. data/lib/agave/dump/dsl/directory.rb +30 -0
  22. data/lib/agave/dump/dsl/root.rb +37 -0
  23. data/lib/agave/dump/format.rb +28 -0
  24. data/lib/agave/dump/format/json.rb +18 -0
  25. data/lib/agave/dump/format/toml.rb +31 -0
  26. data/lib/agave/dump/format/yaml.rb +55 -0
  27. data/lib/agave/dump/operation/add_to_data_file.rb +41 -0
  28. data/lib/agave/dump/operation/create_data_file.rb +28 -0
  29. data/lib/agave/dump/operation/create_post.rb +34 -0
  30. data/lib/agave/dump/operation/directory.rb +34 -0
  31. data/lib/agave/dump/operation/root.rb +27 -0
  32. data/lib/agave/dump/runner.rb +47 -0
  33. data/lib/agave/dump/ssg_detector.rb +36 -0
  34. data/lib/agave/json_api_deserializer.rb +38 -0
  35. data/lib/agave/json_api_serializer.rb +145 -0
  36. data/lib/agave/local/entities_repo.rb +46 -0
  37. data/lib/agave/local/field_type/boolean.rb +12 -0
  38. data/lib/agave/local/field_type/color.rb +63 -0
  39. data/lib/agave/local/field_type/date.rb +12 -0
  40. data/lib/agave/local/field_type/date_time.rb +12 -0
  41. data/lib/agave/local/field_type/file.rb +65 -0
  42. data/lib/agave/local/field_type/float.rb +12 -0
  43. data/lib/agave/local/field_type/gallery.rb +23 -0
  44. data/lib/agave/local/field_type/global_seo.rb +56 -0
  45. data/lib/agave/local/field_type/image.rb +82 -0
  46. data/lib/agave/local/field_type/integer.rb +12 -0
  47. data/lib/agave/local/field_type/json.rb +13 -0
  48. data/lib/agave/local/field_type/lat_lon.rb +30 -0
  49. data/lib/agave/local/field_type/link.rb +12 -0
  50. data/lib/agave/local/field_type/links.rb +21 -0
  51. data/lib/agave/local/field_type/rich_text.rb +21 -0
  52. data/lib/agave/local/field_type/seo.rb +33 -0
  53. data/lib/agave/local/field_type/slug.rb +12 -0
  54. data/lib/agave/local/field_type/string.rb +12 -0
  55. data/lib/agave/local/field_type/text.rb +12 -0
  56. data/lib/agave/local/field_type/theme.rb +43 -0
  57. data/lib/agave/local/field_type/video.rb +77 -0
  58. data/lib/agave/local/item.rb +179 -0
  59. data/lib/agave/local/items_repo.rb +210 -0
  60. data/lib/agave/local/json_api_entity.rb +78 -0
  61. data/lib/agave/local/loader.rb +60 -0
  62. data/lib/agave/local/site.rb +73 -0
  63. data/lib/agave/paginator.rb +33 -0
  64. data/lib/agave/repo.rb +93 -0
  65. data/lib/agave/site/client.rb +24 -0
  66. data/lib/agave/upload/file.rb +92 -0
  67. data/lib/agave/upload/image.rb +8 -0
  68. data/lib/agave/utils/favicon_tags_builder.rb +85 -0
  69. data/lib/agave/utils/locale_value.rb +15 -0
  70. data/lib/agave/utils/meta_tags/article_modified_time.rb +15 -0
  71. data/lib/agave/utils/meta_tags/article_publisher.rb +18 -0
  72. data/lib/agave/utils/meta_tags/base.rb +55 -0
  73. data/lib/agave/utils/meta_tags/description.rb +24 -0
  74. data/lib/agave/utils/meta_tags/image.rb +35 -0
  75. data/lib/agave/utils/meta_tags/og_locale.rb +15 -0
  76. data/lib/agave/utils/meta_tags/og_site_name.rb +18 -0
  77. data/lib/agave/utils/meta_tags/og_type.rb +18 -0
  78. data/lib/agave/utils/meta_tags/robots.rb +14 -0
  79. data/lib/agave/utils/meta_tags/title.rb +46 -0
  80. data/lib/agave/utils/meta_tags/twitter_card.rb +14 -0
  81. data/lib/agave/utils/meta_tags/twitter_site.rb +18 -0
  82. data/lib/agave/utils/seo_tags_builder.rb +45 -0
  83. data/lib/agave/version.rb +4 -0
  84. data/lib/agave/watch/site_change_watcher.rb +37 -0
  85. metadata +504 -0
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Date
6
+ def self.parse(value, _repo)
7
+ value && ::Date.parse(value)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class DateTime
6
+ def self.parse(value, _repo)
7
+ value && ::Time.parse(value).utc
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ require 'imgix'
3
+
4
+ module Agave
5
+ module Local
6
+ module FieldType
7
+ class File
8
+ attr_reader :path
9
+ attr_reader :format
10
+ attr_reader :size
11
+ attr_reader :title
12
+ attr_reader :alt
13
+ attr_reader :image_host
14
+
15
+ def self.parse(upload_attributes, repo)
16
+ return nil if !upload_attributes
17
+ return nil if !upload_attributes[:path]
18
+ upload = repo.entities_repo.find_entity(
19
+ "upload", upload_attributes[:path]
20
+ )
21
+ return nil if !upload
22
+ new(
23
+ upload.path,
24
+ upload.format,
25
+ upload.size,
26
+ upload.alt,
27
+ upload.title,
28
+ repo.site.entity.image_host
29
+ )
30
+ end
31
+
32
+ def initialize(path, format, size, alt, title, image_host)
33
+ @path = path
34
+ @format = format
35
+ @size = size
36
+ @image_host = image_host
37
+ @alt = alt
38
+ @title = title
39
+ end
40
+
41
+ def file
42
+ Imgix::Client.new(
43
+ host: image_host,
44
+ secure: true,
45
+ include_library_param: false
46
+ ).path(path)
47
+ end
48
+
49
+ def url(opts = {})
50
+ file.to_url(opts)
51
+ end
52
+
53
+ def to_hash(*_args)
54
+ {
55
+ format: format,
56
+ size: size,
57
+ alt: alt,
58
+ title: title,
59
+ url: url
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Float
6
+ def self.parse(value, _repo)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'agave/local/field_type/file'
3
+
4
+ module Agave
5
+ module Local
6
+ module FieldType
7
+ class Gallery < Array
8
+ def self.parse(value, repo)
9
+ images = if value
10
+ value.map { |image| FieldType::File.parse(image, repo) }
11
+ else
12
+ []
13
+ end
14
+ new(images)
15
+ end
16
+
17
+ def to_hash(max_depth = 3, current_depth = 0)
18
+ map { |item| item.to_hash(max_depth, current_depth) }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require 'agave/local/field_type/seo'
3
+
4
+ module Agave
5
+ module Local
6
+ module FieldType
7
+ class GlobalSeo
8
+ attr_reader :site_name
9
+ attr_reader :title_suffix
10
+ attr_reader :twitter_account
11
+ attr_reader :facebook_page_url
12
+
13
+ def self.parse(value, repo)
14
+ value && new(
15
+ value[:site_name],
16
+ value[:title_suffix],
17
+ value[:twitter_account],
18
+ value[:facebook_page_url],
19
+ value[:fallback_seo],
20
+ repo
21
+ )
22
+ end
23
+
24
+ def initialize(
25
+ site_name,
26
+ title_suffix,
27
+ twitter_account,
28
+ facebook_page_url,
29
+ fallback_seo,
30
+ repo
31
+ )
32
+ @site_name = site_name
33
+ @title_suffix = title_suffix
34
+ @twitter_account = twitter_account
35
+ @facebook_page_url = facebook_page_url
36
+ @fallback_seo = fallback_seo
37
+ @repo = repo
38
+ end
39
+
40
+ def fallback_seo
41
+ @fallback_seo && Seo.parse(@fallback_seo, @repo)
42
+ end
43
+
44
+ def to_hash(*args)
45
+ {
46
+ site_name: site_name,
47
+ title_suffix: title_suffix,
48
+ twitter_account: twitter_account,
49
+ facebook_page_url: facebook_page_url,
50
+ fallback_seo: fallback_seo && fallback_seo.to_hash(*args)
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+ require 'imgix'
3
+
4
+ module Agave
5
+ module Local
6
+ module FieldType
7
+ class Image
8
+ attr_reader :path
9
+ attr_reader :format
10
+ attr_reader :size
11
+ attr_reader :width
12
+ attr_reader :height
13
+ attr_reader :title
14
+ attr_reader :alt
15
+ attr_reader :image_host
16
+
17
+ def self.parse(upload_attributes, repo)
18
+ return nil if !upload_attributes
19
+ return nil if !upload_attributes[:path]
20
+ upload = repo.entities_repo.find_entity(
21
+ "upload", upload_attributes[:path]
22
+ )
23
+ return nil if !upload
24
+ new(
25
+ upload.path,
26
+ upload.format,
27
+ upload.size,
28
+ upload.width,
29
+ upload.height,
30
+ upload.alt,
31
+ upload.title,
32
+ repo.site.entity.image_host
33
+ )
34
+ end
35
+
36
+ def initialize(
37
+ path,
38
+ format,
39
+ size,
40
+ width,
41
+ height,
42
+ alt,
43
+ title,
44
+ image_host
45
+ )
46
+ @path = path
47
+ @format = format
48
+ @size = size
49
+ @width = width
50
+ @height = height
51
+ @title = title
52
+ @alt = alt
53
+ @image_host = image_host
54
+ end
55
+
56
+ def file
57
+ Imgix::Client.new(
58
+ host: image_host,
59
+ secure: true,
60
+ include_library_param: false
61
+ ).path(path)
62
+ end
63
+
64
+ def url(opts = {})
65
+ file.to_url(opts)
66
+ end
67
+
68
+ def to_hash(*_args)
69
+ {
70
+ format: format,
71
+ size: size,
72
+ width: width,
73
+ height: height,
74
+ alt: alt,
75
+ title: title,
76
+ url: url
77
+ }
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Integer
6
+ def self.parse(value, _repo)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Json
6
+ def self.parse(value, _repo)
7
+ value && JSON.parse(value)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class LatLon
6
+ attr_reader :latitude, :longitude
7
+
8
+ def self.parse(value, _repo)
9
+ value && new(value[:latitude], value[:longitude])
10
+ end
11
+
12
+ def initialize(latitude, longitude)
13
+ @latitude = latitude
14
+ @longitude = longitude
15
+ end
16
+
17
+ def values
18
+ [latitude, longitude]
19
+ end
20
+
21
+ def to_hash(*_args)
22
+ {
23
+ latitude: latitude,
24
+ longitude: longitude
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Link
6
+ def self.parse(value, repo)
7
+ value && repo.find(value)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Links < Array
6
+ def self.parse(ids, repo)
7
+ items = if ids
8
+ ids.map { |id| repo.find(id) }
9
+ else
10
+ []
11
+ end
12
+ new(items)
13
+ end
14
+
15
+ def to_hash(max_depth = 3, current_depth = 0)
16
+ map { |item| item.to_hash(max_depth, current_depth) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class RichText < Array
6
+ def self.parse(ids, repo)
7
+ items = if ids
8
+ ids.map { |id| repo.find(id) }
9
+ else
10
+ []
11
+ end
12
+ new(items)
13
+ end
14
+
15
+ def to_hash(max_depth = 3, current_depth = 0)
16
+ map { |item| item.to_hash(max_depth, current_depth) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Seo
6
+ attr_reader :title, :description
7
+
8
+ def self.parse(value, repo)
9
+ value && new(value[:title], value[:description], value[:image], repo)
10
+ end
11
+
12
+ def initialize(title, description, image, repo)
13
+ @title = title
14
+ @description = description
15
+ @image = image
16
+ @repo = repo
17
+ end
18
+
19
+ def image
20
+ @image && File.parse(@image, @repo)
21
+ end
22
+
23
+ def to_hash(*args)
24
+ {
25
+ title: title,
26
+ description: description,
27
+ image: image && image.to_hash(*args)
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class Slug
6
+ def self.parse(value, _repo)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agave
3
+ module Local
4
+ module FieldType
5
+ class String
6
+ def self.parse(value, _repo)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end