nucleo-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.env.sample +2 -0
  3. data/.gitignore +16 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +31 -0
  7. data/Rakefile +37 -0
  8. data/lib/nucleo/client.rb +172 -0
  9. data/lib/nucleo/client/version.rb +5 -0
  10. data/lib/nucleo/configuration.rb +83 -0
  11. data/lib/nucleo/configurations.rb +6 -0
  12. data/lib/nucleo/configurations/default.rb +100 -0
  13. data/lib/nucleo/connection.rb +44 -0
  14. data/lib/nucleo/errors.rb +7 -0
  15. data/lib/nucleo/errors/invalid_uri_error.rb +6 -0
  16. data/lib/nucleo/errors/record_not_found.rb +6 -0
  17. data/lib/nucleo/logger.rb +36 -0
  18. data/lib/nucleo/models.rb +50 -0
  19. data/lib/nucleo/models/change_types.rb +10 -0
  20. data/lib/nucleo/models/change_types/base.rb +81 -0
  21. data/lib/nucleo/models/change_types/seo.rb +13 -0
  22. data/lib/nucleo/models/change_types/seo/base.rb +50 -0
  23. data/lib/nucleo/models/change_types/seo/meta_description.rb +10 -0
  24. data/lib/nucleo/models/change_types/seo/page_title.rb +10 -0
  25. data/lib/nucleo/models/changes.rb +50 -0
  26. data/lib/nucleo/models/check_js.rb +41 -0
  27. data/lib/nucleo/models/check_types.rb +11 -0
  28. data/lib/nucleo/models/check_types/base.rb +25 -0
  29. data/lib/nucleo/models/check_types/count.rb +26 -0
  30. data/lib/nucleo/models/check_types/length.rb +26 -0
  31. data/lib/nucleo/models/check_types/not_exists.rb +8 -0
  32. data/lib/nucleo/models/checks.rb +56 -0
  33. data/lib/nucleo/models/concerns.rb +7 -0
  34. data/lib/nucleo/models/concerns/count.rb +57 -0
  35. data/lib/nucleo/models/concerns/length.rb +57 -0
  36. data/lib/nucleo/models/date_range.rb +66 -0
  37. data/lib/nucleo/models/element.rb +40 -0
  38. data/lib/nucleo/models/elements.rb +47 -0
  39. data/lib/nucleo/models/feed.rb +141 -0
  40. data/lib/nucleo/models/feed_types.rb +11 -0
  41. data/lib/nucleo/models/feed_types/analytics.rb +18 -0
  42. data/lib/nucleo/models/feed_types/analytics/base.rb +12 -0
  43. data/lib/nucleo/models/feed_types/analytics/page/channels.rb +61 -0
  44. data/lib/nucleo/models/feed_types/analytics/page/pages.rb +58 -0
  45. data/lib/nucleo/models/feed_types/analytics/page/referrers.rb +61 -0
  46. data/lib/nucleo/models/feed_types/analytics/page/social.rb +61 -0
  47. data/lib/nucleo/models/feed_types/analytics/site/channels.rb +61 -0
  48. data/lib/nucleo/models/feed_types/analytics/site/pages.rb +61 -0
  49. data/lib/nucleo/models/feed_types/analytics/site/referrers.rb +61 -0
  50. data/lib/nucleo/models/feed_types/analytics/site/social.rb +61 -0
  51. data/lib/nucleo/models/feed_types/base.rb +182 -0
  52. data/lib/nucleo/models/feed_types/seo.rb +22 -0
  53. data/lib/nucleo/models/feed_types/seo/page/base.rb +47 -0
  54. data/lib/nucleo/models/feed_types/seo/page/img_alt.rb +90 -0
  55. data/lib/nucleo/models/feed_types/seo/page/meta_description.rb +49 -0
  56. data/lib/nucleo/models/feed_types/seo/page/meta_robots.rb +48 -0
  57. data/lib/nucleo/models/feed_types/seo/page/page_title.rb +48 -0
  58. data/lib/nucleo/models/feed_types/seo/page/seo_summary.rb +53 -0
  59. data/lib/nucleo/models/feed_types/seo/page/summary.rb +52 -0
  60. data/lib/nucleo/models/feed_types/seo/site/base.rb +22 -0
  61. data/lib/nucleo/models/feed_types/seo/site/img_alt.rb +14 -0
  62. data/lib/nucleo/models/feed_types/seo/site/meta_description.rb +14 -0
  63. data/lib/nucleo/models/feed_types/seo/site/meta_robots.rb +14 -0
  64. data/lib/nucleo/models/feed_types/seo/site/page_title.rb +14 -0
  65. data/lib/nucleo/models/feeds.rb +126 -0
  66. data/lib/nucleo/models/metric.rb +54 -0
  67. data/lib/nucleo/models/metric_period.rb +97 -0
  68. data/lib/nucleo/models/metric_period_row.rb +125 -0
  69. data/lib/nucleo/models/metric_period_rows.rb +34 -0
  70. data/lib/nucleo/models/metric_period_totals.rb +121 -0
  71. data/lib/nucleo/models/metric_periods.rb +78 -0
  72. data/lib/nucleo/models/metric_periods_comparison.rb +80 -0
  73. data/lib/nucleo/models/metric_periods_comparisons.rb +73 -0
  74. data/lib/nucleo/models/metric_periods_totals.rb +58 -0
  75. data/lib/nucleo/models/page.rb +147 -0
  76. data/lib/nucleo/models/page_alerts.rb +27 -0
  77. data/lib/nucleo/models/page_metric.rb +58 -0
  78. data/lib/nucleo/models/page_rank.rb +28 -0
  79. data/lib/nucleo/models/pages.rb +40 -0
  80. data/lib/nucleo/models/seo_score.rb +28 -0
  81. data/lib/nucleo/models/site_feed.rb +82 -0
  82. data/lib/nucleo/models/tag.rb +48 -0
  83. data/lib/nucleo/models/tags.rb +35 -0
  84. data/lib/nucleo/requests.rb +14 -0
  85. data/lib/nucleo/requests/analyzer.rb +35 -0
  86. data/lib/nucleo/requests/check_js.rb +56 -0
  87. data/lib/nucleo/requests/feed.rb +58 -0
  88. data/lib/nucleo/requests/page.rb +113 -0
  89. data/lib/nucleo/requests/page_alerts.rb +36 -0
  90. data/lib/nucleo/requests/page_changes.rb +44 -0
  91. data/lib/nucleo/requests/site.rb +26 -0
  92. data/lib/nucleo/requests/site_changes.rb +56 -0
  93. data/lib/nucleo/requests/site_feed.rb +41 -0
  94. data/lib/nucleo/response.rb +52 -0
  95. data/lib/nucleo/utilities.rb +7 -0
  96. data/lib/nucleo/utilities/status_code_mapper.rb +53 -0
  97. data/lib/nucleo/webhook.rb +26 -0
  98. data/nucleo-client.gemspec +35 -0
  99. data/spec/data/models/feed_types/seo/heading_tag_length.json +55 -0
  100. data/spec/data/models/feed_types/seo/internal_link_count.json +149 -0
  101. data/spec/data/models/feed_types/seo/no_follow_link_count.json +142 -0
  102. data/spec/spec_helper.rb +15 -0
  103. data/spec/unit/nucleo/models/concerns/count_spec.rb +103 -0
  104. data/spec/unit/nucleo/models/concerns/length_spec.rb +79 -0
  105. data/spec/unit/nucleo/models/feed_types/analytics/site/pages_no_data_spec.rb +39 -0
  106. data/spec/unit/nucleo/models/metric_periods_comparison_spec.rb +50 -0
  107. data/spec/unit/nucleo/models/metric_periods_comparisons_spec.rb +58 -0
  108. metadata +341 -0
@@ -0,0 +1,48 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Page
6
+
7
+ class MetaRobots < Nucleo::Models::FeedTypes::Seo::Page::Base
8
+ # Returns the class level feed summary title
9
+ #
10
+ # @return [String]
11
+ def self.feed_summary
12
+ "<strong>Meta robot</strong> feed summary"
13
+ end
14
+
15
+ # Delegate to the class level feed summary
16
+ #
17
+ # @return [String]
18
+ def feed_summary
19
+ self.class.feed_summary
20
+ end
21
+
22
+ # Returns the headline based on the length of the content
23
+ #
24
+ # @return [String]
25
+ def headline
26
+ "Meta robot headline"
27
+ end
28
+
29
+ # Returns the detailed summary
30
+ #
31
+ # @return [String]
32
+ def long_summary
33
+ "Meta robots long summary"
34
+ end
35
+
36
+ # Returns the short summary
37
+ #
38
+ # @return [String]
39
+ def short_summary
40
+ "Meta robots <strong>noindex</strong> will block search engines."
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Page
6
+
7
+ class PageTitle < Nucleo::Models::FeedTypes::Seo::Page::Base
8
+ # Returns the class level feed summary title
9
+ #
10
+ # @return [String]
11
+ def self.feed_summary
12
+ "<strong>page title</strong> feed summary"
13
+ end
14
+
15
+ # Delegate to the class level feed summary
16
+ #
17
+ # @return [String]
18
+ def feed_summary
19
+ self.class.feed_summary
20
+ end
21
+
22
+ # Returns the headline based on the length of the content
23
+ #
24
+ # @return [String]
25
+ def headline
26
+ "page title headline"
27
+ end
28
+
29
+ # Returns the detailed summary
30
+ #
31
+ # @return [String]
32
+ def long_summary
33
+ "page titles long summary"
34
+ end
35
+
36
+ # Returns the short summary
37
+ #
38
+ # @return [String]
39
+ def short_summary
40
+ "Page titles are customers first impression in search results."
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,53 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Page
6
+
7
+ class SeoSummary < Nucleo::Models::FeedTypes::Seo::Page::Base
8
+
9
+ # Returns an instance of the SeoScore domain model
10
+ #
11
+ # @return [Nucleo::Models::SeoScore]
12
+ def seo_score
13
+ params = {
14
+ 'score' => data['seo_score'],
15
+ 'grade' => data['seo_grade']
16
+ }
17
+
18
+ Nucleo::Models::SeoScore.new(params)
19
+ end
20
+
21
+ # Returns an instance of the PageRank domain model
22
+ #
23
+ # @return [Nucleo::Models::PageRank]
24
+ def page_rank
25
+ params = {
26
+ 'rank' => data['page_rank'],
27
+ 'rank_max' => data['page_rank_max']
28
+ }
29
+
30
+ Nucleo::Models::PageRank.new(params)
31
+ end
32
+
33
+ # Returns the number of page views
34
+ #
35
+ # @return [Integer]
36
+ def page_views
37
+ data['page_views'].to_i
38
+ end
39
+ alias :pageviews :page_views
40
+
41
+ # Returns the count of issues (children recommendations)
42
+ #
43
+ # @return [Integer]
44
+ def issue_count
45
+ data['issue_count'].to_i
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Page
6
+
7
+ class Summary < Nucleo::Models::FeedTypes::Seo::Page::Base
8
+ # Returns an instance of the SeoScore domain model
9
+ #
10
+ # @return [Nucleo::Models::SeoScore]
11
+ def seo_score
12
+ params = {
13
+ 'score' => data['seo_score'],
14
+ 'grade' => data['seo_grade']
15
+ }
16
+
17
+ Nucleo::Models::SeoScore.new(params)
18
+ end
19
+
20
+ # Returns an instance of the PageRank domain model
21
+ #
22
+ # @return [Nucleo::Models::PageRank]
23
+ def page_rank
24
+ params = {
25
+ 'rank' => data['page_rank'],
26
+ 'rank_max' => data['page_rank_max']
27
+ }
28
+
29
+ Nucleo::Models::PageRank.new(params)
30
+ end
31
+
32
+ # Returns the number of page views
33
+ #
34
+ # @return [Integer]
35
+ def page_views
36
+ data['page_views'].to_i
37
+ end
38
+ alias :pageviews :page_views
39
+
40
+ # Returns the count of issues (children recommendations)
41
+ #
42
+ # @return [Integer]
43
+ def issue_count
44
+ data['issue_count'].to_i
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../../../base', __FILE__)
2
+
3
+ module Nucleo
4
+ module Models
5
+ module FeedTypes
6
+ module Seo
7
+ module Site
8
+
9
+ class Base < Nucleo::Models::FeedTypes::Base
10
+ # Returns the count of checks
11
+ #
12
+ # @return [Array]
13
+ def count
14
+ data['count']
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Site
6
+
7
+ class ImgAlt < Nucleo::Models::FeedTypes::Seo::Site::Base
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Site
6
+
7
+ class MetaDescription < Nucleo::Models::FeedTypes::Seo::Site::Base
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Site
6
+
7
+ class MetaRobots < Nucleo::Models::FeedTypes::Seo::Site::Base
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Nucleo
2
+ module Models
3
+ module FeedTypes
4
+ module Seo
5
+ module Site
6
+
7
+ class PageTitle < Nucleo::Models::FeedTypes::Seo::Site::Base
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,126 @@
1
+ require File.expand_path('../feed', __FILE__)
2
+ require File.expand_path('../../requests/feed', __FILE__)
3
+
4
+ module Nucleo
5
+ module Models
6
+ class Feeds
7
+ include Enumerable
8
+
9
+ # Return an instance of the Feeds Collection domain model
10
+ #
11
+ # @param collection [Array]
12
+ #
13
+ # @return [Nucleo::Models::Feeds]
14
+ def initialize(collection)
15
+ @collection = Array(collection)
16
+ end
17
+
18
+ # Retrieve a record by the ID.
19
+ #
20
+ # @return [Nucleo::Models::Feed, nil]
21
+ def find_by_id(id)
22
+ self.find { |record| record.id == id.to_s }
23
+ end
24
+
25
+ # Returns only SEO category items
26
+ #
27
+ # @return [Array]
28
+ def seo_category
29
+ self.select(&:seo_category?)
30
+ end
31
+
32
+ # Returns only the Analytics category items
33
+ #
34
+ # @return [Array]
35
+ def analytics_category
36
+ self.select(&:analytics_category?)
37
+ end
38
+
39
+ # Returns only the page context items
40
+ #
41
+ # @return [Array]
42
+ def page_context
43
+ self.select(&:page_context?)
44
+ end
45
+
46
+ # REturns only the site context items
47
+ #
48
+ # @return [Array]
49
+ def site_context
50
+ self.select(&:site_context?)
51
+ end
52
+
53
+ # Returns all records that match the site id
54
+ #
55
+ # @return [Array]
56
+ def find_all_by_site_id(id)
57
+ self.select { |record| record.site_id == id.to_i }
58
+ end
59
+
60
+ # Returns all records that match the category name
61
+ #
62
+ # @return [Array]
63
+ def find_all_by_category_name(name)
64
+ self.select { |record| record.category_name == name.to_s }
65
+ end
66
+
67
+ # Returns all records that match the type name
68
+ #
69
+ # @return [Array]
70
+ def find_all_by_type_name(name)
71
+ self.select { |record| record.type_name == name.to_s }
72
+ end
73
+
74
+ # Returns all records that match the status name
75
+ #
76
+ # @return [Array]
77
+ def find_all_by_status_name(name)
78
+ self.select { |record| record.status_name == name.to_s }
79
+ end
80
+
81
+ # Retrieve a feed with the specified params and return
82
+ # the model as an instance of Feeds.
83
+ #
84
+ # @param site_id [String,Integer] The ID of the site for the feed
85
+ # @param max_feed_items [Integer] Max number of feed items
86
+ #
87
+ # @return [Nucleo::Models::Feeds]
88
+ def self.retrieve(site_id, params={})
89
+ response_body = Nucleo::Requests::Feed.retrieve(site_id, params)
90
+
91
+ self.new(response_body)
92
+ end
93
+
94
+ def each(&block)
95
+ internal_collection.each(&block)
96
+ end
97
+
98
+ # Delegate sample to the array
99
+ #
100
+ # @todo: Ensure this delegates properly
101
+ #
102
+ # @return [Array]
103
+ def sample(n)
104
+ self.to_a.sample(n)
105
+ end
106
+
107
+ private
108
+ def internal_collection
109
+ core_collection = []
110
+ @collection.inject(core_collection) do |collection,record|
111
+ const_name = ['nucleo', 'models', 'feed_types', record['category'], record['context'], record['type']].map(&:camelcase).join('::')
112
+
113
+ begin
114
+ collection.push(Object.const_get(const_name).new(record))
115
+ rescue
116
+ Nucleo::Client.configuration.logger.fatal("Could not instantiate %s" % [const_name])
117
+ end
118
+
119
+ collection
120
+ end
121
+
122
+ Array(core_collection)
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../metric_periods', __FILE__)
2
+
3
+ module Nucleo
4
+ module Models
5
+ class Metric
6
+ # Returns an instance of the Metric domain model. This is
7
+ # the core domain model for a specific metric `type` and
8
+ # `classification`.
9
+ #
10
+ # @param attributes [Hash]
11
+ #
12
+ # @return [Nucleo::Models::Metric]
13
+ def initialize(attributes={})
14
+ @attributes = attributes
15
+ end
16
+
17
+ # Returns the classification of the metric
18
+ #
19
+ # @return [String]
20
+ def classification
21
+ @attributes['classification']
22
+ end
23
+
24
+ # Returns the type of the metric
25
+ #
26
+ # @return [String]
27
+ def metric
28
+ @attributes['metric']
29
+ end
30
+
31
+ # Returns the dimension
32
+ #
33
+ # @return [String]
34
+ def dimension
35
+ @attributes['dimension']
36
+ end
37
+
38
+ # Returns the metric periods used for comparison
39
+ #
40
+ # @return [Nucleo::Models::MetricPeriods]
41
+ def metric_periods
42
+ params = {
43
+ 'metric' => self.metric,
44
+ 'dimension' => self.dimension,
45
+ 'totals' => @attributes['totals'],
46
+ 'current_period' => @attributes['current_period'],
47
+ 'prior_period' => @attributes['prior_period']
48
+ }
49
+
50
+ Nucleo::Models::MetricPeriods.new(params)
51
+ end
52
+ end
53
+ end
54
+ end