nucleo-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.sample +2 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +37 -0
- data/lib/nucleo/client.rb +172 -0
- data/lib/nucleo/client/version.rb +5 -0
- data/lib/nucleo/configuration.rb +83 -0
- data/lib/nucleo/configurations.rb +6 -0
- data/lib/nucleo/configurations/default.rb +100 -0
- data/lib/nucleo/connection.rb +44 -0
- data/lib/nucleo/errors.rb +7 -0
- data/lib/nucleo/errors/invalid_uri_error.rb +6 -0
- data/lib/nucleo/errors/record_not_found.rb +6 -0
- data/lib/nucleo/logger.rb +36 -0
- data/lib/nucleo/models.rb +50 -0
- data/lib/nucleo/models/change_types.rb +10 -0
- data/lib/nucleo/models/change_types/base.rb +81 -0
- data/lib/nucleo/models/change_types/seo.rb +13 -0
- data/lib/nucleo/models/change_types/seo/base.rb +50 -0
- data/lib/nucleo/models/change_types/seo/meta_description.rb +10 -0
- data/lib/nucleo/models/change_types/seo/page_title.rb +10 -0
- data/lib/nucleo/models/changes.rb +50 -0
- data/lib/nucleo/models/check_js.rb +41 -0
- data/lib/nucleo/models/check_types.rb +11 -0
- data/lib/nucleo/models/check_types/base.rb +25 -0
- data/lib/nucleo/models/check_types/count.rb +26 -0
- data/lib/nucleo/models/check_types/length.rb +26 -0
- data/lib/nucleo/models/check_types/not_exists.rb +8 -0
- data/lib/nucleo/models/checks.rb +56 -0
- data/lib/nucleo/models/concerns.rb +7 -0
- data/lib/nucleo/models/concerns/count.rb +57 -0
- data/lib/nucleo/models/concerns/length.rb +57 -0
- data/lib/nucleo/models/date_range.rb +66 -0
- data/lib/nucleo/models/element.rb +40 -0
- data/lib/nucleo/models/elements.rb +47 -0
- data/lib/nucleo/models/feed.rb +141 -0
- data/lib/nucleo/models/feed_types.rb +11 -0
- data/lib/nucleo/models/feed_types/analytics.rb +18 -0
- data/lib/nucleo/models/feed_types/analytics/base.rb +12 -0
- data/lib/nucleo/models/feed_types/analytics/page/channels.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/page/pages.rb +58 -0
- data/lib/nucleo/models/feed_types/analytics/page/referrers.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/page/social.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/site/channels.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/site/pages.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/site/referrers.rb +61 -0
- data/lib/nucleo/models/feed_types/analytics/site/social.rb +61 -0
- data/lib/nucleo/models/feed_types/base.rb +182 -0
- data/lib/nucleo/models/feed_types/seo.rb +22 -0
- data/lib/nucleo/models/feed_types/seo/page/base.rb +47 -0
- data/lib/nucleo/models/feed_types/seo/page/img_alt.rb +90 -0
- data/lib/nucleo/models/feed_types/seo/page/meta_description.rb +49 -0
- data/lib/nucleo/models/feed_types/seo/page/meta_robots.rb +48 -0
- data/lib/nucleo/models/feed_types/seo/page/page_title.rb +48 -0
- data/lib/nucleo/models/feed_types/seo/page/seo_summary.rb +53 -0
- data/lib/nucleo/models/feed_types/seo/page/summary.rb +52 -0
- data/lib/nucleo/models/feed_types/seo/site/base.rb +22 -0
- data/lib/nucleo/models/feed_types/seo/site/img_alt.rb +14 -0
- data/lib/nucleo/models/feed_types/seo/site/meta_description.rb +14 -0
- data/lib/nucleo/models/feed_types/seo/site/meta_robots.rb +14 -0
- data/lib/nucleo/models/feed_types/seo/site/page_title.rb +14 -0
- data/lib/nucleo/models/feeds.rb +126 -0
- data/lib/nucleo/models/metric.rb +54 -0
- data/lib/nucleo/models/metric_period.rb +97 -0
- data/lib/nucleo/models/metric_period_row.rb +125 -0
- data/lib/nucleo/models/metric_period_rows.rb +34 -0
- data/lib/nucleo/models/metric_period_totals.rb +121 -0
- data/lib/nucleo/models/metric_periods.rb +78 -0
- data/lib/nucleo/models/metric_periods_comparison.rb +80 -0
- data/lib/nucleo/models/metric_periods_comparisons.rb +73 -0
- data/lib/nucleo/models/metric_periods_totals.rb +58 -0
- data/lib/nucleo/models/page.rb +147 -0
- data/lib/nucleo/models/page_alerts.rb +27 -0
- data/lib/nucleo/models/page_metric.rb +58 -0
- data/lib/nucleo/models/page_rank.rb +28 -0
- data/lib/nucleo/models/pages.rb +40 -0
- data/lib/nucleo/models/seo_score.rb +28 -0
- data/lib/nucleo/models/site_feed.rb +82 -0
- data/lib/nucleo/models/tag.rb +48 -0
- data/lib/nucleo/models/tags.rb +35 -0
- data/lib/nucleo/requests.rb +14 -0
- data/lib/nucleo/requests/analyzer.rb +35 -0
- data/lib/nucleo/requests/check_js.rb +56 -0
- data/lib/nucleo/requests/feed.rb +58 -0
- data/lib/nucleo/requests/page.rb +113 -0
- data/lib/nucleo/requests/page_alerts.rb +36 -0
- data/lib/nucleo/requests/page_changes.rb +44 -0
- data/lib/nucleo/requests/site.rb +26 -0
- data/lib/nucleo/requests/site_changes.rb +56 -0
- data/lib/nucleo/requests/site_feed.rb +41 -0
- data/lib/nucleo/response.rb +52 -0
- data/lib/nucleo/utilities.rb +7 -0
- data/lib/nucleo/utilities/status_code_mapper.rb +53 -0
- data/lib/nucleo/webhook.rb +26 -0
- data/nucleo-client.gemspec +35 -0
- data/spec/data/models/feed_types/seo/heading_tag_length.json +55 -0
- data/spec/data/models/feed_types/seo/internal_link_count.json +149 -0
- data/spec/data/models/feed_types/seo/no_follow_link_count.json +142 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/nucleo/models/concerns/count_spec.rb +103 -0
- data/spec/unit/nucleo/models/concerns/length_spec.rb +79 -0
- data/spec/unit/nucleo/models/feed_types/analytics/site/pages_no_data_spec.rb +39 -0
- data/spec/unit/nucleo/models/metric_periods_comparison_spec.rb +50 -0
- data/spec/unit/nucleo/models/metric_periods_comparisons_spec.rb +58 -0
- metadata +341 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday/detailed_logger'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'delegate'
|
5
|
+
|
6
|
+
module Nucleo
|
7
|
+
class Connection < SimpleDelegator
|
8
|
+
|
9
|
+
# Decorating the Faraday object
|
10
|
+
#
|
11
|
+
# @return [Nucleo::Connection ] Faraday Conection Delegator
|
12
|
+
def initialize(url, &block)
|
13
|
+
@_connection = Faraday.new(url, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the Net::HTTP default adapter from Faraday
|
17
|
+
#
|
18
|
+
# @return [Symbol] Default Adapter
|
19
|
+
def self.default_adapter
|
20
|
+
Faraday.default_adapter
|
21
|
+
end
|
22
|
+
|
23
|
+
# Faraday does not provide an HTTP OPTIONS call. Its
|
24
|
+
# core library utilizes `options` for RequestOptions.
|
25
|
+
#
|
26
|
+
# This allows us to perform an HTTP options request
|
27
|
+
#
|
28
|
+
# @param url [String] The URL for the request
|
29
|
+
# @param params [Hash] Request parameters to send
|
30
|
+
# @param headers [Hash] Request headers to send
|
31
|
+
#
|
32
|
+
# @return [Faraday::Response] Faraday Response
|
33
|
+
def http_options(url=nil, params=nil, headers=nil)
|
34
|
+
@_connection.run_request(:options, url, params, headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Specify the class for the Delegator
|
38
|
+
#
|
39
|
+
# @return [Faraday]
|
40
|
+
def __getobj__
|
41
|
+
@_connection
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Nucleo
|
5
|
+
class Logger < SimpleDelegator
|
6
|
+
DEFAULT_PROGNAME = "NUCLEO_API_CLIENT"
|
7
|
+
|
8
|
+
def initialize(name, shift_age=7, shift_size=1048576)
|
9
|
+
@_logger = ::Logger.new(name, shift_age, shift_size)
|
10
|
+
end
|
11
|
+
|
12
|
+
def warn(progname = nil, &block)
|
13
|
+
@_logger.warn((progname || DEFAULT_PROGNAME), &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def debug(progname = nil, &block)
|
17
|
+
@_logger.debug((progname || DEFAULT_PROGNAME), &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fatal(progname = nil, &block)
|
21
|
+
@_logger.fatal((progname || DEFAULT_PROGNAME), &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def error(progname = nil, &block)
|
25
|
+
@_logger.error((progname || DEFAULT_PROGNAME), &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def info(progname = nil, &block)
|
29
|
+
@_logger.info((progname || DEFAULT_PROGNAME), &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def __getobj__
|
33
|
+
@_logger
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../models/site_feed', __FILE__)
|
2
|
+
require File.expand_path('../models/page_alerts', __FILE__)
|
3
|
+
|
4
|
+
require File.expand_path('../models/feeds', __FILE__)
|
5
|
+
require File.expand_path('../models/feed', __FILE__)
|
6
|
+
|
7
|
+
require File.expand_path('../models/changes', __FILE__)
|
8
|
+
require File.expand_path('../models/change_types', __FILE__)
|
9
|
+
|
10
|
+
require File.expand_path('../models/checks', __FILE__)
|
11
|
+
require File.expand_path('../models/check_types', __FILE__)
|
12
|
+
require File.expand_path('../models/elements', __FILE__)
|
13
|
+
require File.expand_path('../models/element', __FILE__)
|
14
|
+
|
15
|
+
require File.expand_path('../models/date_range', __FILE__)
|
16
|
+
|
17
|
+
require File.expand_path('../models/pages', __FILE__)
|
18
|
+
require File.expand_path('../models/page', __FILE__)
|
19
|
+
require File.expand_path('../models/page_metric', __FILE__)
|
20
|
+
|
21
|
+
require File.expand_path('../models/tags', __FILE__)
|
22
|
+
require File.expand_path('../models/tag', __FILE__)
|
23
|
+
|
24
|
+
require File.expand_path('../models/metric', __FILE__)
|
25
|
+
|
26
|
+
require File.expand_path('../models/metric_period_totals', __FILE__)
|
27
|
+
require File.expand_path('../models/metric_periods_totals', __FILE__)
|
28
|
+
|
29
|
+
require File.expand_path('../models/metric_period', __FILE__)
|
30
|
+
require File.expand_path('../models/metric_periods', __FILE__)
|
31
|
+
|
32
|
+
require File.expand_path('../models/metric_periods_comparisons', __FILE__)
|
33
|
+
require File.expand_path('../models/metric_periods_comparison', __FILE__)
|
34
|
+
|
35
|
+
require File.expand_path('../models/metric_period_rows', __FILE__)
|
36
|
+
require File.expand_path('../models/metric_period_row', __FILE__)
|
37
|
+
|
38
|
+
require File.expand_path('../models/seo_score', __FILE__)
|
39
|
+
require File.expand_path('../models/page_rank', __FILE__)
|
40
|
+
|
41
|
+
require File.expand_path('../models/feed_types', __FILE__)
|
42
|
+
|
43
|
+
require File.expand_path('../models/check_js', __FILE__)
|
44
|
+
|
45
|
+
require File.expand_path('../models/concerns', __FILE__)
|
46
|
+
|
47
|
+
module Nucleo
|
48
|
+
module Models
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Nucleo
|
2
|
+
module Models
|
3
|
+
module ChangeTypes
|
4
|
+
class Base
|
5
|
+
include Comparable
|
6
|
+
|
7
|
+
# Return an instance of the Rule Type domain model
|
8
|
+
#
|
9
|
+
# @param attributes [Hash]
|
10
|
+
#
|
11
|
+
# @return [Nucleo::Models::RuleType::Base]
|
12
|
+
def initialize(attributes={})
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def <=>(other)
|
17
|
+
self.created_at <=> other.created_at
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the ID of the rule
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
def id
|
24
|
+
@attributes['id']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the associated site id
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
def site_id
|
31
|
+
@attributes['site_id']
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the associated page id
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
def page_id
|
38
|
+
@attributes['page_id']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the context of the rule
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
def context
|
45
|
+
@attributes['context']
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the category of the rule
|
49
|
+
#
|
50
|
+
# @return [String]
|
51
|
+
def category
|
52
|
+
@attributes['category']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the type of the rule
|
56
|
+
#
|
57
|
+
# @return [String]
|
58
|
+
def type
|
59
|
+
@attributes['type']
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the created at timestamp
|
63
|
+
# of the rule.
|
64
|
+
#
|
65
|
+
# @return [DateTime]
|
66
|
+
def created_at
|
67
|
+
begin
|
68
|
+
DateTime.parse(@attributes['created_at'])
|
69
|
+
rescue
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
def rule
|
76
|
+
@attributes.fetch('rule', {})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../../change_types/seo/base', __FILE__)
|
2
|
+
|
3
|
+
require File.expand_path('../../change_types/seo/page_title', __FILE__)
|
4
|
+
require File.expand_path('../../change_types/seo/meta_description', __FILE__)
|
5
|
+
|
6
|
+
module Nucleo
|
7
|
+
module Models
|
8
|
+
module RuleTypes
|
9
|
+
module Seo
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../../change_types/base', __FILE__)
|
2
|
+
|
3
|
+
module Nucleo
|
4
|
+
module Models
|
5
|
+
module ChangeTypes
|
6
|
+
module Seo
|
7
|
+
class Base < Nucleo::Models::ChangeTypes::Base
|
8
|
+
VALID_ACTIONS = %w( insert update remove ).freeze
|
9
|
+
VALID_SELECTORS = %w( class content id name src ).freeze
|
10
|
+
|
11
|
+
# Returns the action
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
def action
|
15
|
+
rule['action']
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the content to insert/replace
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def content
|
22
|
+
rule['content']
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the selector
|
26
|
+
#
|
27
|
+
# @return [String]
|
28
|
+
def selector
|
29
|
+
rule['selector']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a string value that uniquely identifies
|
33
|
+
# and item by the `selector` provided.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
def selector_content
|
37
|
+
rule['selector_content']
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the string value of the content to be replaced
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
def content
|
44
|
+
rule['content']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Nucleo
|
2
|
+
module Models
|
3
|
+
class Changes
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
# Return an instance of the Rules collection domain model
|
7
|
+
#
|
8
|
+
# @param collection [Array]
|
9
|
+
#
|
10
|
+
# @return [Nucleo::Models::Changes]
|
11
|
+
def initialize(collection)
|
12
|
+
@collection = Array(collection)
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&block)
|
16
|
+
internal_collection.each(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def push(args)
|
20
|
+
@collection.push(args)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Retrieve a rule by the ID.
|
24
|
+
#
|
25
|
+
# @return [Nucleo::Models::ChangeType]
|
26
|
+
def find_by_id(id)
|
27
|
+
self.find { |record| record.id == id.to_s }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def internal_collection
|
32
|
+
core_collection = []
|
33
|
+
|
34
|
+
@collection.inject(core_collection) do |collection,record|
|
35
|
+
const_name = ['nucleo', 'models', 'change_types', record['category'], record['type']].map(&:camelcase).join('::')
|
36
|
+
|
37
|
+
begin
|
38
|
+
collection.push(Object.const_get(const_name).new(record))
|
39
|
+
rescue
|
40
|
+
Nucleo::Client.configuration.logger.fatal("Could not instantiate: %s" % [const_name])
|
41
|
+
end
|
42
|
+
|
43
|
+
collection
|
44
|
+
end
|
45
|
+
|
46
|
+
Array(core_collection)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
module Nucleo
|
3
|
+
module Models
|
4
|
+
class CheckJS
|
5
|
+
# Returns an instanc eof the Site Feed domain model
|
6
|
+
#
|
7
|
+
# @param attributes [Hash]
|
8
|
+
#
|
9
|
+
# @return [Nucleo::Models::SiteFeed]
|
10
|
+
def initialize(attributes={})
|
11
|
+
@attributes = attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.check_js(url)
|
15
|
+
response_body = Nucleo::Requests::CheckJS.retrieve({url: url})
|
16
|
+
|
17
|
+
self.new(response_body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def body?
|
21
|
+
@attributes.fetch("body")
|
22
|
+
end
|
23
|
+
|
24
|
+
def head?
|
25
|
+
@attributes.fetch("head")
|
26
|
+
end
|
27
|
+
|
28
|
+
def other?
|
29
|
+
@attributes.fetch("other")
|
30
|
+
end
|
31
|
+
|
32
|
+
def installed?
|
33
|
+
@attributes.fetch("installed")
|
34
|
+
end
|
35
|
+
|
36
|
+
def installed_correctly?
|
37
|
+
self.head? and not (self.body? or self.other?)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../check_types/base', __FILE__)
|
2
|
+
require File.expand_path('../check_types/count', __FILE__)
|
3
|
+
require File.expand_path('../check_types/not_exists', __FILE__)
|
4
|
+
require File.expand_path('../check_types/length', __FILE__)
|
5
|
+
|
6
|
+
module Nucleo
|
7
|
+
module Models
|
8
|
+
module CheckTypes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|