Class: CustomGateway::CPP::Categories

Inherits:
Base
  • Object
show all
Includes:
Singleton
Defined in:
lib/custom_gateway/services/categories.rb

Constant Summary

Constants inherited from Base

Base::API_INTERNAL_GRAPHQL, Base::API_INTERNAL_LOGIN

Instance Attribute Summary

Attributes inherited from Base

#g3d_cppoms, #http_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CustomGateway::Base

Class Method Details

.allObject



8
9
10
# File 'lib/custom_gateway/services/categories.rb', line 8

def self.all
  instance.all
end

Instance Method Details

#allObject



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
# File 'lib/custom_gateway/services/categories.rb', line 12

def all
  params = {
    "query": "fragment pages on PaginatorInterface {\npages {\npageCount\nitemCountPerPage\nfirst\ncurrent\nlast\nnext\nfirstPageInRange\nlastPageInRange\ncurrentItemCount\ntotalItemCount\nfirstItemNumber\nlastItemNumber\npagesInRange\n}\n}\nquery paginator($filter: Json, $order: Json, $page: Int, $count: Int) {\npaginator: product_categories(filter: $filter, order: $order, page: $page, count: $count) {\n... pages,\n\nitems {\nid, name, full_path\n}\n}\n}",
    "variables": {
      "order": {
        "full_path": "ASC"
      },
      "count": 100,
      "page": 1
    }
  }

  response = http_client.post(API_INTERNAL_GRAPHQL, params)
  if response.status == 200
    categories = []
    response.body['data']['paginator']['items'].each { |c| categories << CustomGateway::Category.new(c) }

    {
      pages: response.body['data']['paginator']['pages'],
      categories: categories
    }
  else
    if auth_failure?(response)
      self.auth!
      self.all
    end
  end
end