Class: RTX::API::Resources

Inherits:
Object
  • Object
show all
Defined in:
lib/rtx/api/resources.rb

Class Method Summary collapse

Class Method Details

.allowed_builable_resourcesObject

rubocop:enable Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rtx/api/resources.rb', line 66

def self.allowed_builable_resources
  {
    local_search_location_reports: {
      required_values: %i[account_id location_id],
      resource_method: :build_local_search_location_reports_path
    },
    metrics_child_overviews: {
      required_values: %i[account_id],
      resource_method: :build_metrics_child_overviews_path
    }
  }.freeze
end

.allowed_resourcesObject

rubocop:disable Metrics/MethodLength



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rtx/api/resources.rb', line 7

def self.allowed_resources
  {
    accounts: 'accounts',
    account_children: 'account_children',
    account_settings: 'account_settings',
    alerts: 'alerts',
    alert_frequencies: 'alert_frequencies',
    alert_types: 'alert_types',
    auth_tokens: 'auth/tokens',
    campaigns: 'campaigns',
    child_integrations: 'child_integrations',
    competitors_brands_overview_csv: 'intel/locations/tags_overview/export',
    competitors_overview_csv: 'export/csv/intel/locations',
    contacts: 'contacts',
    countries: 'countries',
    crawlers: 'crawlers',
    google_posts: 'google_posts',
    gpt_response: 'ghostwriter_response/gpt',
    groups: 'groups',
    groups_and_locations: 'groups_and_locations',
    industry_scores: 'industry_scores',
    keywords: 'insights/keywords',
    items: 'items',
    layouts: 'layouts',
    locations: 'locations',
    location_performance_overview_csv: 'location_performance_overview/csv',
    location_score: 'location_score',
    metric_locations: 'export/csv/location_metrics',
    metric_locations_new: 'location_score/export/locations/csv',
    metric_groups: 'export/csv/group_metrics',
    metric_groups_new: 'location_score/export/groups/csv',
    notes: 'notes',
    passwords: 'passwords',
    permissions: 'permissions',
    plan_changes: 'plan_changes',
    profiles: 'profiles',
    requests: 'requests',
    request_pages: 'request_pages',
    request_types: 'request_types',
    responses: 'responses',
    reviews: 'reviews',
    review_status_labels: 'review_status_labels',
    single_sign_ons: 'single_sign_ons',
    sources: 'sources',
    states: 'states',
    target_scores: 'target_scores',
    templates: 'templates',
    template_tags: 'template_tags',
    urls: 'urls',
    users: 'users',
    user_location_assignments: 'assignments/location',
    user_types: 'user_types',
    whitelabels: 'whitelabels',
    v2_reviews: 'v2/reviews',
    v2_reviews_csv: 'v2/reviews_csv'
  }.freeze
end

.build_local_search_location_reports_path(attrs) ⇒ Object



91
92
93
# File 'lib/rtx/api/resources.rb', line 91

def self.build_local_search_location_reports_path(attrs)
  "local_search/#{attrs[:account_id]}/locations/#{attrs[:location_id]}/reports"
end

.build_metrics_child_overviews_path(attrs) ⇒ Object



95
96
97
# File 'lib/rtx/api/resources.rb', line 95

def self.build_metrics_child_overviews_path(attrs)
  "metrics/#{attrs[:account_id]}/child_overview"
end

.build_resource(resource_name, attrs) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rtx/api/resources.rb', line 79

def self.build_resource(resource_name, attrs)
  return unless allowed_builable_resources.key?(resource_name)

  unless allowed_builable_resources[resource_name][:required_values].all? do |v|
           attrs[v]
         end
    raise API::Errors::InvalidResourceError,
          "Missing required params for (#{resource_name})"
  end
  send(allowed_builable_resources[resource_name][:resource_method], attrs)
end